-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
layers_decoder.go
101 lines (98 loc) · 2.76 KB
/
layers_decoder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2019 The GoPacket Authors. All rights reserved.
package gopacket
// Created by gen.go, don't edit manually
// Generated at 2019-06-18 11:37:31.308731293 +0600 +06 m=+0.000842599
// LayersDecoder returns DecodingLayerFunc for specified
// DecodingLayerContainer, LayerType value to start decoding with and
// some DecodeFeedback.
func LayersDecoder(dl DecodingLayerContainer, first LayerType, df DecodeFeedback) DecodingLayerFunc {
firstDec, ok := dl.Decoder(first)
if !ok {
return func([]byte, *[]LayerType) (LayerType, error) {
return first, nil
}
}
if dlc, ok := dl.(DecodingLayerSparse); ok {
return func(data []byte, decoded *[]LayerType) (LayerType, error) {
*decoded = (*decoded)[:0] // Truncated decoded layers.
typ := first
decoder := firstDec
for {
if err := decoder.DecodeFromBytes(data, df); err != nil {
return LayerTypeZero, err
}
*decoded = append(*decoded, typ)
typ = decoder.NextLayerType()
if data = decoder.LayerPayload(); len(data) == 0 {
break
}
if decoder, ok = dlc.Decoder(typ); !ok {
return typ, nil
}
}
return LayerTypeZero, nil
}
}
if dlc, ok := dl.(DecodingLayerArray); ok {
return func(data []byte, decoded *[]LayerType) (LayerType, error) {
*decoded = (*decoded)[:0] // Truncated decoded layers.
typ := first
decoder := firstDec
for {
if err := decoder.DecodeFromBytes(data, df); err != nil {
return LayerTypeZero, err
}
*decoded = append(*decoded, typ)
typ = decoder.NextLayerType()
if data = decoder.LayerPayload(); len(data) == 0 {
break
}
if decoder, ok = dlc.Decoder(typ); !ok {
return typ, nil
}
}
return LayerTypeZero, nil
}
}
if dlc, ok := dl.(DecodingLayerMap); ok {
return func(data []byte, decoded *[]LayerType) (LayerType, error) {
*decoded = (*decoded)[:0] // Truncated decoded layers.
typ := first
decoder := firstDec
for {
if err := decoder.DecodeFromBytes(data, df); err != nil {
return LayerTypeZero, err
}
*decoded = append(*decoded, typ)
typ = decoder.NextLayerType()
if data = decoder.LayerPayload(); len(data) == 0 {
break
}
if decoder, ok = dlc.Decoder(typ); !ok {
return typ, nil
}
}
return LayerTypeZero, nil
}
}
dlc := dl
return func(data []byte, decoded *[]LayerType) (LayerType, error) {
*decoded = (*decoded)[:0] // Truncated decoded layers.
typ := first
decoder := firstDec
for {
if err := decoder.DecodeFromBytes(data, df); err != nil {
return LayerTypeZero, err
}
*decoded = append(*decoded, typ)
typ = decoder.NextLayerType()
if data = decoder.LayerPayload(); len(data) == 0 {
break
}
if decoder, ok = dlc.Decoder(typ); !ok {
return typ, nil
}
}
return LayerTypeZero, nil
}
}