diff options
author | Vladimir Lavor <vlavor@cisco.com> | 2021-03-11 10:13:17 +0100 |
---|---|---|
committer | Vladimir Lavor <vlavor@cisco.com> | 2021-04-22 11:32:58 +0200 |
commit | a6607d9c1ba37320984c13580c932076cbff6dd6 (patch) | |
tree | a8a7dba6b40114788c1295197c1b4bd8010f22c0 /binapigen/vppapi/parse_json.go | |
parent | d0b973030fe07dc7875da72f5ebe42d8bd9544b1 (diff) |
added api message options
In case the API message contains option of type deprecated
or in-progress, the information is displayed in the generated
code in a form of additional comment:
// InProgress: <info>
// Deprecated: <info>
In case the <info> is not provided, a generic message is shown.
Possible future use to automatically search whether such
messages are in use.
Change-Id: Icf87cc9a2fe6bf31f7555320255c9f0736add6e1
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Diffstat (limited to 'binapigen/vppapi/parse_json.go')
-rw-r--r-- | binapigen/vppapi/parse_json.go | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/binapigen/vppapi/parse_json.go b/binapigen/vppapi/parse_json.go index a2ca257..ed7bcad 100644 --- a/binapigen/vppapi/parse_json.go +++ b/binapigen/vppapi/parse_json.go @@ -46,10 +46,11 @@ const ( fileServices = "services" fileImports = "imports" // type keys - messageCrc = "crc" - enumType = "enumtype" - aliasLength = "length" - aliasType = "type" + messageCrc = "crc" + messageOptions = "options" + enumType = "enumtype" + aliasLength = "length" + aliasType = "type" // service serviceReply = "reply" serviceStream = "stream" @@ -375,10 +376,30 @@ func parseMessage(msgNode *jsongo.Node) (*Message, error) { if !ok { return nil, fmt.Errorf("message crc invalid or missing") } + var msgOpts map[string]string + msgOptsNode := msgNode.At(msgNode.Len() - 1).Map(messageOptions) + if msgOptsNode.GetType() == jsongo.TypeMap { + msgOpts = make(map[string]string) + for _, opt := range msgOptsNode.GetKeys() { + if _, ok := opt.(string); !ok { + logf("invalid message option key, expected string") + continue + } + msgOpts[opt.(string)] = "" + if msgOptsNode.At(opt).Get() != nil { + if optMsgStr, ok := msgOptsNode.At(opt).Get().(string); ok { + msgOpts[opt.(string)] = optMsgStr + } else { + logf("invalid message option value, expected string") + } + } + } + } msg := Message{ - Name: msgName, - CRC: msgCRC, + Name: msgName, + CRC: msgCRC, + Options: msgOpts, } // loop through message fields, skip first (name) and last (crc) |