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/cop/cop.ba.go | |
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/cop/cop.ba.go')
-rw-r--r-- | binapi/cop/cop.ba.go | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/binapi/cop/cop.ba.go b/binapi/cop/cop.ba.go index a252c9a..14f0b11 100644 --- a/binapi/cop/cop.ba.go +++ b/binapi/cop/cop.ba.go @@ -42,22 +42,19 @@ func (*CopInterfaceEnableDisable) GetMessageType() api.MessageType { return api.RequestMessage } -func (m *CopInterfaceEnableDisable) Size() int { +func (m *CopInterfaceEnableDisable) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.SwIfIndex size += 1 // m.EnableDisable return size } func (m *CopInterfaceEnableDisable) 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.EnableDisable) return buf.Bytes(), nil @@ -83,27 +80,24 @@ func (*CopInterfaceEnableDisableReply) GetMessageType() api.MessageType { return api.ReplyMessage } -func (m *CopInterfaceEnableDisableReply) Size() int { +func (m *CopInterfaceEnableDisableReply) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.Retval return size } func (m *CopInterfaceEnableDisableReply) 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 *CopInterfaceEnableDisableReply) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) - m.Retval = int32(buf.DecodeUint32()) + m.Retval = buf.DecodeInt32() return nil } @@ -123,11 +117,10 @@ func (*CopWhitelistEnableDisable) GetMessageType() api.MessageType { return api.RequestMessage } -func (m *CopWhitelistEnableDisable) Size() int { +func (m *CopWhitelistEnableDisable) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.SwIfIndex size += 4 // m.FibID size += 1 // m.IP4 @@ -136,14 +129,12 @@ func (m *CopWhitelistEnableDisable) Size() int { return size } func (m *CopWhitelistEnableDisable) 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.EncodeUint32(uint32(m.FibID)) + buf.EncodeUint32(m.FibID) buf.EncodeBool(m.IP4) buf.EncodeBool(m.IP6) buf.EncodeBool(m.DefaultCop) @@ -173,27 +164,24 @@ func (*CopWhitelistEnableDisableReply) GetMessageType() api.MessageType { return api.ReplyMessage } -func (m *CopWhitelistEnableDisableReply) Size() int { +func (m *CopWhitelistEnableDisableReply) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.Retval return size } func (m *CopWhitelistEnableDisableReply) 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 *CopWhitelistEnableDisableReply) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) - m.Retval = int32(buf.DecodeUint32()) + m.Retval = buf.DecodeInt32() return nil } |