MCPcopy Index your code
hub / github.com/google/gopacket / DecodeFromBytes

Method DecodeFromBytes

layers/loopback.go:29–50  ·  view source on GitHub ↗

DecodeFromBytes decodes the given bytes into this layer.

(data []byte, df gopacket.DecodeFeedback)

Source from the content-addressed store, hash-verified

27
28// DecodeFromBytes decodes the given bytes into this layer.
29func (l *Loopback) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
30 if len(data) < 4 {
31 return errors.New("Loopback packet too small")
32 }
33
34 // The protocol could be either big-endian or little-endian, we're
35 // not sure. But we're PRETTY sure that the value is less than
36 // 256, so we can check the first two bytes.
37 var prot uint32
38 if data[0] == 0 && data[1] == 0 {
39 prot = binary.BigEndian.Uint32(data[:4])
40 } else {
41 prot = binary.LittleEndian.Uint32(data[:4])
42 }
43 if prot > 0xFF {
44 return fmt.Errorf("Invalid loopback protocol %q", data[:4])
45 }
46
47 l.Family = ProtocolFamily(prot)
48 l.BaseLayer = BaseLayer{data[:4], data[4:]}
49 return nil
50}
51
52// CanDecode returns the set of layer types that this DecodingLayer can decode.
53func (l *Loopback) CanDecode() gopacket.LayerClass {

Callers 1

decodeLoopbackFunction · 0.95

Calls 2

ProtocolFamilyTypeAlias · 0.85
NewMethod · 0.65

Tested by

no test coverage detected