summaryrefslogtreecommitdiffstats
path: root/binapi/p2p_ethernet
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/p2p_ethernet
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/p2p_ethernet')
-rw-r--r--binapi/p2p_ethernet/p2p_ethernet.ba.go46
1 files changed, 17 insertions, 29 deletions
diff --git a/binapi/p2p_ethernet/p2p_ethernet.ba.go b/binapi/p2p_ethernet/p2p_ethernet.ba.go
index 5435390..2f76041 100644
--- a/binapi/p2p_ethernet/p2p_ethernet.ba.go
+++ b/binapi/p2p_ethernet/p2p_ethernet.ba.go
@@ -44,25 +44,22 @@ func (*P2pEthernetAdd) GetMessageType() api.MessageType {
return api.RequestMessage
}
-func (m *P2pEthernetAdd) Size() int {
+func (m *P2pEthernetAdd) Size() (size int) {
if m == nil {
return 0
}
- var size int
size += 4 // m.ParentIfIndex
size += 4 // m.SubifID
size += 1 * 6 // m.RemoteMac
return size
}
func (m *P2pEthernetAdd) 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.ParentIfIndex))
- buf.EncodeUint32(uint32(m.SubifID))
+ buf.EncodeUint32(m.SubifID)
buf.EncodeBytes(m.RemoteMac[:], 6)
return buf.Bytes(), nil
}
@@ -87,29 +84,26 @@ func (*P2pEthernetAddReply) GetMessageType() api.MessageType {
return api.ReplyMessage
}
-func (m *P2pEthernetAddReply) Size() int {
+func (m *P2pEthernetAddReply) Size() (size int) {
if m == nil {
return 0
}
- var size int
size += 4 // m.Retval
size += 4 // m.SwIfIndex
return size
}
func (m *P2pEthernetAddReply) 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)
buf.EncodeUint32(uint32(m.SwIfIndex))
return buf.Bytes(), nil
}
func (m *P2pEthernetAddReply) Unmarshal(b []byte) error {
buf := codec.NewBuffer(b)
- m.Retval = int32(buf.DecodeUint32())
+ m.Retval = buf.DecodeInt32()
m.SwIfIndex = interface_types.InterfaceIndex(buf.DecodeUint32())
return nil
}
@@ -127,22 +121,19 @@ func (*P2pEthernetDel) GetMessageType() api.MessageType {
return api.RequestMessage
}
-func (m *P2pEthernetDel) Size() int {
+func (m *P2pEthernetDel) Size() (size int) {
if m == nil {
return 0
}
- var size int
size += 4 // m.ParentIfIndex
size += 1 * 6 // m.RemoteMac
return size
}
func (m *P2pEthernetDel) 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.ParentIfIndex))
buf.EncodeBytes(m.RemoteMac[:], 6)
return buf.Bytes(), nil
@@ -166,27 +157,24 @@ func (*P2pEthernetDelReply) GetMessageType() api.MessageType {
return api.ReplyMessage
}
-func (m *P2pEthernetDelReply) Size() int {
+func (m *P2pEthernetDelReply) Size() (size int) {
if m == nil {
return 0
}
- var size int
size += 4 // m.Retval
return size
}
func (m *P2pEthernetDelReply) 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 *P2pEthernetDelReply) Unmarshal(b []byte) error {
buf := codec.NewBuffer(b)
- m.Retval = int32(buf.DecodeUint32())
+ m.Retval = buf.DecodeInt32()
return nil
}