Example #1
0
func (d *DRCP) serializeOtherGatewayVector(b gopacket.SerializeBuffer) error {

	// ignore assumed that there are less than 3 portals
	if d.OtherGatewayVector.TlvTypeLength.GetTlv() == 0 {
		return nil
	}

	if d.OtherGatewayVector.TlvTypeLength.GetTlv() != DRCPTLVTypeOtherGatewayVector {
		return fmt.Errorf("Error in Serialize to for DRCP Other Gateway Vector TLV incorrect %d", d.OtherGatewayVector.TlvTypeLength.GetTlv())
	}

	if (DRCPTlvTypeLength(d.OtherGatewayVector.TlvTypeLength.GetLength()) == DRCPTLVOtherGatewayVectorLength_1 &&
		len(d.OtherGatewayVector.Vector) != 0) ||
		(DRCPTlvTypeLength(d.OtherGatewayVector.TlvTypeLength.GetLength()) == DRCPTLVOtherGatewayVectorLength_2 &&
			len(d.OtherGatewayVector.Vector) != 512) {
		return fmt.Errorf("Error in Serialize to for DRCP Other Gateway Vector Length incorrect %d", d.OtherGatewayVector.TlvTypeLength.GetLength())
	}

	bytes, err := b.AppendBytes(int(d.OtherGatewayVector.TlvTypeLength.GetLength()) + 2)
	if err != nil {
		fmt.Println("Error in Serialize Other Gateway Vector for DRCP")
		return err
	}

	binary.BigEndian.PutUint16(bytes[0:], uint16(d.OtherGatewayVector.TlvTypeLength))
	binary.BigEndian.PutUint32(bytes[2:], d.OtherGatewayVector.Sequence)
	for i, j := uint16(6), uint16(0); j < d.OtherGatewayVector.TlvTypeLength.GetLength()-4; i, j = i+1, j+1 {
		bytes[i] = byte(d.OtherGatewayVector.Vector[j])
	}
	return nil
}
Example #2
0
func (d *DRCP) serialize3PPortConversationVector2(b gopacket.SerializeBuffer) error {

	// optional
	if d.ThreePortalPortConversationVector2.TlvTypeLength.GetTlv() == DRCPTlvTypeLength(0) {
		return nil
	}

	if d.ThreePortalPortConversationVector2.TlvTypeLength.GetTlv() != DRCPTLV3PPortConversationVector2 {
		return fmt.Errorf("Error in Serialize to for DRCP 3P Port Conversation Vector 2 TLV incorrect %d", d.ThreePortalPortConversationVector2.TlvTypeLength.GetTlv())
	}

	if DRCPTlvTypeLength(d.ThreePortalPortConversationVector2.TlvTypeLength.GetLength()) != DRCPTLV3PPortConversationVector2Length {
		return fmt.Errorf("Error in Serialize to for DRCP 3P Port Conversation Vector 2 Length incorrect %d", d.ThreePortalPortConversationVector2.TlvTypeLength.GetLength())
	}

	bytes, err := b.AppendBytes(int(d.ThreePortalPortConversationVector2.TlvTypeLength.GetLength()) + 2)
	if err != nil {
		fmt.Println("Error in Serialize 3P Port Conversation Vector 2 for DRCP")
		return err
	}

	binary.BigEndian.PutUint16(bytes[0:], uint16(d.ThreePortalPortConversationVector2.TlvTypeLength))
	for i, j := uint16(2), uint16(0); j < d.ThreePortalPortConversationVector2.TlvTypeLength.GetLength(); i, j = i+1, j+1 {
		bytes[i] = byte(d.ThreePortalPortConversationVector2.Vector[j])
	}

	return nil
}
Example #3
0
func (d *DRCP) serializePortalInfo(b gopacket.SerializeBuffer) error {

	if d.PortalInfo.TlvTypeLength.GetTlv() != DRCPTLVTypePortalInfo {
		return fmt.Errorf("Error in Serialize to for DRCP PortalInfo TLV incorrect %d", d.PortalInfo.TlvTypeLength.GetTlv())
	}

	bytes, err := b.AppendBytes(int(DRCPTLVPortalInfoLength) + 2)
	if err != nil {
		fmt.Println("Error in Serialize to PortalInfo for DRCP")
		return err
	}
	binary.BigEndian.PutUint16(bytes[0:], uint16(d.PortalInfo.TlvTypeLength))
	binary.BigEndian.PutUint16(bytes[2:], d.PortalInfo.AggPriority)
	bytes[4] = byte(d.PortalInfo.AggId[0])
	bytes[5] = byte(d.PortalInfo.AggId[1])
	bytes[6] = byte(d.PortalInfo.AggId[2])
	bytes[7] = byte(d.PortalInfo.AggId[3])
	bytes[8] = byte(d.PortalInfo.AggId[4])
	bytes[9] = byte(d.PortalInfo.AggId[5])
	binary.BigEndian.PutUint16(bytes[10:], d.PortalInfo.PortalPriority)
	bytes[12] = byte(d.PortalInfo.PortalAddr[0])
	bytes[13] = byte(d.PortalInfo.PortalAddr[1])
	bytes[14] = byte(d.PortalInfo.PortalAddr[2])
	bytes[15] = byte(d.PortalInfo.PortalAddr[3])
	bytes[16] = byte(d.PortalInfo.PortalAddr[4])
	bytes[17] = byte(d.PortalInfo.PortalAddr[5])
	return nil
}
Example #4
0
// SerializeTo is for gopacket.SerializableLayer.
func (sc SCTPData) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
	payload := b.Bytes()
	// Pad the payload to a 32 bit boundary
	if rem := len(payload) % 4; rem != 0 {
		b.AppendBytes(4 - rem)
	}
	length := 16
	bytes, err := b.PrependBytes(length)
	if err != nil {
		return err
	}
	bytes[0] = uint8(sc.Type)
	flags := uint8(0)
	if sc.Unordered {
		flags |= 0x4
	}
	if sc.BeginFragment {
		flags |= 0x2
	}
	if sc.EndFragment {
		flags |= 0x1
	}
	bytes[1] = flags
	binary.BigEndian.PutUint16(bytes[2:4], uint16(length+len(payload)))
	binary.BigEndian.PutUint32(bytes[4:8], sc.TSN)
	binary.BigEndian.PutUint16(bytes[8:10], sc.StreamId)
	binary.BigEndian.PutUint16(bytes[10:12], sc.StreamSequence)
	binary.BigEndian.PutUint32(bytes[12:16], uint32(sc.PayloadProtocol))
	return nil
}
Example #5
0
func (d *DRCP) serializeNeighborGatewayVector(b gopacket.SerializeBuffer) error {

	// optional
	if d.NeighborGatewayVector.TlvTypeLength.GetTlv() == 0 {
		return nil
	}

	if d.NeighborGatewayVector.TlvTypeLength.GetTlv() != DRCPTLVTypeNeighborGatewayVector {
		return fmt.Errorf("Error in Serialize to for DRCP Neighbor Gateway Vector TLV incorrect %d", d.NeighborGatewayVector.TlvTypeLength.GetTlv())
	}

	if DRCPTlvTypeLength(d.NeighborGatewayVector.TlvTypeLength.GetLength()) != DRCPTLVNeighborGatewayVectorLength {
		return fmt.Errorf("Error in Serialize to for DRCP Neighbor Gateway Vector TLV Length incorrect %d", d.NeighborGatewayVector.TlvTypeLength.GetLength())
	}

	bytes, err := b.AppendBytes(int(d.NeighborGatewayVector.TlvTypeLength.GetLength()) + 2)
	if err != nil {
		fmt.Println("Error in Serialize Neighbor Gateway Vector for DRCP")
		return err
	}

	binary.BigEndian.PutUint16(bytes[0:], uint16(d.NeighborGatewayVector.TlvTypeLength))
	binary.BigEndian.PutUint32(bytes[2:], d.NeighborGatewayVector.Sequence)

	return nil
}
Example #6
0
func (d *DRCP) serializeOtherPortsInfo(b gopacket.SerializeBuffer) error {

	// ignore assumed that there are less than 3 portals
	if d.OtherPortsInfo.TlvTypeLength.GetTlv() == 0 {
		return nil
	}

	if d.OtherPortsInfo.TlvTypeLength.GetTlv() != DRCPTLVTypeOtherPortsInfo {
		return fmt.Errorf("Error in Serialize to for DRCP Other Ports Info TLV incorrect %d", d.OtherPortsInfo.TlvTypeLength.GetTlv())
	}

	if math.Mod(float64(d.OtherPortsInfo.TlvTypeLength.GetLength()), 4) != 0 {
		return fmt.Errorf("Error in Serialize to for DRCP Other Ports Info Length incorrect %d", d.OtherPortsInfo.TlvTypeLength.GetLength())
	}

	bytes, err := b.AppendBytes(int(d.OtherPortsInfo.TlvTypeLength.GetLength()) + 2)
	if err != nil {
		fmt.Println("Error in Serialize Other Ports Info for DRCP")
		return err
	}

	binary.BigEndian.PutUint16(bytes[0:], uint16(d.OtherPortsInfo.TlvTypeLength))
	binary.BigEndian.PutUint16(bytes[2:], d.OtherPortsInfo.AdminAggKey)
	binary.BigEndian.PutUint16(bytes[4:], d.OtherPortsInfo.OperPartnerAggKey)
	for i, j := uint16(6), uint16(0); j < (d.OtherPortsInfo.TlvTypeLength.GetLength()-4)/4; i, j = i+4, j+1 {
		binary.BigEndian.PutUint32(bytes[i:], d.OtherPortsInfo.NeighborPorts[j])
	}

	return nil
}
Example #7
0
File: itto.go Project: ikravets/ev
func (m *IttoMessageBaseReference) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	errs.CheckE(m.IttoMessageCommon.SerializeTo(b, opts))
	buf, err := b.AppendBytes(8)
	errs.CheckE(err)
	binary.BigEndian.PutUint64(buf, m.BaseRefNum)
	return
}
Example #8
0
File: itto.go Project: ikravets/ev
func (m *IttoMessageSeconds) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	errs.CheckE(m.IttoMessageCommon.SerializeTo(b, opts))
	buf, err := b.AppendBytes(4)
	errs.CheckE(err)
	binary.BigEndian.PutUint32(buf, m.Second)
	return
}
Example #9
0
File: tom.go Project: ikravets/ev
func (m *TomMessageSystemTime) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	errs.CheckE(m.TomMessageCommon.SerializeTo(b, opts))
	buf, err := b.AppendBytes(4)
	errs.CheckE(err)
	binary.LittleEndian.PutUint32(buf, m.Second)
	return
}
Example #10
0
func (d *DRCP) serializeNetworkIPLSharingEncapsulation(b gopacket.SerializeBuffer) error {

	// optional
	if d.NetworkIPLEncapsulation.TlvTypeLength.GetTlv() == DRCPTlvTypeLength(0) {
		return nil
	}

	if d.NetworkIPLEncapsulation.TlvTypeLength.GetTlv() != DRCPTLVNetworkIPLSharingEncapsulation {
		return fmt.Errorf("Error in Serialize to for DRCP Network/IPL Sharing Encapsulation TLV incorrect %d", d.NetworkIPLEncapsulation.TlvTypeLength.GetTlv())
	}

	if DRCPTlvTypeLength(d.NetworkIPLEncapsulation.TlvTypeLength.GetLength()) != DRCPTLVNetworkIPLSharingEncapsulationLength {
		return fmt.Errorf("Error in Serialize to for DRCP Network/IPL Sharing Encapsulation Length incorrect %d", d.NetworkIPLEncapsulation.TlvTypeLength.GetLength())
	}

	bytes, err := b.AppendBytes(int(d.NetworkIPLEncapsulation.TlvTypeLength.GetLength()) + 2)
	if err != nil {
		fmt.Println("Error in Serialize Network/IPL Sharing Method for DRCP")
		return err
	}

	binary.BigEndian.PutUint16(bytes[0:], uint16(d.NetworkIPLEncapsulation.TlvTypeLength))
	bytes[2] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[0])
	bytes[3] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[1])
	bytes[4] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[2])
	bytes[5] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[3])
	bytes[6] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[4])
	bytes[7] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[5])
	bytes[8] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[6])
	bytes[9] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[7])
	bytes[10] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[8])
	bytes[11] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[9])
	bytes[12] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[10])
	bytes[13] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[11])
	bytes[14] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[12])
	bytes[15] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[13])
	bytes[16] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[14])
	bytes[17] = byte(d.NetworkIPLEncapsulation.IplEncapDigest[15])
	bytes[18] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[0])
	bytes[19] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[1])
	bytes[20] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[2])
	bytes[21] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[3])
	bytes[22] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[4])
	bytes[23] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[5])
	bytes[24] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[6])
	bytes[25] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[7])
	bytes[26] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[8])
	bytes[27] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[9])
	bytes[28] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[10])
	bytes[29] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[11])
	bytes[30] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[12])
	bytes[31] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[13])
	bytes[32] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[14])
	bytes[33] = byte(d.NetworkIPLEncapsulation.NetEncapDigest[15])

	return nil
}
Example #11
0
func (d *DRCP) serializePortalConfigInfo(b gopacket.SerializeBuffer) error {

	if d.PortalConfigInfo.TlvTypeLength.GetTlv() != DRCPTLVTypePortalConfigInfo {
		return fmt.Errorf("Error in Serialize to for DRCP PortalConfigInfo TLV incorrect %d", d.PortalConfigInfo.TlvTypeLength.GetTlv())
	}
	bytes, err := b.AppendBytes(int(DRCPTLVPortalConfigurationInfoLength) + 2)
	if err != nil {
		fmt.Println("Error in Serialize PortalConfigInfo for DRCP")
		return err
	}

	binary.BigEndian.PutUint16(bytes[0:], uint16(d.PortalConfigInfo.TlvTypeLength))
	bytes[2] = byte(d.PortalConfigInfo.TopologyState)
	binary.BigEndian.PutUint16(bytes[3:], d.PortalConfigInfo.OperAggKey)
	bytes[5] = byte(d.PortalConfigInfo.PortAlgorithm[0])
	bytes[6] = byte(d.PortalConfigInfo.PortAlgorithm[1])
	bytes[7] = byte(d.PortalConfigInfo.PortAlgorithm[2])
	bytes[8] = byte(d.PortalConfigInfo.PortAlgorithm[3])
	bytes[9] = byte(d.PortalConfigInfo.GatewayAlgorithm[0])
	bytes[10] = byte(d.PortalConfigInfo.GatewayAlgorithm[1])
	bytes[11] = byte(d.PortalConfigInfo.GatewayAlgorithm[2])
	bytes[12] = byte(d.PortalConfigInfo.GatewayAlgorithm[3])
	bytes[13] = byte(d.PortalConfigInfo.PortDigest[0])
	bytes[14] = byte(d.PortalConfigInfo.PortDigest[1])
	bytes[15] = byte(d.PortalConfigInfo.PortDigest[2])
	bytes[16] = byte(d.PortalConfigInfo.PortDigest[3])
	bytes[17] = byte(d.PortalConfigInfo.PortDigest[4])
	bytes[18] = byte(d.PortalConfigInfo.PortDigest[5])
	bytes[19] = byte(d.PortalConfigInfo.PortDigest[6])
	bytes[20] = byte(d.PortalConfigInfo.PortDigest[7])
	bytes[21] = byte(d.PortalConfigInfo.PortDigest[8])
	bytes[22] = byte(d.PortalConfigInfo.PortDigest[9])
	bytes[23] = byte(d.PortalConfigInfo.PortDigest[10])
	bytes[24] = byte(d.PortalConfigInfo.PortDigest[11])
	bytes[25] = byte(d.PortalConfigInfo.PortDigest[12])
	bytes[26] = byte(d.PortalConfigInfo.PortDigest[13])
	bytes[27] = byte(d.PortalConfigInfo.PortDigest[14])
	bytes[28] = byte(d.PortalConfigInfo.PortDigest[15])
	bytes[29] = byte(d.PortalConfigInfo.GatewayDigest[0])
	bytes[30] = byte(d.PortalConfigInfo.GatewayDigest[1])
	bytes[31] = byte(d.PortalConfigInfo.GatewayDigest[2])
	bytes[32] = byte(d.PortalConfigInfo.GatewayDigest[3])
	bytes[33] = byte(d.PortalConfigInfo.GatewayDigest[4])
	bytes[34] = byte(d.PortalConfigInfo.GatewayDigest[5])
	bytes[35] = byte(d.PortalConfigInfo.GatewayDigest[6])
	bytes[36] = byte(d.PortalConfigInfo.GatewayDigest[7])
	bytes[37] = byte(d.PortalConfigInfo.GatewayDigest[8])
	bytes[38] = byte(d.PortalConfigInfo.GatewayDigest[9])
	bytes[39] = byte(d.PortalConfigInfo.GatewayDigest[10])
	bytes[40] = byte(d.PortalConfigInfo.GatewayDigest[11])
	bytes[41] = byte(d.PortalConfigInfo.GatewayDigest[12])
	bytes[42] = byte(d.PortalConfigInfo.GatewayDigest[13])
	bytes[43] = byte(d.PortalConfigInfo.GatewayDigest[14])
	bytes[44] = byte(d.PortalConfigInfo.GatewayDigest[15])

	return nil
}
Example #12
0
func (self Dot11NoFCS) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
	dot11 := append([]byte{}, b.Bytes()...)
	if err := b.Clear(); err != nil {
		return err
	}
	bytes, err := b.AppendBytes(len(dot11) - 4) // remove FCS
	if err != nil {
		return err
	}
	copy(bytes, dot11)
	return nil
}
Example #13
0
File: tom.go Project: ikravets/ev
func (m *TomMessageCommon) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	buf, err := b.AppendBytes(1)
	errs.CheckE(err)
	buf[0] = byte(m.Type)

	if m.Type != TomMessageTypeSystemTime {
		buf, err := b.AppendBytes(4)
		errs.CheckE(err)
		binary.LittleEndian.PutUint32(buf, m.Timestamp)
	}
	return
}
Example #14
0
File: pitch.go Project: ikravets/ev
func (m *PitchMessageCommon) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	buf, err := b.AppendBytes(2)
	errs.CheckE(err)
	buf[0] = m.Length
	buf[1] = byte(m.Type)

	if m.Type != PitchMessageTypeTime {
		buf, err := b.AppendBytes(4)
		errs.CheckE(err)
		binary.LittleEndian.PutUint32(buf, m.TimeOffset)
	}
	return
}
Example #15
0
func (d *DRCP) serializeDRCPState(b gopacket.SerializeBuffer) error {

	if d.State.TlvTypeLength.GetTlv() != DRCPTLVTypeDRCPState {
		return fmt.Errorf("Error in Serialize to for DRCP State TLV incorrect %d", d.State.TlvTypeLength.GetTlv())
	}
	bytes, err := b.AppendBytes(int(DRCPTLVStateLength) + 2)
	if err != nil {
		fmt.Println("Error in Serialize State for DRCP")
		return err
	}
	binary.BigEndian.PutUint16(bytes[0:], uint16(d.State.TlvTypeLength))
	bytes[2] = byte(d.State.State)

	return nil
}
Example #16
0
func (d *DRCP) serializeTerminator(b gopacket.SerializeBuffer) error {

	if d.Terminator.TlvTypeLength.GetTlv() != DRCPTLVTypeTerminator {
		return fmt.Errorf("Error in Serialize to for DRCP Terminator TLV incorrect %d", d.Terminator.TlvTypeLength.GetTlv())
	}

	bytes, err := b.AppendBytes(int(d.Terminator.TlvTypeLength.GetLength()) + 2)
	if err != nil {
		fmt.Println("Error in Serialize PortalConfigInfo for DRCP")
		return err
	}

	binary.BigEndian.PutUint16(bytes[0:], uint16(d.NetworkIPLEncapsulation.TlvTypeLength))

	return nil
}
Example #17
0
// SerializeTo writes the serialized form of this layer into the
// SerializationBuffer, implementing gopacket.SerializableLayer.
// See the docs for gopacket.SerializableLayer for more info.
func (eth *Ethernet) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
	if len(eth.DstMAC) != 6 {
		return fmt.Errorf("invalid dst MAC: %v", eth.DstMAC)
	}
	if len(eth.SrcMAC) != 6 {
		return fmt.Errorf("invalid src MAC: %v", eth.SrcMAC)
	}
	payload := b.Bytes()
	bytes, err := b.PrependBytes(14)
	if err != nil {
		return err
	}
	copy(bytes, eth.DstMAC)
	copy(bytes[6:], eth.SrcMAC)
	if eth.Length != 0 || eth.EthernetType == EthernetTypeLLC {
		if opts.FixLengths {
			eth.Length = uint16(len(payload))
		}
		if eth.EthernetType != EthernetTypeLLC {
			return fmt.Errorf("ethernet type %v not compatible with length value %v", eth.EthernetType, eth.Length)
		} else if eth.Length > 0x0600 {
			return fmt.Errorf("invalid ethernet length %v", eth.Length)
		}
		binary.BigEndian.PutUint16(bytes[12:], eth.Length)
	} else {
		binary.BigEndian.PutUint16(bytes[12:], uint16(eth.EthernetType))
	}
	length := len(b.Bytes())
	if length < 60 {
		// Pad out to 60 bytes.
		padding, err := b.AppendBytes(60 - length)
		if err != nil {
			return err
		}
		copy(padding, lotsOfZeros[:])
	}
	return nil
}
Example #18
0
func (d *DRCP) serializeNetworkIPLSharingMethod(b gopacket.SerializeBuffer) error {

	if d.NetworkIPLMethod.TlvTypeLength.GetTlv() != DRCPTLVNetworkIPLSharingMethod {
		return fmt.Errorf("Error in Serialize to for DRCP Network/IPL Sharing Method TLV incorrect %d", d.NetworkIPLMethod.TlvTypeLength.GetTlv())
	}

	if DRCPTlvTypeLength(d.NetworkIPLMethod.TlvTypeLength.GetLength()) != DRCPTLVNetworkIPLSharingMethodLength {
		return fmt.Errorf("Error in Serialize to for DRCP Network/IPL Sharing Method Length incorrect %d", d.NetworkIPLMethod.TlvTypeLength.GetLength())
	}

	bytes, err := b.AppendBytes(int(d.NetworkIPLMethod.TlvTypeLength.GetLength()) + 2)
	if err != nil {
		fmt.Println("Error in Serialize Network/IPL Sharing Method for DRCP")
		return err
	}

	binary.BigEndian.PutUint16(bytes[0:], uint16(d.NetworkIPLMethod.TlvTypeLength))
	bytes[2] = byte(d.NetworkIPLMethod.Method[0])
	bytes[3] = byte(d.NetworkIPLMethod.Method[1])
	bytes[4] = byte(d.NetworkIPLMethod.Method[2])
	bytes[5] = byte(d.NetworkIPLMethod.Method[3])

	return nil
}
Example #19
0
File: itto.go Project: ikravets/ev
func (m *IttoMessageAddOrder) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) (err error) {
	defer errs.PassE(&err)
	errs.CheckE(m.IttoMessageCommon.SerializeTo(b, opts))
	buf, err := b.AppendBytes(9)
	errs.CheckE(err)
	binary.BigEndian.PutUint32(buf, m.RefNumD.ToUint32())
	buf[4], err = m.Side.ToByte()
	errs.CheckE(err)
	binary.BigEndian.PutUint32(buf[5:9], m.OId.ToUint32())
	if m.Type.IsShort() {
		buf, err := b.AppendBytes(4)
		errs.CheckE(err)
		binary.BigEndian.PutUint16(buf, uint16(packet.PriceTo2Dec(m.Price)))
		binary.BigEndian.PutUint16(buf[2:], uint16(m.Size))
	} else {
		buf, err := b.AppendBytes(8)
		errs.CheckE(err)
		binary.BigEndian.PutUint32(buf, uint32(packet.PriceTo4Dec(m.Price)))
		binary.BigEndian.PutUint32(buf[4:], uint32(m.Size))
	}
	return
}