-
Notifications
You must be signed in to change notification settings - Fork 7
/
except.go
56 lines (46 loc) · 1.03 KB
/
except.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
package ciqdb
import (
"encoding/binary"
"strconv"
"strings"
)
type Exceptions struct {
PRGSection
exc []Exception
}
func (e *Exceptions) String() string {
var buf strings.Builder
buf.WriteString(e.PRGSection.String() + "\n")
for _, ex := range e.exc {
buf.WriteString(" Exception: try: " +
strconv.Itoa(ex.tryBegin) +
" - " + strconv.Itoa(ex.tryEnd) +
". Handle: " + strconv.Itoa(ex.handleBegin))
}
return buf.String()
}
type Exception struct {
tryBegin int
tryEnd int
handleBegin int
}
func i24ToInt(d []byte) int {
return int(d[2]) | int(d[1])<<8 | int(d[0])<<16
}
func parseExceptions(p *PRG, t SecType, length int, data []byte) *Exceptions {
e := Exceptions{
PRGSection: PRGSection{
Type: t,
length: length,
},
}
count := int(binary.BigEndian.Uint16(data[0:2]))
for i := 0; i < count; i++ {
e.exc = append(e.exc, Exception{
tryBegin: i24ToInt(data[i*9+2 : i*9+5]),
tryEnd: i24ToInt(data[i*9+5 : i*9+8]),
handleBegin: i24ToInt(data[i*9+8 : i*9+11]),
})
}
return &e
}