X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=binapigen%2Fvppapi%2Fparse_json.go;h=ed7bcad7cc8a1918559dd7f372068bda66362d59;hb=refs%2Fchanges%2F12%2F31612%2F7;hp=a2ca2570c83f4de89f427afc643cb54c8e8c1c02;hpb=d0b973030fe07dc7875da72f5ebe42d8bd9544b1;p=govpp.git 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)