-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsymbols.go
63 lines (47 loc) · 1.33 KB
/
symbols.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
package cypress
import "fmt"
// Symbols is used to minimize attribute key values by using preset keys.
// Each message version in the wild has a symbol set, allowing for symbol
// set evolution.
type symbols struct {
StrToIndex map[string]uint32
IndexToStr []string
}
func newSymbols() *symbols {
return &symbols{
make(map[string]uint32),
[]string{"-"}, // we start the symbol values at 1 so we reserve 0
}
}
func (s *symbols) Append(strings ...string) {
for _, str := range strings {
if _, ok := s.StrToIndex[str]; ok {
panic(fmt.Sprintf("already assigned %s", str))
}
idx := len(s.IndexToStr)
s.IndexToStr = append(s.IndexToStr, str)
s.StrToIndex[str] = uint32(idx)
}
}
func (s *symbols) FromIndex(i uint32) string {
if i > uint32(len(s.IndexToStr)) {
return fmt.Sprintf("symbol%d", i)
}
return s.IndexToStr[i]
}
func (s *symbols) FindIndex(str string) (uint32, bool) {
if idx, ok := s.StrToIndex[str]; ok {
return idx, true
}
return 0, false
}
var versionSymbols []*symbols
func init() {
// do not reorder this function. Do not alphabetize these. They're order
// in the function dictates their idx. Change them breaks shit.
v1 := newSymbols()
v1.Append("message", "value", "source")
v1.Append("host", "facility", "severity", "tag", "pid")
v1.Append("name", "type")
versionSymbols = []*symbols{v1, v1}
}