aboutsummaryrefslogtreecommitdiffstats
path: root/binapi/urpf/urpf.ba.go
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2020-07-22 04:40:55 +0200
committerOndrej Fabry <ofabry@cisco.com>2020-07-22 04:40:55 +0200
commit58da9ac6e691a8c660eb8ca838a154e11da0db68 (patch)
treea1bbda04c6d0621ce0fc20779276620f1820190b /binapi/urpf/urpf.ba.go
parenta155cd438c6558da266c1c5931361ea088b35653 (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/urpf/urpf.ba.go')
-rw-r--r--binapi/urpf/urpf.ba.go22
1 files changed, 8 insertions, 14 deletions
diff --git a/binapi/urpf/urpf.ba.go b/binapi/urpf/urpf.ba.go
index d324bdb..c504cfb 100644
--- a/binapi/urpf/urpf.ba.go
+++ b/binapi/urpf/urpf.ba.go
@@ -78,11 +78,10 @@ func (*UrpfUpdate) GetMessageType() api.MessageType {
return api.RequestMessage
}
-func (m *UrpfUpdate) Size() int {
+func (m *UrpfUpdate) Size() (size int) {
if m == nil {
return 0
}
- var size int
size += 1 // m.IsInput
size += 1 // m.Mode
size += 1 // m.Af
@@ -90,12 +89,10 @@ func (m *UrpfUpdate) Size() int {
return size
}
func (m *UrpfUpdate) 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.IsInput)
buf.EncodeUint8(uint8(m.Mode))
buf.EncodeUint8(uint8(m.Af))
@@ -123,27 +120,24 @@ func (*UrpfUpdateReply) GetMessageType() api.MessageType {
return api.ReplyMessage
}
-func (m *UrpfUpdateReply) Size() int {
+func (m *UrpfUpdateReply) Size() (size int) {
if m == nil {
return 0
}
- var size int
size += 4 // m.Retval
return size
}
func (m *UrpfUpdateReply) 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 *UrpfUpdateReply) Unmarshal(b []byte) error {
buf := codec.NewBuffer(b)
- m.Retval = int32(buf.DecodeUint32())
+ m.Retval = buf.DecodeInt32()
return nil
}