github.com/vishvananda/netlink@v1.3.0/nl/bridge_linux_test.go (about) 1 package nl 2 3 import ( 4 "bytes" 5 "crypto/rand" 6 "encoding/binary" 7 "testing" 8 ) 9 10 func (msg *BridgeVlanInfo) write(b []byte) { 11 native := NativeEndian() 12 native.PutUint16(b[0:2], msg.Flags) 13 native.PutUint16(b[2:4], msg.Vid) 14 } 15 16 func (msg *BridgeVlanInfo) serializeSafe() []byte { 17 length := SizeofBridgeVlanInfo 18 b := make([]byte, length) 19 msg.write(b) 20 return b 21 } 22 23 func deserializeBridgeVlanInfoSafe(b []byte) *BridgeVlanInfo { 24 var msg = BridgeVlanInfo{} 25 binary.Read(bytes.NewReader(b[0:SizeofBridgeVlanInfo]), NativeEndian(), &msg) 26 return &msg 27 } 28 29 func TestBridgeVlanInfoDeserializeSerialize(t *testing.T) { 30 var orig = make([]byte, SizeofBridgeVlanInfo) 31 rand.Read(orig) 32 safemsg := deserializeBridgeVlanInfoSafe(orig) 33 msg := DeserializeBridgeVlanInfo(orig) 34 testDeserializeSerialize(t, orig, safemsg, msg) 35 }