-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom_fields.go
57 lines (46 loc) · 1.06 KB
/
custom_fields.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
package egmanifest
import (
"encoding/binary"
"io"
"github.com/er-azh/egmanifest/binreader"
)
type FCustomFields struct {
DataSize uint32
DataVersion uint8
Count uint32
Fields map[string]string
}
func ReadCustomFields(f io.ReadSeeker) (*FCustomFields, error) {
reader := binreader.NewReader(f, binary.LittleEndian)
var fields FCustomFields
var err error
fields.DataSize, err = reader.ReadUint32()
if err != nil {
return nil, err
}
fields.DataVersion, err = reader.ReadUint8()
if err != nil {
return nil, err
}
fields.Count, err = reader.ReadUint32()
if err != nil {
return nil, err
}
fields.Fields = map[string]string{}
// store the keys for the second iteration
firstHalf := make([]string, fields.Count)
for idx := range firstHalf {
firstHalf[idx], err = reader.ReadFString()
if err != nil {
return nil, err
}
}
// map indexs to keys and use them to build the map
for idx := range firstHalf {
fields.Fields[firstHalf[idx]], err = reader.ReadFString()
if err != nil {
return nil, err
}
}
return &fields, nil
}