From ceed73403bdb61387d04be8b47183e9c4a970749 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Tue, 23 Jun 2020 14:10:53 +0200 Subject: Fix codec fallback and generate type imports Change-Id: Idd76c7f19d952939caf153928ac60175845078ff Signed-off-by: Ondrej Fabry --- examples/binapi/vpe/vpe.ba.go | 158 ++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 100 deletions(-) (limited to 'examples/binapi/vpe/vpe.ba.go') diff --git a/examples/binapi/vpe/vpe.ba.go b/examples/binapi/vpe/vpe.ba.go index 4c00c86..b682d9f 100644 --- a/examples/binapi/vpe/vpe.ba.go +++ b/examples/binapi/vpe/vpe.ba.go @@ -1,11 +1,11 @@ // Code generated by GoVPP's binapi-generator. DO NOT EDIT. // versions: -// binapi-generator: v0.4.0-alpha-1-g435c3f4-dirty -// VPP: 20.01-45~g7a071e370~b63 +// binapi-generator: v0.4.0-dev +// VPP: 20.05-release // source: /usr/share/vpp/api/core/vpe.api.json /* -Package vpe contains generated code for VPP binary API defined by vpe.api (version 1.6.0). +Package vpe contains generated code for VPP API file vpe.api (1.6.1). It consists of: 2 aliases @@ -38,9 +38,9 @@ const ( // ModuleName is the name of this module. ModuleName = "vpe" // APIVersion is the API version of this module. - APIVersion = "1.6.0" + APIVersion = "1.6.1" // VersionCrc is the CRC of this module. - VersionCrc = 0xc6c0bcf6 + VersionCrc = 0xbd2c94f4 ) // LogLevel represents VPP binary API enum 'log_level'. @@ -100,8 +100,8 @@ type Timestamp float64 // ThreadData represents VPP binary API type 'thread_data'. type ThreadData struct { ID uint32 `binapi:"u32,name=id" json:"id,omitempty"` - Name []byte `binapi:"u8[64],name=name" json:"name,omitempty" struc:"[64]byte"` - Type []byte `binapi:"u8[64],name=type" json:"type,omitempty" struc:"[64]byte"` + Name string `binapi:"string[64],name=name" json:"name,omitempty" struc:"[64]byte"` + Type string `binapi:"string[64],name=type" json:"type,omitempty" struc:"[64]byte"` PID uint32 `binapi:"u32,name=pid" json:"pid,omitempty"` CPUID uint32 `binapi:"u32,name=cpu_id" json:"cpu_id,omitempty"` Core uint32 `binapi:"u32,name=core" json:"core,omitempty"` @@ -123,13 +123,13 @@ func (*Version) GetTypeName() string { return "version" } // AddNodeNext represents VPP binary API message 'add_node_next'. type AddNodeNext struct { - NodeName []byte `binapi:"u8[64],name=node_name" json:"node_name,omitempty" struc:"[64]byte"` - NextName []byte `binapi:"u8[64],name=next_name" json:"next_name,omitempty" struc:"[64]byte"` + NodeName string `binapi:"string[64],name=node_name" json:"node_name,omitempty" struc:"[64]byte"` + NextName string `binapi:"string[64],name=next_name" json:"next_name,omitempty" struc:"[64]byte"` } func (m *AddNodeNext) Reset() { *m = AddNodeNext{} } func (*AddNodeNext) GetMessageName() string { return "add_node_next" } -func (*AddNodeNext) GetCrcString() string { return "9ab92f7a" } +func (*AddNodeNext) GetCrcString() string { return "2457116d" } func (*AddNodeNext) GetMessageType() api.MessageType { return api.RequestMessage } func (m *AddNodeNext) Size() int { @@ -155,23 +155,11 @@ func (m *AddNodeNext) Marshal(b []byte) ([]byte, error) { buf = b } // field[1] m.NodeName - for i := 0; i < 64; i++ { - var x uint8 - if i < len(m.NodeName) { - x = uint8(m.NodeName[i]) - } - buf[pos] = uint8(x) - pos += 1 - } + copy(buf[pos:pos+64], m.NodeName) + pos += 64 // field[1] m.NextName - for i := 0; i < 64; i++ { - var x uint8 - if i < len(m.NextName) { - x = uint8(m.NextName[i]) - } - buf[pos] = uint8(x) - pos += 1 - } + copy(buf[pos:pos+64], m.NextName) + pos += 64 return buf, nil } func (m *AddNodeNext) Unmarshal(tmp []byte) error { @@ -180,16 +168,16 @@ func (m *AddNodeNext) Unmarshal(tmp []byte) error { pos := 0 _ = pos // field[1] m.NodeName - m.NodeName = make([]uint8, 64) - for i := 0; i < len(m.NodeName); i++ { - m.NodeName[i] = uint8(tmp[pos]) - pos += 1 + { + nul := bytes.Index(tmp[pos:pos+64], []byte{0x00}) + m.NodeName = codec.DecodeString(tmp[pos : pos+nul]) + pos += 64 } // field[1] m.NextName - m.NextName = make([]uint8, 64) - for i := 0; i < len(m.NextName); i++ { - m.NextName[i] = uint8(tmp[pos]) - pos += 1 + { + nul := bytes.Index(tmp[pos:pos+64], []byte{0x00}) + m.NextName = codec.DecodeString(tmp[pos : pos+nul]) + pos += 64 } return nil } @@ -769,13 +757,13 @@ func (m *GetF64IncrementByOneReply) Unmarshal(tmp []byte) error { // GetNextIndex represents VPP binary API message 'get_next_index'. type GetNextIndex struct { - NodeName []byte `binapi:"u8[64],name=node_name" json:"node_name,omitempty" struc:"[64]byte"` - NextName []byte `binapi:"u8[64],name=next_name" json:"next_name,omitempty" struc:"[64]byte"` + NodeName string `binapi:"string[64],name=node_name" json:"node_name,omitempty" struc:"[64]byte"` + NextName string `binapi:"string[64],name=next_name" json:"next_name,omitempty" struc:"[64]byte"` } func (m *GetNextIndex) Reset() { *m = GetNextIndex{} } func (*GetNextIndex) GetMessageName() string { return "get_next_index" } -func (*GetNextIndex) GetCrcString() string { return "9ab92f7a" } +func (*GetNextIndex) GetCrcString() string { return "2457116d" } func (*GetNextIndex) GetMessageType() api.MessageType { return api.RequestMessage } func (m *GetNextIndex) Size() int { @@ -801,23 +789,11 @@ func (m *GetNextIndex) Marshal(b []byte) ([]byte, error) { buf = b } // field[1] m.NodeName - for i := 0; i < 64; i++ { - var x uint8 - if i < len(m.NodeName) { - x = uint8(m.NodeName[i]) - } - buf[pos] = uint8(x) - pos += 1 - } + copy(buf[pos:pos+64], m.NodeName) + pos += 64 // field[1] m.NextName - for i := 0; i < 64; i++ { - var x uint8 - if i < len(m.NextName) { - x = uint8(m.NextName[i]) - } - buf[pos] = uint8(x) - pos += 1 - } + copy(buf[pos:pos+64], m.NextName) + pos += 64 return buf, nil } func (m *GetNextIndex) Unmarshal(tmp []byte) error { @@ -826,16 +802,16 @@ func (m *GetNextIndex) Unmarshal(tmp []byte) error { pos := 0 _ = pos // field[1] m.NodeName - m.NodeName = make([]uint8, 64) - for i := 0; i < len(m.NodeName); i++ { - m.NodeName[i] = uint8(tmp[pos]) - pos += 1 + { + nul := bytes.Index(tmp[pos:pos+64], []byte{0x00}) + m.NodeName = codec.DecodeString(tmp[pos : pos+nul]) + pos += 64 } // field[1] m.NextName - m.NextName = make([]uint8, 64) - for i := 0; i < len(m.NextName); i++ { - m.NextName[i] = uint8(tmp[pos]) - pos += 1 + { + nul := bytes.Index(tmp[pos:pos+64], []byte{0x00}) + m.NextName = codec.DecodeString(tmp[pos : pos+nul]) + pos += 64 } return nil } @@ -988,12 +964,12 @@ func (m *GetNodeGraphReply) Unmarshal(tmp []byte) error { // GetNodeIndex represents VPP binary API message 'get_node_index'. type GetNodeIndex struct { - NodeName []byte `binapi:"u8[64],name=node_name" json:"node_name,omitempty" struc:"[64]byte"` + NodeName string `binapi:"string[64],name=node_name" json:"node_name,omitempty" struc:"[64]byte"` } func (m *GetNodeIndex) Reset() { *m = GetNodeIndex{} } func (*GetNodeIndex) GetMessageName() string { return "get_node_index" } -func (*GetNodeIndex) GetCrcString() string { return "6c9a495d" } +func (*GetNodeIndex) GetCrcString() string { return "f1984c64" } func (*GetNodeIndex) GetMessageType() api.MessageType { return api.RequestMessage } func (m *GetNodeIndex) Size() int { @@ -1017,14 +993,8 @@ func (m *GetNodeIndex) Marshal(b []byte) ([]byte, error) { buf = b } // field[1] m.NodeName - for i := 0; i < 64; i++ { - var x uint8 - if i < len(m.NodeName) { - x = uint8(m.NodeName[i]) - } - buf[pos] = uint8(x) - pos += 1 - } + copy(buf[pos:pos+64], m.NodeName) + pos += 64 return buf, nil } func (m *GetNodeIndex) Unmarshal(tmp []byte) error { @@ -1033,10 +1003,10 @@ func (m *GetNodeIndex) Unmarshal(tmp []byte) error { pos := 0 _ = pos // field[1] m.NodeName - m.NodeName = make([]uint8, 64) - for i := 0; i < len(m.NodeName); i++ { - m.NodeName[i] = uint8(tmp[pos]) - pos += 1 + { + nul := bytes.Index(tmp[pos:pos+64], []byte{0x00}) + m.NodeName = codec.DecodeString(tmp[pos : pos+nul]) + pos += 64 } return nil } @@ -1266,7 +1236,7 @@ type ShowThreadsReply struct { func (m *ShowThreadsReply) Reset() { *m = ShowThreadsReply{} } func (*ShowThreadsReply) GetMessageName() string { return "show_threads_reply" } -func (*ShowThreadsReply) GetCrcString() string { return "f5e0b66f" } +func (*ShowThreadsReply) GetCrcString() string { return "efd78e83" } func (*ShowThreadsReply) GetMessageType() api.MessageType { return api.ReplyMessage } func (m *ShowThreadsReply) Size() int { @@ -1329,23 +1299,11 @@ func (m *ShowThreadsReply) Marshal(b []byte) ([]byte, error) { o.PutUint32(buf[pos:pos+4], uint32(v1.ID)) pos += 4 // field[2] v1.Name - for i := 0; i < 64; i++ { - var x uint8 - if i < len(v1.Name) { - x = uint8(v1.Name[i]) - } - buf[pos] = uint8(x) - pos += 1 - } + copy(buf[pos:pos+64], v1.Name) + pos += 64 // field[2] v1.Type - for i := 0; i < 64; i++ { - var x uint8 - if i < len(v1.Type) { - x = uint8(v1.Type[i]) - } - buf[pos] = uint8(x) - pos += 1 - } + copy(buf[pos:pos+64], v1.Type) + pos += 64 // field[2] v1.PID o.PutUint32(buf[pos:pos+4], uint32(v1.PID)) pos += 4 @@ -1379,16 +1337,16 @@ func (m *ShowThreadsReply) Unmarshal(tmp []byte) error { m.ThreadData[j1].ID = uint32(o.Uint32(tmp[pos : pos+4])) pos += 4 // field[2] m.ThreadData[j1].Name - m.ThreadData[j1].Name = make([]uint8, 64) - for i := 0; i < len(m.ThreadData[j1].Name); i++ { - m.ThreadData[j1].Name[i] = uint8(tmp[pos]) - pos += 1 + { + nul := bytes.Index(tmp[pos:pos+64], []byte{0x00}) + m.ThreadData[j1].Name = codec.DecodeString(tmp[pos : pos+nul]) + pos += 64 } // field[2] m.ThreadData[j1].Type - m.ThreadData[j1].Type = make([]uint8, 64) - for i := 0; i < len(m.ThreadData[j1].Type); i++ { - m.ThreadData[j1].Type[i] = uint8(tmp[pos]) - pos += 1 + { + nul := bytes.Index(tmp[pos:pos+64], []byte{0x00}) + m.ThreadData[j1].Type = codec.DecodeString(tmp[pos : pos+nul]) + pos += 64 } // field[2] m.ThreadData[j1].PID m.ThreadData[j1].PID = uint32(o.Uint32(tmp[pos : pos+4])) -- cgit 1.2.3-korg