-
-func TestSize(t *testing.T) {
- m := NewTestAllMsg()
- size := binary.Size(*m)
- t.Logf("size: %v", size)
-}
-
-func (m *TestAllMsg) Marshal(b []byte) ([]byte, error) {
- order := binary.BigEndian
- tmp := make([]byte, 143)
- pos := 0
-
- tmp[pos] = boolToUint(m.Bool)
- pos += 1
-
- tmp[pos] = m.Uint8
- pos += 1
-
- order.PutUint16(tmp[pos:pos+2], m.Uint16)
- pos += 2
-
- order.PutUint32(tmp[pos:pos+4], m.Uint32)
- pos += 4
-
- tmp[pos] = byte(m.Int8)
- pos += 1
-
- order.PutUint16(tmp[pos:pos+2], uint16(m.Int16))
- pos += 2
-
- order.PutUint32(tmp[pos:pos+4], uint32(m.Int32))
- pos += 4
-
- order.PutUint32(tmp[pos:pos+4], uint32(m.AliasUint32))
- pos += 4
-
- copy(tmp[pos:pos+6], m.AliasArray[:])
- pos += 6
-
- order.PutUint32(tmp[pos:pos+4], uint32(m.Enum))
- pos += 4
-
- for i := 0; i < 4; i++ {
- var x uint32
- if i < len(m.BaseArray) {
- x = m.BaseArray[i]
- }
- order.PutUint32(tmp[pos:pos+4], uint32(x))
- pos += 4
- }
-
- copy(tmp[pos:pos+7], m.Slice)
- pos += 7
-
- copy(tmp[pos:pos+64], m.String)
- pos += 64
-
- order.PutUint32(tmp[pos:pos+4], uint32(len(m.VlaStr)) /*m.SizeOf*/)
- pos += 4
-
- copy(tmp[pos:pos+len(m.VlaStr)], m.VlaStr[:])
- pos += len(m.VlaStr)
-
- order.PutUint32(tmp[pos:pos+4], uint32(len(m.VariableSlice)) /*m.SizeOf*/)
- pos += 4
-
- for i := range m.VariableSlice {
- tmp[pos+i*1] = uint8(m.VariableSlice[i].Proto)
- //copy(tmp[102+i:103+i], []byte{byte(m.VariableSlice[i].Proto)})
- }
- pos += len(m.VariableSlice) * 1
-
- tmp[pos] = uint8(m.TypeUnion.Af)
- pos += 1
-
- copy(tmp[pos:pos+16], m.TypeUnion.Un.XXX_UnionData[:])
- pos += 16
-
- return tmp, nil
-}
-
-func (m *TestAllMsg) Unmarshal(tmp []byte) error {
- order := binary.BigEndian
-
- //tmp := make([]byte, 143)
- pos := 0
-
- m.Bool = tmp[pos] != 0
- pos += 1
-
- //tmp[pos] = m.Uint8
- m.Uint8 = tmp[pos]
- pos += 1
-
- //order.PutUint16(tmp[pos:pos+2], m.Uint16)
- m.Uint16 = order.Uint16(tmp[pos : pos+2])
- pos += 2
-
- //order.PutUint32(tmp[pos:pos+4], m.Uint32)
- m.Uint32 = order.Uint32(tmp[pos : pos+4])
- pos += 4
-
- //tmp[pos] = byte(m.Int8)
- m.Int8 = int8(tmp[pos])
- pos += 1
-
- //order.PutUint16(tmp[pos:pos+2], uint16(m.Int16))
- m.Int16 = int16(order.Uint16(tmp[pos : pos+2]))
- pos += 2
-
- //order.PutUint32(tmp[pos:pos+4], uint32(m.Int32))
- m.Int32 = int32(order.Uint32(tmp[pos : pos+4]))
- pos += 4
-
- //order.PutUint32(tmp[pos:pos+4], uint32(m.AliasUint32))
- m.AliasUint32 = InterfaceIndex(order.Uint32(tmp[pos : pos+4]))
- pos += 4
-
- //copy(tmp[pos:pos+6], m.AliasArray[:])
- copy(m.AliasArray[:], tmp[pos:pos+6])
- pos += 6
-
- //order.PutUint32(tmp[pos:pos+4], uint32(m.Enum))
- m.Enum = IfStatusFlags(order.Uint32(tmp[pos : pos+4]))
- pos += 4
-
- m.BaseArray = make([]uint32, 4)
- for i := 0; i < 4; i++ {
- /*var x uint32
- if i < len(m.BaseArray) {
- x = m.BaseArray[i]
- }
- order.PutUint32(tmp[pos:pos+4], uint32(x))*/
- m.BaseArray[i] = order.Uint32(tmp[pos : pos+4])
- pos += 4
- }
-
- m.Slice = make([]byte, 7)
- copy(m.Slice[:7], tmp[pos:pos+7])
- //copy(tmp[pos:pos+7], m.Slice)
- pos += 7
-
- i := bytes.Index(tmp[pos:pos+64], []byte{0x00})
- m.String = string(tmp[pos : pos+i])
- //copy(tmp[pos:pos+64], m.String)
- pos += 64
-
- //order.PutUint32(tmp[pos:pos+4], uint32(len(m.VlaStr)) /*m.SizeOf*/)
- VlaStrLen := int(order.Uint32(tmp[pos : pos+4]))
- pos += 4
-
- m.VlaStr = string(tmp[pos : pos+VlaStrLen])
- //copy(m.VlaStr[pos:pos+VlaStrLen], tmp[pos:pos+64])
- pos += len(m.VlaStr)
-
- m.SizeOf = uint32(order.Uint32(tmp[pos : pos+4]))
- pos += 4
-
- /*order.PutUint32(tmp[pos:pos+4], uint32(len(m.VariableSlice)))
- m.VariableSlice = IfStatusFlags(order.Uint32(tmp[pos : pos+4]))
- pos += 4*/
-
- m.VariableSlice = make([]SliceType, m.SizeOf)
- for i := range m.VariableSlice {
- //tmp[pos+i*1] = uint8(m.VariableSlice[i].Proto)
- m.VariableSlice[i].Proto = IPProto(tmp[pos+i*1])
- //copy(tmp[102+i:103+i], []byte{byte(m.VariableSlice[i].Proto)})
- }
- pos += len(m.VariableSlice) * 1
-
- //tmp[pos] = uint8(m.TypeUnion.Af)
- m.TypeUnion.Af = AddressFamily(tmp[pos])
- pos += 1
-
- //copy(tmp[pos:pos+16], m.TypeUnion.Un.XXX_UnionData[:])
- copy(m.TypeUnion.Un.XXX_UnionData[:], tmp[pos:pos+16])
- pos += 16
-
- return nil
-}
-
-func boolToUint(b bool) uint8 {
- if b {
- return 1
- }
- return 0
-}
-
-// SwInterfaceDetails represents VPP binary API message 'sw_interface_details'.
-type TestAllMsg struct {
- Bool bool
- Uint8 uint8
- Uint16 uint16
- Uint32 uint32
- Int8 int8
- Int16 int16
- Int32 int32
- AliasUint32 InterfaceIndex
- AliasArray MacAddress
- Enum IfStatusFlags
- BaseArray []uint32 `struc:"[4]uint32"`
- Slice []byte `struc:"[7]byte"`
- String string `struc:"[64]byte"`
- XXX_VlaStrLen uint32 `struc:"sizeof=VlaStr"`
- VlaStr string
- SizeOf uint32 `struc:"sizeof=VariableSlice"`
- VariableSlice []SliceType
- TypeUnion Address
-}
-
-type InterfaceIndex uint32
-type MacAddress [6]uint8
-type IfStatusFlags uint32
-
-const (
- IF_STATUS_API_FLAG_ADMIN_UP IfStatusFlags = 1
- IF_STATUS_API_FLAG_LINK_UP IfStatusFlags = 2
-)
-
-// Address represents VPP binary API type 'address'.
-type Address struct {
- Af AddressFamily
- Un AddressUnion
-}
-
-// AddressFamily represents VPP binary API enum 'address_family'.
-type AddressFamily uint8
-
-const (
- ADDRESS_IP4 AddressFamily = 0
- ADDRESS_IP6 AddressFamily = 1
-)
-
-// AddressUnion represents VPP binary API union 'address_union'.
-type AddressUnion struct {
- XXX_UnionData [16]byte
-}
-
-func (*AddressUnion) GetTypeName() string { return "address_union" }
-
-func AddressUnionIP4(a IP4Address) (u AddressUnion) {
- u.SetIP4(a)
- return
-}
-func (u *AddressUnion) SetIP4(a IP4Address) {
- var b = new(bytes.Buffer)
- if err := struc.Pack(b, &a); err != nil {
- return
- }
- copy(u.XXX_UnionData[:], b.Bytes())
-}
-func (u *AddressUnion) GetIP4() (a IP4Address) {
- var b = bytes.NewReader(u.XXX_UnionData[:])
- struc.Unpack(b, &a)
- return
-}
-
-func AddressUnionIP6(a IP6Address) (u AddressUnion) {
- u.SetIP6(a)
- return
-}
-func (u *AddressUnion) SetIP6(a IP6Address) {
- var b = new(bytes.Buffer)
- if err := struc.Pack(b, &a); err != nil {
- return
- }
- copy(u.XXX_UnionData[:], b.Bytes())
-}
-func (u *AddressUnion) GetIP6() (a IP6Address) {
- var b = bytes.NewReader(u.XXX_UnionData[:])
- struc.Unpack(b, &a)
- return
-}
-
-// IP4Address represents VPP binary API alias 'ip4_address'.
-type IP4Address [4]uint8
-
-// IP6Address represents VPP binary API alias 'ip6_address'.
-type IP6Address [16]uint8
-
-type SliceType struct {
- Proto IPProto
-}
-
-type IPProto uint8
-
-const (
- IP_API_PROTO_HOPOPT IPProto = 0
- IP_API_PROTO_ICMP IPProto = 1
- IP_API_PROTO_IGMP IPProto = 2
- IP_API_PROTO_TCP IPProto = 6
- IP_API_PROTO_UDP IPProto = 17
- IP_API_PROTO_GRE IPProto = 47
- IP_API_PROTO_ESP IPProto = 50
- IP_API_PROTO_AH IPProto = 51
- IP_API_PROTO_ICMP6 IPProto = 58
- IP_API_PROTO_EIGRP IPProto = 88
- IP_API_PROTO_OSPF IPProto = 89
- IP_API_PROTO_SCTP IPProto = 132
- IP_API_PROTO_RESERVED IPProto = 255
-)
-
-func (m *TestAllMsg) Reset() { *m = TestAllMsg{} }
-func (*TestAllMsg) GetMessageName() string { return "sw_interface_details" }
-func (*TestAllMsg) GetCrcString() string { return "17b69fa2" }
-func (*TestAllMsg) GetMessageType() api.MessageType { return api.ReplyMessage }