-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.go
107 lines (85 loc) · 1.73 KB
/
group.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
package brlyt
import (
"bytes"
"encoding/binary"
"strings"
)
func (r *Root) ParseGRP(data []byte) (*XMLGRP, error) {
var grp GRP
err := binary.Read(bytes.NewReader(data), binary.BigEndian, &grp)
if err != nil {
return nil, err
}
// Strip the null bytes from the strings
name := strings.Replace(string(grp.Name[:]), "\x00", "", -1)
entries := make([]string, grp.NumOfEntries)
for i := 0; i < int(grp.NumOfEntries); i++ {
offset := 20 + (i * 16)
object := strings.Replace(string(data[offset:offset+16]), "\x00", "", -1)
entries[i] = object
}
xmlData := XMLGRP{
Name: name,
Entries: entries,
}
if name == "RootGroup" {
r.RootGroup = xmlData
if r.HasChildren() {
r.RootGroup.Children, err = r.ParseChildren()
if err != nil {
return nil, err
}
}
} else {
if r.HasChildren() {
xmlData.Children, err = r.ParseChildren()
if err != nil {
return nil, err
}
}
}
return &xmlData, nil
}
func (b *BRLYTWriter) WriteGRP(data XMLGRP) error {
header := SectionHeader{
Type: SectionTypeGRP,
Size: uint32(28 + (16 * len(data.Entries))),
}
var name [16]byte
copy(name[:], data.Name)
grp := GRP{
Name: name,
NumOfEntries: uint16(len(data.Entries)),
}
err := write(b, header)
if err != nil {
return err
}
err = write(b, grp)
if err != nil {
return err
}
for _, str := range data.Entries {
var entry [16]byte
copy(entry[:], str)
err = write(b, entry)
if err != nil {
return err
}
}
return nil
}
func (b *BRLYTWriter) WriteGRS() error {
header := SectionHeader{
Type: SectionTypeGRS,
Size: 8,
}
return write(b, header)
}
func (b *BRLYTWriter) WriteGRE() error {
header := SectionHeader{
Type: SectionTypeGRE,
Size: 8,
}
return write(b, header)
}