This repository was archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.go
More file actions
70 lines (54 loc) · 1.24 KB
/
array.go
File metadata and controls
70 lines (54 loc) · 1.24 KB
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
package amf0
import (
"bytes"
"encoding/binary"
"errors"
"io"
"reflect"
)
type Array struct {
*Paired
}
var _ AmfType = new(Array)
func NewArray() *Array {
return &Array{NewPaired()}
}
// Implements AmfType.Marker
func (a *Array) Marker() byte { return 0x08 }
func (a *Array) Native() reflect.Type { return reflect.TypeOf(a) }
// Implements AmfType.Decode
func (a *Array) Decode(r io.Reader) error {
var n [4]byte
if _, err := io.ReadFull(r, n[:]); err != nil {
return err
}
a.tuples = make([]*tuple, 0, binary.BigEndian.Uint32(n[:]))
for i := 0; i < cap(a.tuples); i++ {
if err := a.decodePair(r); err != nil {
return err
}
}
var endSeq [3]byte
if _, err := io.ReadFull(r, endSeq[:]); err != nil {
return err
}
if !bytes.Equal(ObjectEndSeq, endSeq[:]) {
return errors.New("amf0: missing end sequence for array")
}
return nil
}
// Implements AmfType.Encode
func (a *Array) Encode(w io.Writer) (int, error) {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, uint32(len(a.tuples)))
a.writePairs(buf)
buf.Write(ObjectEndSeq)
n, err := io.Copy(w, buf)
return int(n), err
}
// Implements AmfType.EncodeBytes
func (a *Array) EncodeBytes() []byte {
buf := new(bytes.Buffer)
a.Encode(buf)
return buf.Bytes()
}