-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
100 lines (96 loc) · 1.7 KB
/
parse.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package librmonitor
import (
"encoding/csv"
"strings"
)
func Parse(raw string) any {
records, err := csv.NewReader(strings.NewReader(raw)).Read()
if err != nil {
return msg{raw}
}
// F, A, B, C, E, G, H, I, J, Cor, L, T, RMS, RMLT, RMDTL, RMCA, RMHL,
switch len(records) {
case 0:
return msg{raw}
case 1:
if records[0] == "$RMDTL" {
return ToRMDTL(raw, records[0:])
} else {
return msg{raw}
}
case 2:
// RMS, RMCA
switch records[0] {
case "$RMS":
return ToRMS(raw, records[1:])
case "$RMCA":
return ToRMCA(raw, records[1:])
default:
return msg{raw}
}
case 3:
// B, C, E, I, RMLT
switch records[0] {
case "$B":
return ToB(raw, records[1:])
case "$C":
return ToC(raw, records[1:])
case "$E":
return ToE(raw, records[1:])
case "$I":
return ToI(raw, records[1:])
case "$RMLT":
return ToRMLT(raw, records[1:])
default:
return msg{raw}
}
case 4:
// J
if records[0] == "$J" {
return ToJ(raw, records[1:])
} else {
return msg{raw}
}
case 5:
// G, H
switch records[0] {
case "$G":
return ToG(raw, records[1:])
case "$H":
return ToH(raw, records[1:])
default:
return msg{raw}
}
case 6:
// F, Cor
switch records[0] {
case "$F":
return ToF(raw, records[1:])
case "$COR":
return ToCor(raw, records[1:])
default:
return msg{raw}
}
case 7:
// RMHL
if records[0] == "$RMHL" {
return ToRMHL(raw, records[1:])
} else {
return msg{raw}
}
case 8:
// A, Comp, L
switch records[0] {
case "$A":
return ToA(raw, records[1:])
case "$Comp":
return ToComp(raw, records[1:])
case "$L":
return ToL(raw, records[1:])
default:
return msg{raw}
}
default:
return msg{raw}
}
}