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/builtinurl/builtinurl.ba.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'binapi/builtinurl') diff --git a/binapi/builtinurl/builtinurl.ba.go b/binapi/builtinurl/builtinurl.ba.go index bfc593f..6b0350d 100644 --- a/binapi/builtinurl/builtinurl.ba.go +++ b/binapi/builtinurl/builtinurl.ba.go @@ -38,20 +38,17 @@ func (*BuiltinurlEnable) GetMessageType() api.MessageType { return api.RequestMessage } -func (m *BuiltinurlEnable) Size() int { +func (m *BuiltinurlEnable) Size() (size int) { if m == nil { return 0 } - var size int return size } func (m *BuiltinurlEnable) 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) return buf.Bytes(), nil } func (m *BuiltinurlEnable) Unmarshal(b []byte) error { @@ -70,27 +67,24 @@ func (*BuiltinurlEnableReply) GetMessageType() api.MessageType { return api.ReplyMessage } -func (m *BuiltinurlEnableReply) Size() int { +func (m *BuiltinurlEnableReply) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.Retval return size } func (m *BuiltinurlEnableReply) 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 *BuiltinurlEnableReply) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) - m.Retval = int32(buf.DecodeUint32()) + m.Retval = buf.DecodeInt32() return nil } -- cgit 1.2.3-korg