diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2019-06-04 14:47:19 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2019-06-04 14:47:19 +0200 |
commit | 0ff02b6b1f0757f5e4c011457757bd18d0a60f01 (patch) | |
tree | 599d8a351942ba63b2418da737d7f9e10b6c0973 /cmd/binapi-generator/types.go | |
parent | 3f0489044a1fbc6539aa8c57ffce6d7b00de7d82 (diff) |
Fix union data size for types with enums
- this also fixed proper alphabetical order for struct tags
- env var DEBUG_BINAPI_GENERATOR=y can be used to enable debug mode
Change-Id: I5b08a696ad2ff2a297872f231f9229cd956ee443
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'cmd/binapi-generator/types.go')
-rw-r--r-- | cmd/binapi-generator/types.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/cmd/binapi-generator/types.go b/cmd/binapi-generator/types.go index 3aa9819..d056251 100644 --- a/cmd/binapi-generator/types.go +++ b/cmd/binapi-generator/types.go @@ -69,8 +69,13 @@ func convertToGoType(ctx *context, binapiType string) (typ string) { return typ } -func getSizeOfType(typ *Type) (size int) { +func getSizeOfType(ctx *context, typ *Type) (size int) { for _, field := range typ.Fields { + enum := getEnumByRef(ctx, field.Type) + if enum != nil { + size += getSizeOfBinapiTypeLength(enum.Type, field.Length) + continue + } size += getSizeOfBinapiTypeLength(field.Type, field.Length) } return size @@ -84,9 +89,19 @@ func getSizeOfBinapiTypeLength(typ string, length int) (size int) { return n } } + return } +func getEnumByRef(ctx *context, ref string) *Enum { + for _, typ := range ctx.packageData.Enums { + if ref == toApiType(typ.Name) { + return &typ + } + } + return nil +} + func getTypeByRef(ctx *context, ref string) *Type { for _, typ := range ctx.packageData.Types { if ref == toApiType(typ.Name) { @@ -109,7 +124,7 @@ func getUnionSize(ctx *context, union *Union) (maxSize int) { for _, field := range union.Fields { typ := getTypeByRef(ctx, field.Type) if typ != nil { - if size := getSizeOfType(typ); size > maxSize { + if size := getSizeOfType(ctx, typ); size > maxSize { maxSize = size } continue @@ -125,5 +140,6 @@ func getUnionSize(ctx *context, union *Union) (maxSize int) { continue } } + logf("getUnionSize: %s %+v max=%v", union.Name, union.Fields, maxSize) return } |