Generator improvements and cleanup
[govpp.git] / cmd / binapi-generator / objects.go
index 97318cb..75c7581 100644 (file)
@@ -1,41 +1,37 @@
 package main
 
-import "strings"
-
 // Package represents collection of objects parsed from VPP binary API JSON data
 type Package struct {
        APIVersion string
+       Services   []Service
        Enums      []Enum
-       Unions     []Union
-       Types      []Type
        Aliases    []Alias
+       Types      []Type
+       Unions     []Union
        Messages   []Message
-       Services   []Service
        RefMap     map[string]string
 }
 
-// MessageType represents the type of a VPP message
-type MessageType int
-
-const (
-       requestMessage MessageType = iota // VPP request message
-       replyMessage                      // VPP reply message
-       eventMessage                      // VPP event message
-       otherMessage                      // other VPP message
-)
+// Service represents VPP binary API service
+type Service struct {
+       Name        string
+       RequestType string
+       ReplyType   string
+       Stream      bool
+       Events      []string
+}
 
-// Message represents VPP binary API message
-type Message struct {
-       Name   string
-       CRC    string
-       Fields []Field
+// Enum represents VPP binary API enum
+type Enum struct {
+       Name    string
+       Type    string
+       Entries []EnumEntry
 }
 
-// Type represents VPP binary API type
-type Type struct {
-       Name   string
-       CRC    string
-       Fields []Field
+// EnumEntry represents VPP binary API enum entry
+type EnumEntry struct {
+       Name  string
+       Value interface{}
 }
 
 // Alias represents VPP binary API alias
@@ -45,8 +41,8 @@ type Alias struct {
        Length int
 }
 
-// Union represents VPP binary API union
-type Union struct {
+// Type represents VPP binary API type
+type Type struct {
        Name   string
        CRC    string
        Fields []Field
@@ -60,56 +56,26 @@ type Field struct {
        SizeFrom string
 }
 
-func (f *Field) IsArray() bool {
-       return f.Length > 0 || f.SizeFrom != ""
-}
-
-// Enum represents VPP binary API enum
-type Enum struct {
-       Name    string
-       Type    string
-       Entries []EnumEntry
-}
-
-// EnumEntry represents VPP binary API enum entry
-type EnumEntry struct {
-       Name  string
-       Value interface{}
-}
-
-// Service represents VPP binary API service
-type Service struct {
-       Name        string
-       RequestType string
-       ReplyType   string
-       Stream      bool
-       Events      []string
-}
-
-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
-               }
-       }
-
-       return method
+// Union represents VPP binary API union
+type Union struct {
+       Name   string
+       CRC    string
+       Fields []Field
 }
 
-func (s Service) IsDumpService() bool {
-       return s.Stream
+// Message represents VPP binary API message
+type Message struct {
+       Name   string
+       CRC    string
+       Fields []Field
 }
 
-func (s Service) IsEventService() bool {
-       return len(s.Events) > 0
-}
+// MessageType represents the type of a VPP message
+type MessageType int
 
-func (s Service) IsRequestService() bool {
-       // some binapi messages might have `null` reply (for example: memclnt)
-       return s.ReplyType != "" && s.ReplyType != "null" // not null
-}
+const (
+       requestMessage MessageType = iota // VPP request message
+       replyMessage                      // VPP reply message
+       eventMessage                      // VPP event message
+       otherMessage                      // other VPP message
+)