forked from mstoykov/mp4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uni.go
50 lines (42 loc) · 931 Bytes
/
uni.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
package mp4
import (
"encoding/binary"
"fmt"
"io"
)
// UniBox - Universal not decoded Box
type UniBox struct {
BoxHeader
buff []byte
}
// DecodeUni - decodes uni
func DecodeUni(header BoxHeader) *UniBox {
fmt.Printf("Universal not decoded box with header %#v\n", header)
return &UniBox{
BoxHeader: header,
}
}
// Decode decodes a uni
func (u *UniBox) Decode(r io.Reader, size uint64) (Box, error) {
u.buff = make([]byte, size)
if err := binary.Read(r, binary.BigEndian, u.buff); err != nil {
return nil, err
}
return u, nil
}
// Type returns teh real type of the box
func (u *UniBox) Type() string {
return u.BoxHeader.Type
}
// Size returns the true size of the box
func (u *UniBox) Size() uint64 {
return u.BoxHeader.Size
}
// Encode really encodes the box
func (u *UniBox) Encode(w io.Writer) error {
if err := EncodeHeader(u, w); err != nil {
return err
}
_, err := w.Write(u.buff)
return err
}