-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.go
115 lines (97 loc) · 2.17 KB
/
list.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package brlyt
import (
"encoding/binary"
"errors"
"io"
)
func (r *Root) ParseChildren() ([]Children, error) {
var children []Children
isOver := false
for {
var sectionHeader SectionHeader
err := binary.Read(r.reader, binary.BigEndian, §ionHeader)
if err != nil {
return nil, err
}
// Subtract the header size
sectionSize := int(sectionHeader.Size) - 8
// We could end off at a pane end, meaning it would try to read EOF
if sectionSize == 0 {
r.count--
break
}
temp := make([]byte, sectionSize)
_, err = r.reader.Read(temp)
if err != nil {
return nil, err
}
switch sectionHeader.Type {
case SectionTypeBND:
bnd, err := r.ParseBND(temp)
if err != nil {
return nil, err
}
children = append(children, Children{BND: bnd})
case SectionTypePIC:
pic, err := r.ParsePIC(temp)
if err != nil {
return nil, err
}
children = append(children, Children{PIC: pic})
case SectionTypeTXT:
txt, err := r.ParseTXT(temp, sectionHeader.Size)
if err != nil {
return nil, err
}
children = append(children, Children{TXT: txt})
case SectionTypeWND:
wnd, err := r.ParseWND(temp)
if err != nil {
return nil, err
}
children = append(children, Children{WND: wnd})
case SectionTypePAN:
pan, err := r.ParsePAN(temp)
if err != nil {
return nil, err
}
children = append(children, Children{Pane: pan})
case SectionTypeGRP:
grp, err := r.ParseGRP(temp)
if err != nil {
return nil, err
}
children = append(children, Children{GRP: grp})
case SectionTypePAE:
isOver = true
case SectionTypeGRE:
isOver = true
}
// Deincrement the amount of sections left to read.
r.count--
if isOver {
break
}
}
return children, nil
}
func (r *Root) HasChildren() bool {
var sectionHeader SectionHeader
err := binary.Read(r.reader, binary.BigEndian, §ionHeader)
if err != nil {
if errors.Is(err, io.EOF) {
return false
}
panic(err)
}
if sectionHeader.Type == SectionTypePAS || sectionHeader.Type == SectionTypeGRS {
// Read the pane start
r.count--
return true
}
_, err = r.reader.Seek(-8, io.SeekCurrent)
if err != nil {
panic(err)
}
return false
}