forked from calmh/ipfix
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexamples_test.go
60 lines (48 loc) · 1.11 KB
/
examples_test.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
package ipfix_test
import (
"fmt"
"os"
"github.com/gravwell/ipfix"
)
func ExampleSession() {
s := ipfix.NewSession()
for {
// ParseReader will block until a full message is available.
msg, err := s.ParseReader(os.Stdin)
if err != nil {
panic(err)
}
for _, record := range msg.DataRecords {
// record contains raw enterpriseId, fieldId => []byte information
fmt.Println(record)
}
}
}
func ExampleInterpreter() {
s := ipfix.NewSession()
i := ipfix.NewInterpreter(s)
for {
// ParseReader will block until a full message is available.
msg, err := s.ParseReader(os.Stdin)
if err != nil {
panic(err)
}
var fieldList []ipfix.InterpretedField
for _, record := range msg.DataRecords {
fieldList = i.InterpretInto(record, fieldList)
fmt.Println(fieldList)
}
}
}
func ExampleInterpreter_AddDictionaryEntry() {
s := ipfix.NewSession()
i := ipfix.NewInterpreter(s)
entry := ipfix.DictionaryEntry{
Name: "someVendorField",
FieldID: 42,
EnterpriseID: 123456,
Type: ipfix.Int32,
}
i.AddDictionaryEntry(entry)
// Now use i.Interpret() etc as usual.
}