-
Notifications
You must be signed in to change notification settings - Fork 0
/
processing_data.go
61 lines (55 loc) · 1.18 KB
/
processing_data.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
package sql1cv8
type processingData struct {
bin []byte
currentLevel int
currentPosit []int
lastLevel int
lastPosit int
lastValue []byte
}
func processing(bin []byte) *processingData {
return &processingData{
bin: bin[3:],
currentPosit: make([]int, 64),
}
}
func (pd *processingData) get() (int, int, string) {
return pd.lastLevel, pd.lastPosit, string(pd.lastValue)
}
func (pd *processingData) next() bool {
pd.lastValue = make([]byte, 0, 256)
var isString bool
for i, v := range pd.bin {
switch v {
case 123: // {
pd.currentLevel++
pd.currentPosit[pd.currentLevel] = 0
continue
case 125: // }
pd.bin = pd.bin[i+1:]
pd.lastLevel = pd.currentLevel
pd.lastPosit = pd.currentPosit[pd.currentLevel]
pd.currentLevel--
return true
case 44: // ,
pd.bin = pd.bin[i+1:]
pd.lastLevel = pd.currentLevel
pd.lastPosit = pd.currentPosit[pd.currentLevel]
pd.currentPosit[pd.currentLevel]++
return true
case 34: // "
if isString && pd.bin[i+1] == 34 {
isString = false
} else {
isString = !isString
continue
}
case 10, 13:
if !isString {
continue
}
}
pd.lastValue = append(pd.lastValue, v)
}
return false
}