summaryrefslogtreecommitdiffstats
path: root/binapi/stn
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/stn
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/stn')
-rw-r--r--binapi/stn/stn.ba.go44
1 files changed, 16 insertions, 28 deletions
diff --git a/binapi/stn/stn.ba.go b/binapi/stn/stn.ba.go
index 34cb419..b44adf5 100644
--- a/binapi/stn/stn.ba.go
+++ b/binapi/stn/stn.ba.go
@@ -44,11 +44,10 @@ func (*StnAddDelRule) GetMessageType() api.MessageType {
return api.RequestMessage
}
-func (m *StnAddDelRule) Size() int {
+func (m *StnAddDelRule) Size() (size int) {
if m == nil {
return 0
}
- var size int
size += 1 // m.IPAddress.Af
size += 1 * 16 // m.IPAddress.Un
size += 4 // m.SwIfIndex
@@ -56,14 +55,12 @@ func (m *StnAddDelRule) Size() int {
return size
}
func (m *StnAddDelRule) 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.EncodeUint8(uint8(m.IPAddress.Af))
- buf.EncodeBytes(m.IPAddress.Un.XXX_UnionData[:], 0)
+ buf.EncodeBytes(m.IPAddress.Un.XXX_UnionData[:], 16)
buf.EncodeUint32(uint32(m.SwIfIndex))
buf.EncodeBool(m.IsAdd)
return buf.Bytes(), nil
@@ -89,27 +86,24 @@ func (*StnAddDelRuleReply) GetMessageType() api.MessageType {
return api.ReplyMessage
}
-func (m *StnAddDelRuleReply) Size() int {
+func (m *StnAddDelRuleReply) Size() (size int) {
if m == nil {
return 0
}
- var size int
size += 4 // m.Retval
return size
}
func (m *StnAddDelRuleReply) 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 *StnAddDelRuleReply) Unmarshal(b []byte) error {
buf := codec.NewBuffer(b)
- m.Retval = int32(buf.DecodeUint32())
+ m.Retval = buf.DecodeInt32()
return nil
}
@@ -126,25 +120,22 @@ func (*StnRulesDetails) GetMessageType() api.MessageType {
return api.ReplyMessage
}
-func (m *StnRulesDetails) Size() int {
+func (m *StnRulesDetails) Size() (size int) {
if m == nil {
return 0
}
- var size int
size += 1 // m.IPAddress.Af
size += 1 * 16 // m.IPAddress.Un
size += 4 // m.SwIfIndex
return size
}
func (m *StnRulesDetails) 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.EncodeUint8(uint8(m.IPAddress.Af))
- buf.EncodeBytes(m.IPAddress.Un.XXX_UnionData[:], 0)
+ buf.EncodeBytes(m.IPAddress.Un.XXX_UnionData[:], 16)
buf.EncodeUint32(uint32(m.SwIfIndex))
return buf.Bytes(), nil
}
@@ -166,20 +157,17 @@ func (*StnRulesDump) GetMessageType() api.MessageType {
return api.RequestMessage
}
-func (m *StnRulesDump) Size() int {
+func (m *StnRulesDump) Size() (size int) {
if m == nil {
return 0
}
- var size int
return size
}
func (m *StnRulesDump) 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 *StnRulesDump) Unmarshal(b []byte) error {