X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=cmd%2Fbinapi-generator%2Fparse.go;h=602b17f3d5a7f3dda092415286ba5cc66137ae9e;hb=682250e328472e855a4c59e9e5f004473b6af0d3;hp=562abab70b7188adc64810b7cfc09f610b8fa256;hpb=c4522fe10317b1729a0820dc880afc78c663f64d;p=govpp.git diff --git a/cmd/binapi-generator/parse.go b/cmd/binapi-generator/parse.go index 562abab..602b17f 100644 --- a/cmd/binapi-generator/parse.go +++ b/cmd/binapi-generator/parse.go @@ -274,9 +274,9 @@ func parseUnion(ctx *context, unionNode *jsongo.JSONNode) (*Union, error) { if !ok { return nil, fmt.Errorf("union name is %T, not a string", unionNode.At(0).Get()) } - unionCRC, ok := unionNode.At(unionNode.Len() - 1).At(crcField).Get().(string) - if !ok { - return nil, fmt.Errorf("union crc invalid or missing") + var unionCRC string + if unionNode.At(unionNode.Len()-1).GetType() == jsongo.TypeMap { + unionCRC = unionNode.At(unionNode.Len() - 1).At(crcField).Get().(string) } union := Union{ @@ -284,8 +284,8 @@ func parseUnion(ctx *context, unionNode *jsongo.JSONNode) (*Union, error) { CRC: unionCRC, } - // loop through union fields, skip first (name) and last (crc) - for j := 1; j < unionNode.Len()-1; j++ { + // loop through union fields, skip first (name) + for j := 1; j < unionNode.Len(); j++ { if unionNode.At(j).GetType() == jsongo.TypeArray { fieldNode := unionNode.At(j) @@ -311,9 +311,9 @@ func parseType(ctx *context, typeNode *jsongo.JSONNode) (*Type, error) { if !ok { return nil, fmt.Errorf("type name is %T, not a string", typeNode.At(0).Get()) } - typeCRC, ok := typeNode.At(typeNode.Len() - 1).At(crcField).Get().(string) - if !ok { - return nil, fmt.Errorf("type crc invalid or missing") + var typeCRC string + if lastField := typeNode.At(typeNode.Len() - 1); lastField.GetType() == jsongo.TypeMap { + typeCRC = lastField.At(crcField).Get().(string) } typ := Type{ @@ -321,8 +321,8 @@ func parseType(ctx *context, typeNode *jsongo.JSONNode) (*Type, error) { CRC: typeCRC, } - // loop through type fields, skip first (name) and last (crc) - for j := 1; j < typeNode.Len()-1; j++ { + // loop through type fields, skip first (name) + for j := 1; j < typeNode.Len(); j++ { if typeNode.At(j).GetType() == jsongo.TypeArray { fieldNode := typeNode.At(j)