-
Notifications
You must be signed in to change notification settings - Fork 0
/
element.go
49 lines (42 loc) · 1.34 KB
/
element.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
package gobulk
// Element represents a structured data element which is a parsing result from container raw data
// one container can have many elements. E.g. container: log file, element: log message
type Element interface {
// RawData returns the []byte data that should be parsed
RawData() []byte
// ParsedData returns the parsed data
ParsedData() []interface{}
// SetParsedData sets parsed data
SetParsedData(parsedData interface{})
// Location returns the location of an element
Location() string
}
// NewInputElement is used by parser to create a new base element
func NewInputElement(location string, rawData []byte) *InputElement {
return &InputElement{
location: location,
rawData: rawData,
}
}
// InputElement must be used as basis for all elements
type InputElement struct {
location string
rawData []byte
parsedData []interface{}
}
// RawData returns the []byte data that should be parsed
func (b *InputElement) RawData() []byte {
return b.rawData
}
// ParsedData returns the parsed data
func (b *InputElement) ParsedData() []interface{} {
return b.parsedData
}
// SetParsedData sets parsed data
func (b *InputElement) SetParsedData(parsedData interface{}) {
b.parsedData = append(b.parsedData, parsedData)
}
// Location returns the location of an element
func (b *InputElement) Location() string {
return b.location
}