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/ioam_export/ioam_export.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/ioam_export/ioam_export.ba.go')
-rw-r--r-- | binapi/ioam_export/ioam_export.ba.go | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/binapi/ioam_export/ioam_export.ba.go b/binapi/ioam_export/ioam_export.ba.go index b95f506..47dd4e2 100644 --- a/binapi/ioam_export/ioam_export.ba.go +++ b/binapi/ioam_export/ioam_export.ba.go @@ -43,23 +43,20 @@ func (*IoamExportIP6EnableDisable) GetMessageType() api.MessageType { return api.RequestMessage } -func (m *IoamExportIP6EnableDisable) Size() int { +func (m *IoamExportIP6EnableDisable) Size() (size int) { if m == nil { return 0 } - var size int size += 1 // m.IsDisable size += 1 * 4 // m.CollectorAddress size += 1 * 4 // m.SrcAddress return size } func (m *IoamExportIP6EnableDisable) 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.EncodeBool(m.IsDisable) buf.EncodeBytes(m.CollectorAddress[:], 4) buf.EncodeBytes(m.SrcAddress[:], 4) @@ -87,27 +84,24 @@ func (*IoamExportIP6EnableDisableReply) GetMessageType() api.MessageType { return api.ReplyMessage } -func (m *IoamExportIP6EnableDisableReply) Size() int { +func (m *IoamExportIP6EnableDisableReply) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.Retval return size } func (m *IoamExportIP6EnableDisableReply) 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 *IoamExportIP6EnableDisableReply) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) - m.Retval = int32(buf.DecodeUint32()) + m.Retval = buf.DecodeInt32() return nil } |