meta: add consts for metadata keys

This commit is contained in:
Trek H 2021-02-22 16:37:13 +10:30
parent 357cb196b9
commit fdf17f3a97
3 changed files with 23 additions and 17 deletions

View File

@ -104,8 +104,8 @@ const (
// Used to consistently read and write MTS metadata entries.
const (
WriteRateKey = "writeRate"
TimestampKey = "ts"
LocationKey = "loc"
TimestampKey = meta.TimestampKey
LocationKey = meta.LocationKey
)
// Meta allows addition of metadata to encoded mts from outside of this pkg.
@ -114,7 +114,7 @@ const (
// TODO: make this not global.
var Meta *meta.Data
// This will help us obtain a realtime for timestamp meta encoding.
// RealTime will help us obtain a realtime for timestamp meta encoding.
var RealTime = realtime.NewRealTime()
// Encoder encapsulates properties of an MPEG-TS generator.

View File

@ -52,6 +52,12 @@ const (
dataLenIdx = 2
)
// Used to consistently read and write metadata entries.
const (
TimestampKey = "ts"
LocationKey = "loc"
)
var (
errKeyAbsent = errors.New("Key does not exist in map")
errInvalidMeta = errors.New("Invalid metadata given")

View File

@ -32,9 +32,9 @@ import (
)
const (
tstKey1 = "loc"
tstKey1 = LocationKey
tstData1 = "a,b,c"
tstKey2 = "ts"
tstKey2 = TimestampKey
tstData2 = "12345678"
tstData3 = "d,e,f"
)
@ -69,7 +69,7 @@ func TestUpdate(t *testing.T) {
if data, ok := meta.Get(tstKey1); !ok {
t.Errorf("Could not get data for key: %v\n", tstKey1)
if data != tstData2 {
t.Error(`Data did not correctly update for key "loc"`)
t.Errorf("Data did not correctly update for key: %v\n", tstKey1)
}
}
}
@ -143,11 +143,11 @@ func TestGetFrom(t *testing.T) {
want string
}{
{
"loc",
LocationKey,
"a,b,c",
},
{
"ts",
TimestampKey,
"12345",
},
}
@ -169,11 +169,11 @@ func TestGetAll(t *testing.T) {
tstMeta := append([]byte{0x00, 0x10, 0x00, 0x12}, "loc=a,b,c\tts=12345"...)
want := [][2]string{
{
"loc",
LocationKey,
"a,b,c",
},
{
"ts",
TimestampKey,
"12345",
},
}
@ -191,8 +191,8 @@ func TestGetAll(t *testing.T) {
func TestGetAllAsMap(t *testing.T) {
tstMeta := append([]byte{0x00, 0x10, 0x00, 0x12}, "loc=a,b,c\tts=12345"...)
want := map[string]string{
"loc": "a,b,c",
"ts": "12345",
LocationKey: "a,b,c",
TimestampKey: "12345",
}
got, err := GetAllAsMap(tstMeta)
if err != nil {
@ -207,7 +207,7 @@ func TestGetAllAsMap(t *testing.T) {
// the meta.Keys method.
func TestKeys(t *testing.T) {
tstMeta := append([]byte{0x00, 0x10, 0x00, 0x12}, "loc=a,b,c\tts=12345"...)
want := []string{"loc", "ts"}
want := []string{LocationKey, TimestampKey}
got, err := Keys(tstMeta)
if err != nil {
t.Errorf("Unexpected error: %v\n", err)
@ -220,8 +220,8 @@ func TestKeys(t *testing.T) {
// TestNewFromMap checks that we can successfully create a new data struct from a map.
func TestNewFromMap(t *testing.T) {
want := map[string]string{
"loc": "a,b,c",
"ts": "12345",
LocationKey: "a,b,c",
TimestampKey: "12345",
}
meta := NewFromMap(want)
@ -236,8 +236,8 @@ func TestNewFromMap(t *testing.T) {
// TestEncodeAsString checks that metadata is correctly encoded as a string.
func TestEncodeAsString(t *testing.T) {
meta := NewFromMap(map[string]string{
"loc": "a,b,c",
"ts": "12345",
LocationKey: "a,b,c",
TimestampKey: "12345",
})
got := meta.EncodeAsString()