Improvements for binapi-generator and support VPP 19.04 in statsclient
[govpp.git] / cmd / binapi-generator / objects.go
1 package main
2
3 import "fmt"
4
5 // Package represents collection of objects parsed from VPP binary API JSON data
6 type Package struct {
7         Name     string
8         Version  string
9         CRC      string
10         Services []Service
11         Enums    []Enum
12         Aliases  []Alias
13         Types    []Type
14         Unions   []Union
15         Messages []Message
16         RefMap   map[string]string
17 }
18
19 // Service represents VPP binary API service
20 type Service struct {
21         Name        string
22         RequestType string
23         ReplyType   string
24         Stream      bool
25         Events      []string
26 }
27
28 // Enum represents VPP binary API enum
29 type Enum struct {
30         Name    string
31         Type    string
32         Entries []EnumEntry
33 }
34
35 // EnumEntry represents VPP binary API enum entry
36 type EnumEntry struct {
37         Name  string
38         Value interface{}
39 }
40
41 // Alias represents VPP binary API alias
42 type Alias struct {
43         Name   string
44         Type   string
45         Length int
46 }
47
48 // Type represents VPP binary API type
49 type Type struct {
50         Name   string
51         CRC    string
52         Fields []Field
53 }
54
55 // Field represents VPP binary API object field
56 type Field struct {
57         Name     string
58         Type     string
59         Length   int
60         SizeFrom string
61         Meta     FieldMeta
62 }
63
64 // FieldMeta represents VPP binary API meta info for field
65 type FieldMeta struct {
66         Limit int
67 }
68
69 // Union represents VPP binary API union
70 type Union struct {
71         Name   string
72         CRC    string
73         Fields []Field
74 }
75
76 // Message represents VPP binary API message
77 type Message struct {
78         Name   string
79         CRC    string
80         Fields []Field
81 }
82
83 // MessageType represents the type of a VPP message
84 type MessageType int
85
86 const (
87         requestMessage MessageType = iota // VPP request message
88         replyMessage                      // VPP reply message
89         eventMessage                      // VPP event message
90         otherMessage                      // other VPP message
91 )
92
93 // printPackage prints all loaded objects for package
94 func printPackage(pkg *Package) {
95         logf("package: %s %s (%s)", pkg.Name, pkg.Version, pkg.CRC)
96         if len(pkg.Enums) > 0 {
97                 logf(" %d enums:", len(pkg.Enums))
98                 for _, enum := range pkg.Enums {
99                         logf("  - %s: %+v", enum.Name, enum)
100                 }
101         }
102         if len(pkg.Unions) > 0 {
103                 logf(" %d unions:", len(pkg.Unions))
104                 for _, union := range pkg.Unions {
105                         logf("  - %s: %+v", union.Name, union)
106                 }
107         }
108         if len(pkg.Types) > 0 {
109                 logf(" %d types:", len(pkg.Types))
110                 for _, typ := range pkg.Types {
111                         logf("  - %s (%d fields): %+v", typ.Name, len(typ.Fields), typ)
112                 }
113         }
114         if len(pkg.Messages) > 0 {
115                 logf(" %d messages:", len(pkg.Messages))
116                 for _, msg := range pkg.Messages {
117                         logf("  - %s (%d fields) %s", msg.Name, len(msg.Fields), msg.CRC)
118                 }
119         }
120         if len(pkg.Services) > 0 {
121                 logf(" %d services:", len(pkg.Services))
122                 for _, svc := range pkg.Services {
123                         var info string
124                         if svc.Stream {
125                                 info = "(STREAM)"
126                         } else if len(svc.Events) > 0 {
127                                 info = fmt.Sprintf("(EVENTS: %v)", svc.Events)
128                         }
129                         logf("  - %s: %q -> %q %s", svc.Name, svc.RequestType, svc.ReplyType, info)
130                 }
131         }
132 }