-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
34 lines (30 loc) · 953 Bytes
/
Copy pathexample_test.go
File metadata and controls
34 lines (30 loc) · 953 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
package loc_test
import (
"fmt"
"github.com/floatdrop/moq-go/pkg/moqt/loc"
)
// LOC turns codec frames into the bytes that fill a MOQT object's Properties
// and Payload slots. Encode produces the two byte slices that drop straight
// into a message.SubgroupObject; Decode reverses it on the subscriber side.
func ExampleObject_Encode() {
obj := loc.Object{
Properties: loc.Properties{
Timestamp: 1718668800000,
HasTimestamp: true,
Timescale: 1000,
HasTimescale: true,
},
Payload: []byte("encoded-frame-bytes"), // codec elementary stream
}
props, payload := obj.Encode()
// On the subscriber, recover the typed Properties and payload.
decoded, err := loc.Decode(props, payload)
if err != nil {
panic(err)
}
fmt.Printf("ts=%d timescale=%d payload=%q\n",
decoded.Properties.Timestamp,
decoded.Properties.Timescale,
decoded.Payload)
// Output: ts=1718668800000 timescale=1000 payload="encoded-frame-bytes"
}