MCPcopy
hub / github.com/google/gopacket / checkSerialization

Function checkSerialization

layers/base_test.go:45–63  ·  view source on GitHub ↗

Checks that when a serialized version of p is decoded, p and the serialized version of p are the same. Does not work for packets where the order of options can change, like icmpv6 router advertisements, dhcpv6, etc.

(p gopacket.Packet, t *testing.T)

Source from the content-addressed store, hash-verified

43// Checks that when a serialized version of p is decoded, p and the serialized version of p are the same.
44// Does not work for packets where the order of options can change, like icmpv6 router advertisements, dhcpv6, etc.
45func checkSerialization(p gopacket.Packet, t *testing.T) {
46 buf := gopacket.NewSerializeBuffer()
47 opts := gopacket.SerializeOptions{
48 ComputeChecksums: false,
49 FixLengths: false,
50 }
51 if err := gopacket.SerializePacket(buf, opts, p); err != nil {
52 t.Error("Failed to encode packet:", err)
53 }
54
55 p2 := gopacket.NewPacket(buf.Bytes(), LinkTypeEthernet, gopacket.Default)
56 if p2.ErrorLayer() != nil {
57 t.Error("Failed to decode the re-encoded packet:", p2.ErrorLayer().Error())
58 }
59
60 if p2.Dump() != p.Dump() {
61 t.Errorf("The decoded and the re-encoded packet are different!\nDecoded:\n%s\n Re-Encoded:\n%s", p.Dump(), p2.Dump())
62 }
63}

Callers 1

TestPacketICMPv6Function · 0.85

Calls 7

BytesMethod · 0.95
ErrorLayerMethod · 0.95
DumpMethod · 0.95
NewSerializeBufferFunction · 0.92
SerializePacketFunction · 0.92
NewPacketFunction · 0.92
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…