-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_section.go
More file actions
executable file
·47 lines (39 loc) · 926 Bytes
/
data_section.go
File metadata and controls
executable file
·47 lines (39 loc) · 926 Bytes
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
package wax
import (
"bytes"
)
/*
The data section has the id 11.
It decodes into a vector of data segments that represent the data component of a module.
datasec ::= seg*:section11(vec(data)) -> seg
data ::= x:memidx e:expr b*:vec(byte) -> {data x, offset e, init b*}
*/
type DataSection struct {
SectionBase
Data []Data
}
func ParseDataSection(ber *BinaryEncodingReader, id SectionID) (*DataSection, error) {
sb, err := ParseSectionBase(ber, id)
if err != nil {
return nil, err
}
cr := NewBinaryEncodingReader(bytes.NewReader(sb.Content))
// Read count of vector
count64, _, err := cr.ReadVaruint()
if err != nil {
return nil, err
}
count := uint32(count64)
data := make([]Data, 0, count)
for i := uint32(0); i < count; i++ {
d, err := ParseData(cr)
if err != nil {
return nil, err
}
data = append(data, *d)
}
return &DataSection{
SectionBase: *sb,
Data: data,
}, nil
}