forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 9
/
util.go
39 lines (31 loc) · 866 Bytes
/
util.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
package decoder
import "github.com/tsg/gopacket"
// implement DecodingLayer with support of switching between multiple layers to
// remember outter layer results
type multiLayer struct {
layers []gopacket.DecodingLayer // all layers must have same type
i int
cnt int
}
func (m *multiLayer) next() {
m.i++
m.cnt++
if m.i >= len(m.layers) {
m.i = 0
}
}
func (m *multiLayer) init(layer ...gopacket.DecodingLayer) {
m.layers = layer
}
func (m *multiLayer) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
return m.layers[m.i].DecodeFromBytes(data, df)
}
func (m *multiLayer) CanDecode() gopacket.LayerClass {
return m.layers[m.i].CanDecode()
}
func (m *multiLayer) NextLayerType() gopacket.LayerType {
return m.layers[m.i].NextLayerType()
}
func (m *multiLayer) LayerPayload() []byte {
return m.layers[m.i].LayerPayload()
}