X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=cmd%2Fbinapi-generator%2Fobjects.go;h=9871abc5722001fe7626d854a5a4aec6506a5f5a;hb=2df59463fcbb1a5aec2173712b32fb9740157a9d;hp=4b424f5e7ff0429906c3cf78ed814211e289be4d;hpb=6476a2b64a2e1ea6c0d695127d726a348cc5c99b;p=govpp.git diff --git a/cmd/binapi-generator/objects.go b/cmd/binapi-generator/objects.go index 4b424f5..9871abc 100644 --- a/cmd/binapi-generator/objects.go +++ b/cmd/binapi-generator/objects.go @@ -1,19 +1,24 @@ package main -import ( - "strings" -) +import "fmt" // Package represents collection of objects parsed from VPP binary API JSON data type Package struct { - APIVersion string - Services []Service - Enums []Enum - Aliases []Alias - Types []Type - Unions []Union - Messages []Message - RefMap map[string]string + Name string + Version string + CRC string + Services []Service + Enums []Enum + Aliases []Alias + Types []Type + Unions []Union + Messages []Message + RefMap map[string]string + Imports map[string]Import +} + +type Import struct { + Package string } // Service represents VPP binary API service @@ -52,6 +57,22 @@ type Type struct { Fields []Field } +// Field represents VPP binary API object field +type Field struct { + Name string + Type string + Length int + SpecifiedLen bool + SizeFrom string + Meta FieldMeta +} + +// FieldMeta represents VPP binary API meta info for field +type FieldMeta struct { + Limit int + Default string +} + // Union represents VPP binary API union type Union struct { Name string @@ -76,42 +97,43 @@ const ( otherMessage // other VPP message ) -// Field represents VPP binary API object field -type Field struct { - Name string - Type string - Length int - SizeFrom string -} - -func (f *Field) IsArray() bool { - return f.Length > 0 || f.SizeFrom != "" -} - -func (s Service) MethodName() string { - reqTyp := camelCaseName(s.RequestType) - - // method name is same as parameter type name by default - method := reqTyp - if s.Stream { - // use Dump as prefix instead of suffix for stream services - if m := strings.TrimSuffix(method, "Dump"); method != m { - method = "Dump" + m +// printPackage prints all loaded objects for package +func printPackage(pkg *Package) { + logf("package: %s %s (%s)", pkg.Name, pkg.Version, pkg.CRC) + if len(pkg.Enums) > 0 { + logf(" %d enums:", len(pkg.Enums)) + for _, enum := range pkg.Enums { + logf(" - %s: %+v", enum.Name, enum) + } + } + if len(pkg.Unions) > 0 { + logf(" %d unions:", len(pkg.Unions)) + for _, union := range pkg.Unions { + logf(" - %s: %+v", union.Name, union) + } + } + if len(pkg.Types) > 0 { + logf(" %d types:", len(pkg.Types)) + for _, typ := range pkg.Types { + logf(" - %s (%d fields): %+v", typ.Name, len(typ.Fields), typ) + } + } + if len(pkg.Messages) > 0 { + logf(" %d messages:", len(pkg.Messages)) + for _, msg := range pkg.Messages { + logf(" - %s (%d fields) %s", msg.Name, len(msg.Fields), msg.CRC) + } + } + if len(pkg.Services) > 0 { + logf(" %d services:", len(pkg.Services)) + for _, svc := range pkg.Services { + var info string + if svc.Stream { + info = "(STREAM)" + } else if len(svc.Events) > 0 { + info = fmt.Sprintf("(EVENTS: %v)", svc.Events) + } + logf(" - %s: %q -> %q %s", svc.Name, svc.RequestType, svc.ReplyType, info) } } - - return method -} - -func (s Service) IsDumpService() bool { - return s.Stream -} - -func (s Service) IsEventService() bool { - return len(s.Events) > 0 -} - -func (s Service) IsRequestService() bool { - // some binapi messages might have `null` reply (for example: memclnt) - return s.ReplyType != "" && s.ReplyType != "null" // not null }