scroot / gopacket

Automatically exported from code.google.com/p/gopacket
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Code example in documentation incorrect #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
http://godoc.org/code.google.com/p/gopacket#hdr-Creating_Packet_Data

2nd code example includes:
gopacket.SerializeLayers(buf, opts,
  &layers.Ethernet{},
  &layers.IPv4{},
  &layers.TCP{},
  gopacket.Payload([]byte{1, 2, 3, 4}))

But Payload does not implement SerializableLayer. Only *Payload does, (and you 
can't add an inline &), so I get the error:

./myfile.go:266: cannot use payload (type gopacket.Payload) as type 
gopacket.SerializableLayer in argument to gopacket.SerializeLayers:
        gopacket.Payload does not implement gopacket.SerializableLayer (SerializeTo method has pointer receiver)

So I think you need to extract that out to

payload := gopacket.Payload([]byte{1, 2, 3, 4})
gopacket.SerializeLayers(buf, opts,
  &layers.Ethernet{},
  &layers.IPv4{},
  &layers.TCP{},
  &payload)

Original issue reported on code.google.com by matthew....@gmail.com on 11 Jul 2014 at 4:04

GoogleCodeExporter commented 9 years ago
New plan:  let's fix the code, not the docs!

Not many of Payload's functions need to have pointer receivers, so we'll make 
the ones that don't need it not use it.

https://code.google.com/p/gopacket/source/detail?r=0d96cd656af1be84afb0097dfdc3d
38c0d559b33

Original comment by gconnell@google.com on 11 Jul 2014 at 4:17