aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/binapi-generator/objects.go
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-06-06 14:08:48 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-06-06 14:08:48 +0200
commitc4522fe10317b1729a0820dc880afc78c663f64d (patch)
tree3c370f285b3d00feb5857ca155f7e46ae8765f7f /cmd/binapi-generator/objects.go
parent0ff02b6b1f0757f5e4c011457757bd18d0a60f01 (diff)
Add various generator improvements
- generate service implementation for modules - generate conversion maps and String() method for enums - generate module name and version as constants - rename Union_data field to XXX_UnionData for consistency - generate constant GoVppAPIPackageIsVersionN for checking compatibility with API - add example for using service clients - add some documentation to socketclient adapter - cleanup gen.go file used for generating binapi - regenerate binapi with latest VPP release (19.04.1) - change global variables Messages into a function AllMessages Change-Id: Id1ef97764570759eaa3e5a4dc14ecda7a168ee39 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'cmd/binapi-generator/objects.go')
-rw-r--r--cmd/binapi-generator/objects.go59
1 files changed, 51 insertions, 8 deletions
diff --git a/cmd/binapi-generator/objects.go b/cmd/binapi-generator/objects.go
index 8f5e8ef..e3270de 100644
--- a/cmd/binapi-generator/objects.go
+++ b/cmd/binapi-generator/objects.go
@@ -1,15 +1,18 @@
package main
+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
+ Version string
+ CRC string
+ Services []Service
+ Enums []Enum
+ Aliases []Alias
+ Types []Type
+ Unions []Union
+ Messages []Message
+ RefMap map[string]string
}
// Service represents VPP binary API service
@@ -85,3 +88,43 @@ const (
eventMessage // VPP event message
otherMessage // other VPP message
)
+
+// printPackage prints all loaded objects for package
+func printPackage(pkg *Package) {
+ if len(pkg.Enums) > 0 {
+ logf("loaded %d enums:", len(pkg.Enums))
+ for k, enum := range pkg.Enums {
+ logf(" - enum #%d\t%+v", k, enum)
+ }
+ }
+ if len(pkg.Unions) > 0 {
+ logf("loaded %d unions:", len(pkg.Unions))
+ for k, union := range pkg.Unions {
+ logf(" - union #%d\t%+v", k, union)
+ }
+ }
+ if len(pkg.Types) > 0 {
+ logf("loaded %d types:", len(pkg.Types))
+ for _, typ := range pkg.Types {
+ logf(" - type: %q (%d fields)", typ.Name, len(typ.Fields))
+ }
+ }
+ if len(pkg.Messages) > 0 {
+ logf("loaded %d messages:", len(pkg.Messages))
+ for _, msg := range pkg.Messages {
+ logf(" - message: %q (%d fields)", msg.Name, len(msg.Fields))
+ }
+ }
+ if len(pkg.Services) > 0 {
+ logf("loaded %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(" - service: %s - %q -> %q %s", svc.Name, svc.RequestType, svc.ReplyType, info)
+ }
+ }
+}