summaryrefslogtreecommitdiffstats
path: root/binapigen/binapigen.go
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2020-10-02 16:36:32 +0200
committerOndrej Fabry <ofabry@cisco.com>2020-10-02 16:36:32 +0200
commitc2456559a66107441addb96f673191bde09d6977 (patch)
tree30020a936849f78f432cf5b6fe0bbb0489e485b6 /binapigen/binapigen.go
parentf751f3f845ef56bbcdb873d81a1c6edbc5a87853 (diff)
Check retval value and convert to error in generated RPC client code
Change-Id: I816b4802cb5fc46239f6db0480fa4cf3645fe2f0 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'binapigen/binapigen.go')
-rw-r--r--binapigen/binapigen.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/binapigen/binapigen.go b/binapigen/binapigen.go
index 35a07d0..de6a804 100644
--- a/binapigen/binapigen.go
+++ b/binapigen/binapigen.go
@@ -243,8 +243,8 @@ func newStruct(gen *Generator, file *File, apitype vppapi.StructType) *Struct {
},
}
gen.structsByName[typ.Name] = typ
- for _, fieldType := range apitype.Fields {
- field := newField(gen, file, typ, fieldType)
+ for i, fieldType := range apitype.Fields {
+ field := newField(gen, file, typ, fieldType, i)
typ.Fields = append(typ.Fields, field)
}
return typ
@@ -276,8 +276,8 @@ func newUnion(gen *Generator, file *File, apitype vppapi.UnionType) *Union {
},
}
gen.unionsByName[typ.Name] = typ
- for _, fieldType := range apitype.Fields {
- field := newField(gen, file, typ, fieldType)
+ for i, fieldType := range apitype.Fields {
+ field := newField(gen, file, typ, fieldType, i)
typ.Fields = append(typ.Fields, field)
}
return typ
@@ -302,11 +302,12 @@ const (
msgTypeEvent // msg_id, client_index
)
-// message fields
+// common message fields
const (
fieldMsgID = "_vl_msg_id"
fieldClientIndex = "client_index"
fieldContext = "context"
+ fieldRetval = "retval"
)
// field options
@@ -343,7 +344,7 @@ func newMessage(gen *Generator, file *File, apitype vppapi.Message) *Message {
}
}
n++
- field := newField(gen, file, msg, fieldType)
+ field := newField(gen, file, msg, fieldType, n)
msg.Fields = append(msg.Fields, field)
}
return msg
@@ -394,12 +395,24 @@ func getMsgType(m vppapi.Message) (msgType, error) {
return typ, nil
}
+func getRetvalField(m *Message) *Field {
+ for _, field := range m.Fields {
+ if field.Name == fieldRetval {
+ return field
+ }
+ }
+ return nil
+}
+
// Field represents a field for message or struct/union types.
type Field struct {
vppapi.Field
GoName string
+ // Index defines field index in parent.
+ Index int
+
// DefaultValue is a default value of field or
// nil if default value is not defined for field.
DefaultValue interface{}
@@ -423,10 +436,11 @@ type Field struct {
FieldSizeFrom *Field
}
-func newField(gen *Generator, file *File, parent interface{}, apitype vppapi.Field) *Field {
+func newField(gen *Generator, file *File, parent interface{}, apitype vppapi.Field, index int) *Field {
typ := &Field{
Field: apitype,
GoName: camelCaseName(apitype.Name),
+ Index: index,
}
switch p := parent.(type) {
case *Message: