From 58da9ac6e691a8c660eb8ca838a154e11da0db68 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Wed, 22 Jul 2020 04:40:55 +0200 Subject: 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 --- binapi/feature/feature.ba.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'binapi/feature') diff --git a/binapi/feature/feature.ba.go b/binapi/feature/feature.ba.go index 4d16ce8..cc54364 100644 --- a/binapi/feature/feature.ba.go +++ b/binapi/feature/feature.ba.go @@ -44,11 +44,10 @@ func (*FeatureEnableDisable) GetMessageType() api.MessageType { return api.RequestMessage } -func (m *FeatureEnableDisable) Size() int { +func (m *FeatureEnableDisable) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.SwIfIndex size += 1 // m.Enable size += 64 // m.ArcName @@ -56,12 +55,10 @@ func (m *FeatureEnableDisable) Size() int { return size } func (m *FeatureEnableDisable) 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.Enable) buf.EncodeString(m.ArcName, 64) @@ -89,27 +86,24 @@ func (*FeatureEnableDisableReply) GetMessageType() api.MessageType { return api.ReplyMessage } -func (m *FeatureEnableDisableReply) Size() int { +func (m *FeatureEnableDisableReply) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.Retval return size } func (m *FeatureEnableDisableReply) 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 *FeatureEnableDisableReply) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) - m.Retval = int32(buf.DecodeUint32()) + m.Retval = buf.DecodeInt32() return nil } -- cgit 1.2.3-korg