-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdref.go
106 lines (84 loc) · 1.69 KB
/
dref.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
package bmff
import (
"encoding/binary"
)
type DataReference struct {
*fullbox
Entries []DataEntry
}
func (b *DataReference) parse() error {
entryCount := binary.BigEndian.Uint32(b.raw[0:4])
b.raw = b.raw[4:]
b.Entries = make([]DataEntry, 0, entryCount)
for subBox := range readBoxes(b.raw) {
var fb *fullbox
switch subBox.boxtype {
case "url ", "urn ":
fb = &fullbox{box: subBox}
if err := fb.decode(); err != nil {
return err
}
}
switch subBox.boxtype {
case "url ":
url := &DataEntryURL{fullbox: fb}
if err := url.parse(); err != nil {
return err
}
b.Entries = append(b.Entries, url)
case "urn ":
urn := &DataEntryURN{fullbox: fb}
if err := urn.parse(); err != nil {
return err
}
b.Entries = append(b.Entries, urn)
}
}
b.raw = nil
return nil
}
const inFile = 0x01
type DataEntry interface {
Name() string
Location() string
InFile() bool
}
type DataEntryURL struct {
*fullbox
location string
}
func (b *DataEntryURL) parse() error {
if !b.InFile() {
b.location = string(b.raw[:])
}
return nil
}
func (b *DataEntryURL) Name() string {
return ""
}
func (b *DataEntryURL) Location() string {
return b.location
}
func (b *DataEntryURL) InFile() bool {
return (b.flags & inFile) > 0
}
type DataEntryURN struct {
*fullbox
name string
location string
}
func (b *DataEntryURN) parse() error {
firstTerminator := clen(b.raw[:])
b.name = string(b.raw[0:firstTerminator])
b.location = string(b.raw[firstTerminator:])
return nil
}
func (b *DataEntryURN) Name() string {
return b.name
}
func (b *DataEntryURN) Location() string {
return b.location
}
func (b *DataEntryURN) InFile() bool {
return (b.flags & inFile) > 0
}