"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)",
pkg.Enums[i] = *enum
pkg.RefMap[toApiType(enum.Name)] = enum.Name
}
+ // sort enums
+ sort.SliceStable(pkg.Enums, func(i, j int) bool {
+ return pkg.Enums[i].Name < pkg.Enums[j].Name
+ })
// parse aliases
aliases := jsonRoot.Map("aliases")
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")
pkg.Types[i] = *typ
pkg.RefMap[toApiType(typ.Name)] = typ.Name
}
+ // sort types
+ sort.SliceStable(pkg.Types, func(i, j int) bool {
+ return pkg.Types[i].Name < pkg.Types[j].Name
+ })
// parse unions
unions := jsonRoot.Map("unions")
pkg.Unions[i] = *union
pkg.RefMap[toApiType(union.Name)] = union.Name
}
+ // sort unions
+ sort.SliceStable(pkg.Unions, func(i, j int) bool {
+ return pkg.Unions[i].Name < pkg.Unions[j].Name
+ })
// parse messages
messages := jsonRoot.Map("messages")
}
pkg.Messages[i] = *msg
}
+ // sort messages
+ sort.SliceStable(pkg.Messages, func(i, j int) bool {
+ return pkg.Messages[i].Name < pkg.Messages[j].Name
+ })
// parse services
services := jsonRoot.Map("services")
}
pkg.Services[i] = *svc
}
-
- // sort services
- sort.Slice(pkg.Services, func(i, j int) bool {
- // dumps first
- if pkg.Services[i].Stream != pkg.Services[j].Stream {
- return pkg.Services[i].Stream
- }
- return pkg.Services[i].RequestType < pkg.Services[j].RequestType
- })
}
+ // sort services
+ sort.Slice(pkg.Services, func(i, j int) bool {
+ // dumps first
+ if pkg.Services[i].Stream != pkg.Services[j].Stream {
+ return pkg.Services[i].Stream
+ }
+ return pkg.Services[i].RequestType < pkg.Services[j].RequestType
+ })
printPackage(&pkg)
// validate service
if svc.IsEventService() {
if !strings.HasPrefix(svc.RequestType, "want_") {
- log.Warnf("Unusual EVENTS SERVICE: %+v\n"+
+ log.Debugf("Unusual EVENTS SERVICE: %+v\n"+
"- events service %q does not have 'want_' prefix in request.",
svc, svc.Name)
}
} else if svc.IsDumpService() {
if !strings.HasSuffix(svc.RequestType, "_dump") ||
!strings.HasSuffix(svc.ReplyType, "_details") {
- log.Warnf("Unusual STREAM SERVICE: %+v\n"+
+ log.Debugf("Unusual STREAM SERVICE: %+v\n"+
"- stream service %q does not have '_dump' suffix in request or reply does not have '_details' suffix.",
svc, svc.Name)
}
} else if svc.IsRequestService() {
if !strings.HasSuffix(svc.ReplyType, "_reply") {
- log.Warnf("Unusual REQUEST SERVICE: %+v\n"+
+ log.Debugf("Unusual REQUEST SERVICE: %+v\n"+
"- service %q does not have '_reply' suffix in reply.",
svc, svc.Name)
}
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 {
// 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
}