-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample_test.go
159 lines (140 loc) · 3.58 KB
/
example_test.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package cuei_test
import (
"fmt"
"github.com/futzu/cuei"
"testing"
)
//func BenchmarkStream(b *testing.B) {
// stream := cuei.NewStream()
// stream.Decode("/home/a/v2.ts")
//}
func ExampleJson2Cue() {
js := `{
"InfoSection": {
"Name": "Splice Info Section",
"TableID": "0xfc",
"SectionSyntaxIndicator": false,
"Private": false,
"Reserved": "0x3",
"SectionLength": 42,
"ProtocolVersion": 0,
"EncryptedPacket": false,
"EncryptionAlgorithm": 0,
"PtsAdjustment": 0,
"CwIndex": "0xff",
"Tier": "0xfff",
"CommandLength": 15,
"CommandType": 5
},
"Command": {
"Name": "Splice Insert",
"CommandType": 5,
"SpliceEventID": 5690,
"OutOfNetworkIndicator": true,
"ProgramSpliceFlag": true,
"TimeSpecifiedFlag": true,
"PTS": 23683.480033
},
"DescriptorLoopLength": 10,
"Descriptors": [
{
"Length": 8,
"Identifier": "CUEI",
"Name": "Avail Descriptor"
}
]
}
`
cue := cuei.Json2Cue(js)
cue.Show()
}
func ExampleNewCue() {
data := "/DCtAAAAAAAAAP/wBQb+Tq9DwQCXAixDVUVJCUvhcH+fAR1QQ1IxXzEyMTYyMTE0MDBXQUJDUkFDSEFFTFJBWSEBAQIsQ1VFSQlL4W9/nwEdUENSMV8xMjE2MjExNDAwV0FCQ1JBQ0hBRUxSQVkRAQECGUNVRUkJTBwVf58BClRLUlIxNjA4NEEQAQECHkNVRUkJTBwWf98AA3clYAEKVEtSUjE2MDg0QSABAdHBXYA="
cue := cuei.NewCue()
cue.Command = &cuei.Command{}
cue.Decode(data)
cue.Show()
}
func ExampleCue_Decode() {
data := "/DAWAAAAAAAAAP/wBQb+AKmKxwAACzuu2Q=="
cue := cuei.NewCue()
cue.Decode(data)
fmt.Println("Cue.Decode() parses data and populate the fields in the Cue.")
cue.Show()
fmt.Println("\n\nCue values can be accessed via dot notiation,")
cue.Command.PTS = 987.654321
fmt.Printf("cue.Command.PTS = %v\n", cue.Command.PTS)
cue.Show()
}
func ExampleCue_Encode() {
data := "/DAWAAAAAAAAAP/wBQb+AKmKxwAACzuu2Q=="
cue := cuei.NewCue()
cue.Decode(data)
// encode to bytes
fmt.Println(cue.Encode())
}
func ExampleCue_Encode2B64() {
data := "/DAWAAAAAAAAAP/wBQb+AKmKxwAACzuu2Q=="
cue := cuei.NewCue()
cue.Decode(data)
// encode to base64
fmt.Println(cue.Encode2B64())
}
func ExampleCue_Encode2Hex() {
data := "/DAWAAAAAAAAAP/wBQb+AKmKxwAACzuu2Q=="
cue := cuei.NewCue()
// decode base64 data into cue
cue.Decode(data)
// Encode the cue as hex
hexed := cue.Encode2Hex()
fmt.Println(hexed)
// decode the hex back into a Cue
cue.Decode(hexed)
cue.Show()
}
func ExampleCue_AdjustPts() {
data := "/DAWAAAAAAAAAP/wBQb+AKmKxwAACzuu2Q=="
cue := cuei.NewCue()
cue.Decode(data)
fmt.Println("Before calling Cue.AdjustPts")
fmt.Println(data)
cue.InfoSection.Show()
fmt.Println()
// Change cue.InfoSection.PtsAdjustment and re-encode cue to bytes
cue.AdjustPts(33.333)
fmt.Println("After calling Cue.AdjustPts")
fmt.Println(cue.Encode2B64())
cue.InfoSection.Show()
}
func ExampleCue_Show() {
dee := "/DA0AAAAAAAAAAAABQb/4zZ7tQAeAhxDVUVJAA6Gjz/TAAESy7EICAAAAAAA0/cuIgAAjFLk9Q=="
cue := cuei.NewCue()
cue.Decode(dee)
cue.Show()
}
func Test(t *testing.T) {
t.Run("Json2Cue", func(t *testing.T) {
ExampleJson2Cue()
})
t.Run("Cue.Decode()", func(t *testing.T) {
ExampleCue_Decode()
})
t.Run("Cue.AdjustPts()", func(t *testing.T) {
ExampleCue_AdjustPts()
})
t.Run("NewCue", func(t *testing.T) {
ExampleNewCue()
})
t.Run("Cue_Encode", func(t *testing.T) {
ExampleCue_Encode()
})
t.Run("Cue_Encode2B64", func(t *testing.T) {
ExampleCue_Encode2B64()
})
t.Run("Cue_Encode2Hex", func(t *testing.T) {
ExampleCue_Encode2Hex()
})
t.Run("Cue_Show", func(t *testing.T) {
ExampleCue_Show()
})
}