本文整理匯總了Golang中github.com/google/gopacket.SerializeBuffer類的典型用法代碼示例。如果您正苦於以下問題:Golang SerializeBuffer類的具體用法?Golang SerializeBuffer怎麽用?Golang SerializeBuffer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SerializeBuffer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: serializeOtherGatewayVector
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
}
示例2: serialize3PPortConversationVector2
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
}
示例3: serializeOtherPortsInfo
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
}
示例4: serializeNeighborGatewayVector
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
}
示例5: SerializeTo
// SerializeTo writes the serialized form of this layer into the
// SerializationBuffer, implementing gopacket.SerializableLayer.
// See the docs for gopacket.SerializableLayer for more info.
func (i *IPv6Destination) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
var bytes []byte
var err error
o := make([]*ipv6HeaderTLVOption, 0, len(i.Options))
for _, v := range i.Options {
o = append(o, (*ipv6HeaderTLVOption)(v))
}
l := serializeIPv6HeaderTLVOptions(nil, o, opts.FixLengths)
bytes, err = b.PrependBytes(l)
if err != nil {
return err
}
serializeIPv6HeaderTLVOptions(bytes, o, opts.FixLengths)
length := len(bytes) + 2
if length%8 != 0 {
return fmt.Errorf("IPv6Destination actual length must be multiple of 8")
}
bytes, err = b.PrependBytes(2)
if err != nil {
return err
}
bytes[0] = uint8(i.NextHeader)
if opts.FixLengths {
i.HeaderLength = uint8((length / 8) - 1)
}
bytes[1] = uint8(i.HeaderLength)
return nil
}
示例6: SerializeTo
// 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 *VxlanEthernet) 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))
}
return nil
}
示例7: SerializeTo
// SerializeTo writes the serialized form of this layer into the
// SerializationBuffer, implementing gopacket.SerializableLayer.
// See the docs for gopacket.SerializableLayer for more info.
func (arp *ARP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
size := 8 + len(arp.SourceHwAddress) + len(arp.SourceProtAddress) + len(arp.DstHwAddress) + len(arp.DstProtAddress)
bytes, err := b.PrependBytes(size)
if err != nil {
return err
}
if opts.FixLengths {
if len(arp.SourceHwAddress) != len(arp.DstHwAddress) {
return fmt.Errorf("mismatched hardware address sizes")
}
arp.HwAddressSize = uint8(len(arp.SourceHwAddress))
if len(arp.SourceProtAddress) != len(arp.DstProtAddress) {
return fmt.Errorf("mismatched prot address sizes")
}
arp.ProtAddressSize = uint8(len(arp.SourceProtAddress))
}
binary.BigEndian.PutUint16(bytes, uint16(arp.AddrType))
binary.BigEndian.PutUint16(bytes[2:], uint16(arp.Protocol))
bytes[4] = arp.HwAddressSize
bytes[5] = arp.ProtAddressSize
binary.BigEndian.PutUint16(bytes[6:], arp.Operation)
start := 8
for _, addr := range [][]byte{
arp.SourceHwAddress,
arp.SourceProtAddress,
arp.DstHwAddress,
arp.DstProtAddress,
} {
copy(bytes[start:], addr)
start += len(addr)
}
return nil
}
示例8: SerializeTo
// SerializeTo writes the serialized form of this layer into the
// SerializationBuffer, implementing gopacket.SerializableLayer.
// See the docs for gopacket.SerializableLayer for more info.
func (i *IPv6Destination) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
optionLength := 0
for _, opt := range i.Options {
l, err := opt.serializeTo(b, opts.FixLengths)
if err != nil {
return err
}
optionLength += l
}
bytes, err := b.PrependBytes(2)
if err != nil {
return err
}
bytes[0] = uint8(i.NextHeader)
if opts.FixLengths {
if optionLength <= 0 {
return fmt.Errorf("cannot serialize empty IPv6Destination")
}
length := optionLength + 2
if length%8 != 0 {
return fmt.Errorf("IPv6Destination actual length must be multiple of 8 (check TLV alignment)")
}
i.HeaderLength = uint8((length / 8) - 1)
}
bytes[1] = i.HeaderLength
return nil
}
示例9: SerializeTo
// SerializeTo is for gopacket.SerializableLayer.
func (sc SCTPData) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
length := 16 + len(sc.PayloadData)
bytes, err := b.PrependBytes(roundUpToNearest4(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))
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], sc.PayloadProtocol)
copy(bytes[16:], sc.PayloadData)
return nil
}
示例10: serializePortalInfo
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
}
示例11: SerializeTo
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
}
示例12: SerializeTo
// SerializeTo writes the serialized form of this layer into the
// SerializationBuffer, implementing gopacket.SerializableLayer.
// See the docs for gopacket.SerializableLayer for more info.
func (s *SlowProtocol) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
bytes, err := b.PrependBytes(1)
if err != nil {
return err
}
bytes[0] = uint8(s.SubType)
return nil
}
示例13: SerializeTo
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
}
示例14: putSerializeBuffer
func putSerializeBuffer(buf gopacket.SerializeBuffer) {
if buf == nil {
return
}
buf.Clear()
serializeBufferPool.Put(buf)
}
示例15: SerializeTo
// SerializeTo writes the serialized form of this layer into the
// SerializationBuffer, implementing gopacket.SerializableLayer.
func (l *Loopback) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
bytes, err := b.PrependBytes(4)
if err != nil {
return err
}
binary.LittleEndian.PutUint32(bytes, uint32(l.Family))
return nil
}