// Create a new SerializeBuffer with a capacity of 512 bytes buf := gopacket.NewSerializeBuffer(512) // Write some data to the buffer data := []byte{0x12, 0x34, 0x56} buf.WriteBytes(data) // Get the bytes from the buffer and reset it bytes := buf.Bytes()
// Create a new SerializeBuffer with a capacity of 1024 bytes buf := gopacket.NewSerializeBuffer(1024) // Serialize some Ethernet data to the buffer eth := &layers.Ethernet{ SrcMAC: net.HardwareAddr{0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}, DstMAC: net.HardwareAddr{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}, EthernetType: layers.EthernetTypeIPv4, } if err := gopacket.SerializeLayers(buf, gopacket.SerializeOptions{}, eth); err != nil { log.Fatal(err) } // Get the bytes from the buffer and reset it bytes := buf.Bytes()In this example, we create a new SerializeBuffer with a capacity of 1024 bytes, serialize some Ethernet data to the buffer using gopacket.SerializeLayers, and then get the bytes from the buffer by calling the Bytes method.