/
textdescription.go
54 lines (43 loc) · 953 Bytes
/
textdescription.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
package icc
import (
"bytes"
"fmt"
"github.com/mandykoh/prism/meta/binary"
)
type TextDescription struct {
ASCII string
}
func parseTextDescription(data []byte) (TextDescription, error) {
desc := TextDescription{}
reader := bytes.NewReader(data)
sig, err := binary.ReadU32Big(reader)
if err != nil {
return desc, err
}
if s := Signature(sig); s != DescSignature {
return desc, fmt.Errorf("expected %v but got %v", DescSignature, s)
}
// Reserved field
_, err = binary.ReadU32Big(reader)
if err != nil {
return desc, err
}
asciiCount, err := binary.ReadU32Big(reader)
if err != nil {
return desc, err
}
asciiBytes := make([]byte, asciiCount-1)
for i := 0; i < len(asciiBytes); i++ {
asciiBytes[i], err = reader.ReadByte()
if err != nil {
return desc, err
}
}
// Skip terminating null
_, err = reader.ReadByte()
if err != nil {
return desc, err
}
desc.ASCII = string(asciiBytes)
return desc, nil
}