diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2019-01-10 10:57:50 +0100 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2019-01-10 11:05:35 +0100 |
commit | 08266e35878f198e2fa59fcfc9f0fc3a4b1dfbf5 (patch) | |
tree | 1269acfc3bf6fdd47414eb64da3ecad4865e37d6 /cmd/binapi-generator/parse.go | |
parent | 3ef6f210edcf7dd753733d46ec3f2dd5dc795b61 (diff) |
Add support for string types
- strings are now generated as two fields for length and string itself
- aliases are now sorted by name to prevent generating different code
- dependencies are now managed by dep
- binapi files are regenerated using VPP 19.01-rc0~622-g7b01e9e8
- old stats binary api has been deprecated and removed from VPP
Change-Id: Ieb8515c73021339a45f407386f8e3d87dcf4469e
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'cmd/binapi-generator/parse.go')
-rw-r--r-- | cmd/binapi-generator/parse.go | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/cmd/binapi-generator/parse.go b/cmd/binapi-generator/parse.go index 5dfbe91..5bb3e8e 100644 --- a/cmd/binapi-generator/parse.go +++ b/cmd/binapi-generator/parse.go @@ -23,11 +23,6 @@ import ( "github.com/bennyscetbun/jsongo" ) -// toApiType returns name that is used as type reference in VPP binary API -func toApiType(name string) string { - return fmt.Sprintf("vl_api_%s_t", name) -} - // parsePackage parses provided JSON data into objects prepared for code generation func parsePackage(ctx *context, jsonRoot *jsongo.JSONNode) (*Package, error) { logf(" %s contains: %d services, %d messages, %d types, %d enums, %d unions, %d aliases (version: %s)", @@ -75,6 +70,10 @@ func parsePackage(ctx *context, jsonRoot *jsongo.JSONNode) (*Package, error) { pkg.RefMap[toApiType(alias.Name)] = alias.Name } } + // sort aliases to ensure consistent order + sort.Slice(pkg.Aliases, func(i, j int) bool { + return pkg.Aliases[i].Name < pkg.Aliases[j].Name + }) // parse types types := jsonRoot.Map("types") @@ -479,6 +478,11 @@ func parseService(ctx *context, svcName string, svcNode *jsongo.JSONNode) (*Serv return &svc, nil } +// toApiType returns name that is used as type reference in VPP binary API +func toApiType(name string) string { + return fmt.Sprintf("vl_api_%s_t", name) +} + // convertToGoType translates the VPP binary API type into Go type func convertToGoType(ctx *context, binapiType string) (typ string) { if t, ok := binapiTypes[binapiType]; ok { @@ -488,9 +492,14 @@ func convertToGoType(ctx *context, binapiType string) (typ string) { // specific types (enums/types/unions) typ = camelCaseName(r) } else { - // fallback type - log.Warnf("found unknown VPP binary API type %q, using byte", binapiType) - typ = "byte" + switch binapiType { + case "bool", "string": + typ = binapiType + default: + // fallback type + log.Warnf("found unknown VPP binary API type %q, using byte", binapiType) + typ = "byte" + } } return typ } |