diff options
author | 2018-08-21 22:32:11 +0200 | |
---|---|---|
committer | 2018-08-21 22:32:11 +0200 | |
commit | 08ddeac03fd3832d44a3dfb48ee85ecd95d2b388 (patch) | |
tree | 6b94f6acc86686dfb078cd21c7d67865cac4ae8f /cmd/binapi-generator/objects.go | |
parent | c4ccfc75f0698e148cfa37a3a1dda1a46bb29109 (diff) |
Make the warnings for validating services more obvious
- there is currently simple validation for services,
which checks type of services and its name for request/reply
- there is one known warning in dhcp package for dhcp_client_config,
since it is single case for normal requests subscribing to event
Change-Id: I504a52b9a1823ced841b2ead712318ef5e5477b1
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'cmd/binapi-generator/objects.go')
-rw-r--r-- | cmd/binapi-generator/objects.go | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/cmd/binapi-generator/objects.go b/cmd/binapi-generator/objects.go new file mode 100644 index 0000000..2681085 --- /dev/null +++ b/cmd/binapi-generator/objects.go @@ -0,0 +1,120 @@ +package main + +import "strings" + +// Package represents collection of objects parsed from VPP binary API JSON data +type Package struct { + APIVersion string + Enums []Enum + Unions []Union + Types []Type + 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 != "" +} + +// 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 +} + +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 +} + +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 +} |