diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2020-07-22 04:40:55 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2020-07-22 04:40:55 +0200 |
commit | 58da9ac6e691a8c660eb8ca838a154e11da0db68 (patch) | |
tree | a1bbda04c6d0621ce0fc20779276620f1820190b /binapi/vxlan_gpe | |
parent | a155cd438c6558da266c1c5931361ea088b35653 (diff) |
Fix binapigen decoding and minor improvements
- fixed allocating byte slices before copying decoded data
- simplified encoding functions
- several minor improvements
Change-Id: I6669424b89eb86333805cb1b57e4551169980cc2
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'binapi/vxlan_gpe')
-rw-r--r-- | binapi/vxlan_gpe/vxlan_gpe.ba.go | 82 |
1 files changed, 32 insertions, 50 deletions
diff --git a/binapi/vxlan_gpe/vxlan_gpe.ba.go b/binapi/vxlan_gpe/vxlan_gpe.ba.go index 9da919d..0858ada 100644 --- a/binapi/vxlan_gpe/vxlan_gpe.ba.go +++ b/binapi/vxlan_gpe/vxlan_gpe.ba.go @@ -46,23 +46,20 @@ func (*SwInterfaceSetVxlanGpeBypass) GetMessageType() api.MessageType { return api.RequestMessage } -func (m *SwInterfaceSetVxlanGpeBypass) Size() int { +func (m *SwInterfaceSetVxlanGpeBypass) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.SwIfIndex size += 1 // m.IsIPv6 size += 1 // m.Enable return size } func (m *SwInterfaceSetVxlanGpeBypass) Marshal(b []byte) ([]byte, error) { - var buf *codec.Buffer if b == nil { - buf = codec.NewBuffer(make([]byte, m.Size())) - } else { - buf = codec.NewBuffer(b) + b = make([]byte, m.Size()) } + buf := codec.NewBuffer(b) buf.EncodeUint32(uint32(m.SwIfIndex)) buf.EncodeBool(m.IsIPv6) buf.EncodeBool(m.Enable) @@ -90,27 +87,24 @@ func (*SwInterfaceSetVxlanGpeBypassReply) GetMessageType() api.MessageType { return api.ReplyMessage } -func (m *SwInterfaceSetVxlanGpeBypassReply) Size() int { +func (m *SwInterfaceSetVxlanGpeBypassReply) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.Retval return size } func (m *SwInterfaceSetVxlanGpeBypassReply) Marshal(b []byte) ([]byte, error) { - var buf *codec.Buffer if b == nil { - buf = codec.NewBuffer(make([]byte, m.Size())) - } else { - buf = codec.NewBuffer(b) + b = make([]byte, m.Size()) } - buf.EncodeUint32(uint32(m.Retval)) + buf := codec.NewBuffer(b) + buf.EncodeInt32(m.Retval) return buf.Bytes(), nil } func (m *SwInterfaceSetVxlanGpeBypassReply) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) - m.Retval = int32(buf.DecodeUint32()) + m.Retval = buf.DecodeInt32() return nil } @@ -133,11 +127,10 @@ func (*VxlanGpeAddDelTunnel) GetMessageType() api.MessageType { return api.RequestMessage } -func (m *VxlanGpeAddDelTunnel) Size() int { +func (m *VxlanGpeAddDelTunnel) Size() (size int) { if m == nil { return 0 } - var size int size += 1 // m.Local.Af size += 1 * 16 // m.Local.Un size += 1 // m.Remote.Af @@ -151,21 +144,19 @@ func (m *VxlanGpeAddDelTunnel) Size() int { return size } func (m *VxlanGpeAddDelTunnel) Marshal(b []byte) ([]byte, error) { - var buf *codec.Buffer if b == nil { - buf = codec.NewBuffer(make([]byte, m.Size())) - } else { - buf = codec.NewBuffer(b) + b = make([]byte, m.Size()) } + buf := codec.NewBuffer(b) buf.EncodeUint8(uint8(m.Local.Af)) - buf.EncodeBytes(m.Local.Un.XXX_UnionData[:], 0) + buf.EncodeBytes(m.Local.Un.XXX_UnionData[:], 16) buf.EncodeUint8(uint8(m.Remote.Af)) - buf.EncodeBytes(m.Remote.Un.XXX_UnionData[:], 0) + buf.EncodeBytes(m.Remote.Un.XXX_UnionData[:], 16) buf.EncodeUint32(uint32(m.McastSwIfIndex)) - buf.EncodeUint32(uint32(m.EncapVrfID)) - buf.EncodeUint32(uint32(m.DecapVrfID)) + buf.EncodeUint32(m.EncapVrfID) + buf.EncodeUint32(m.DecapVrfID) buf.EncodeUint8(uint8(m.Protocol)) - buf.EncodeUint32(uint32(m.Vni)) + buf.EncodeUint32(m.Vni) buf.EncodeBool(m.IsAdd) return buf.Bytes(), nil } @@ -197,29 +188,26 @@ func (*VxlanGpeAddDelTunnelReply) GetMessageType() api.MessageType { return api.ReplyMessage } -func (m *VxlanGpeAddDelTunnelReply) Size() int { +func (m *VxlanGpeAddDelTunnelReply) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.Retval size += 4 // m.SwIfIndex return size } func (m *VxlanGpeAddDelTunnelReply) Marshal(b []byte) ([]byte, error) { - var buf *codec.Buffer if b == nil { - buf = codec.NewBuffer(make([]byte, m.Size())) - } else { - buf = codec.NewBuffer(b) + b = make([]byte, m.Size()) } - buf.EncodeUint32(uint32(m.Retval)) + buf := codec.NewBuffer(b) + buf.EncodeInt32(m.Retval) buf.EncodeUint32(uint32(m.SwIfIndex)) return buf.Bytes(), nil } func (m *VxlanGpeAddDelTunnelReply) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) - m.Retval = int32(buf.DecodeUint32()) + m.Retval = buf.DecodeInt32() m.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32()) return nil } @@ -244,11 +232,10 @@ func (*VxlanGpeTunnelDetails) GetMessageType() api.MessageType { return api.ReplyMessage } -func (m *VxlanGpeTunnelDetails) Size() int { +func (m *VxlanGpeTunnelDetails) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.SwIfIndex size += 1 // m.Local.Af size += 1 * 16 // m.Local.Un @@ -263,22 +250,20 @@ func (m *VxlanGpeTunnelDetails) Size() int { return size } func (m *VxlanGpeTunnelDetails) Marshal(b []byte) ([]byte, error) { - var buf *codec.Buffer if b == nil { - buf = codec.NewBuffer(make([]byte, m.Size())) - } else { - buf = codec.NewBuffer(b) + b = make([]byte, m.Size()) } + buf := codec.NewBuffer(b) buf.EncodeUint32(uint32(m.SwIfIndex)) buf.EncodeUint8(uint8(m.Local.Af)) - buf.EncodeBytes(m.Local.Un.XXX_UnionData[:], 0) + buf.EncodeBytes(m.Local.Un.XXX_UnionData[:], 16) buf.EncodeUint8(uint8(m.Remote.Af)) - buf.EncodeBytes(m.Remote.Un.XXX_UnionData[:], 0) - buf.EncodeUint32(uint32(m.Vni)) + buf.EncodeBytes(m.Remote.Un.XXX_UnionData[:], 16) + buf.EncodeUint32(m.Vni) buf.EncodeUint8(uint8(m.Protocol)) buf.EncodeUint32(uint32(m.McastSwIfIndex)) - buf.EncodeUint32(uint32(m.EncapVrfID)) - buf.EncodeUint32(uint32(m.DecapVrfID)) + buf.EncodeUint32(m.EncapVrfID) + buf.EncodeUint32(m.DecapVrfID) buf.EncodeBool(m.IsIPv6) return buf.Bytes(), nil } @@ -310,21 +295,18 @@ func (*VxlanGpeTunnelDump) GetMessageType() api.MessageType { return api.RequestMessage } -func (m *VxlanGpeTunnelDump) Size() int { +func (m *VxlanGpeTunnelDump) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.SwIfIndex return size } func (m *VxlanGpeTunnelDump) Marshal(b []byte) ([]byte, error) { - var buf *codec.Buffer if b == nil { - buf = codec.NewBuffer(make([]byte, m.Size())) - } else { - buf = codec.NewBuffer(b) + b = make([]byte, m.Size()) } + buf := codec.NewBuffer(b) buf.EncodeUint32(uint32(m.SwIfIndex)) return buf.Bytes(), nil } |