X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=cmd%2Fbinapi-generator%2Fobjects.go;h=75c7581a77c68c3b2b286e7c5afbb2ec8b9274e4;hb=fa21c9d726ebb807895a8571af9a16dab5cd8d6e;hp=26810850f9c515a0a69fb0eedda29fad3d94ab5c;hpb=08ddeac03fd3832d44a3dfb48ee85ecd95d2b388;p=govpp.git diff --git a/cmd/binapi-generator/objects.go b/cmd/binapi-generator/objects.go index 2681085..75c7581 100644 --- a/cmd/binapi-generator/objects.go +++ b/cmd/binapi-generator/objects.go @@ -1,59 +1,24 @@ 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 + 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 -) - -// Message represents VPP binary API message -type Message struct { - Name string - CRC string - Fields []Field -} - -// Type represents VPP binary API type -type Type struct { - Name string - CRC string - Fields []Field -} - -// Union represents VPP binary API union -type Union struct { - Name string - CRC string - Fields []Field -} - -// 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 != "" +// Service represents VPP binary API service +type Service struct { + Name string + RequestType string + ReplyType string + Stream bool + Events []string } // Enum represents VPP binary API enum @@ -69,52 +34,48 @@ type EnumEntry struct { Value interface{} } -// Service represents VPP binary API service -type Service struct { - Name string - RequestType string - ReplyType string - Stream bool - Events []string +// Alias represents VPP binary API alias +type Alias struct { + Name string + Type string + Length int } -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 +// Type represents VPP binary API type +type Type struct { + Name string + CRC string + Fields []Field } -func (s Service) IsDumpService() bool { - return s.Stream +// Field represents VPP binary API object field +type Field struct { + Name string + Type string + Length int + SizeFrom string } -func (s Service) IsEventService() bool { - return len(s.Events) > 0 +// Union represents VPP binary API union +type Union struct { + Name string + CRC string + Fields []Field } -func (s Service) IsRequestService() bool { - // some binapi messages might have `null` reply (for example: memclnt) - return s.ReplyType != "" && s.ReplyType != "null" // not null +// Message represents VPP binary API message +type Message struct { + Name string + CRC string + Fields []Field } -func getSizeOfType(typ *Type) (size int) { - for _, field := range typ.Fields { - if n := getBinapiTypeSize(field.Type); n > 0 { - if field.Length > 0 { - size += n * field.Length - } else { - size += n - } - } - } - return size -} +// 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 +)