SerializeLayers clears the given write buffer, then writes all layers into it so they correctly wrap each other. Note that by clearing the buffer, it invalidates all slices previously returned by w.Bytes() Example: buf := gopacket.NewSerializeBuffer() opts := gopacket.SerializeOptions{} gopacket.S
(w SerializeBuffer, opts SerializeOptions, layers ...SerializableLayer)
| 204 | // gopacket.SerializeLayers(buf, opts, d, e, f) |
| 205 | // secondPayload := buf.Bytes() // contains byte representation of d(e(f)). firstPayload is now invalidated, since the SerializeLayers call Clears buf. |
| 206 | func SerializeLayers(w SerializeBuffer, opts SerializeOptions, layers ...SerializableLayer) error { |
| 207 | w.Clear() |
| 208 | for i := len(layers) - 1; i >= 0; i-- { |
| 209 | layer := layers[i] |
| 210 | err := layer.SerializeTo(w, opts) |
| 211 | if err != nil { |
| 212 | return err |
| 213 | } |
| 214 | w.PushLayer(layer.LayerType()) |
| 215 | } |
| 216 | return nil |
| 217 | } |
| 218 | |
| 219 | // SerializePacket is a convenience function that calls SerializeLayers |
| 220 | // on packet's Layers(). |
searching dependent graphs…