-
Notifications
You must be signed in to change notification settings - Fork 0
/
opcode.go
56 lines (49 loc) · 1.52 KB
/
opcode.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
package splunker
//go:generate stringer -type=Opcode
type Opcode byte
const (
OpcodeNop Opcode = 0
OpcodeOldstyleEvent Opcode = 1
OpcodeOldstyleEventWithHash Opcode = 2
OpcodeNewHost Opcode = 3
OpcodeNewSource Opcode = 4
OpcodeNewSourceType Opcode = 5
OpcodeNewString Opcode = 6
OpcodeDelete Opcode = 8
OpcodeSplunkPrivate Opcode = 9
OpcodeHeader Opcode = 10
OpcodeHashSlice Opcode = 11
)
func fetchDecoder(o Opcode) Decoder {
switch o {
case OpcodeHeader:
return decoderFunc((*JournalDecoder).headerDecoder)
case OpcodeSplunkPrivate:
return decoderFunc((*JournalDecoder).splunkPrivateDecoder)
case OpcodeNewHost:
return decoderFunc((*JournalDecoder).hostDecoder)
case OpcodeNewSource:
return decoderFunc((*JournalDecoder).sourceDecoder)
case OpcodeNewSourceType:
return decoderFunc((*JournalDecoder).sourceTypeDecoder)
case OpcodeNewString:
return decoderFunc((*JournalDecoder).stringDecoder)
case OpcodeOldstyleEvent:
return decoderFunc((*JournalDecoder).eventDecoder)
case OpcodeOldstyleEventWithHash:
return decoderFunc((*JournalDecoder).eventDecoder)
case OpcodeNop:
return decoderFunc(nil)
}
return nil
}
type Decoder interface {
Decode(*JournalDecoder, *CountedReader, byte) error
}
type decoderFunc func(*JournalDecoder, *CountedReader, byte) error
func (d decoderFunc) Decode(j *JournalDecoder, r *CountedReader, o byte) error {
if d == nil {
return nil
}
return d(j, r, o)
}