mirror of https://bitbucket.org/ausocean/av.git
stream/mts/meta.go: completed Meta.Encode() function
This commit is contained in:
parent
00816ecf84
commit
7d34fa1969
|
@ -32,6 +32,13 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
const headSize = 4
|
||||
|
||||
const (
|
||||
majVer = 1
|
||||
minVer = 0
|
||||
)
|
||||
|
||||
var (
|
||||
errKeyAbsent = errors.New("Key does not exist in map")
|
||||
)
|
||||
|
@ -39,10 +46,19 @@ var (
|
|||
type Meta struct {
|
||||
mu sync.RWMutex
|
||||
data map[string]string
|
||||
enc []byte
|
||||
}
|
||||
|
||||
func NewMeta() *Meta {
|
||||
return &Meta{data: make(map[string]string)}
|
||||
return &Meta{
|
||||
data: make(map[string]string),
|
||||
enc: []byte{
|
||||
0x00, // Reserved byte
|
||||
(majVer << 4) | minVer, // MS and LS versions
|
||||
0x00, // Data len byte1
|
||||
0x00, // Data len byte2
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds metadata with key and val, if already exists return error
|
||||
|
@ -87,6 +103,12 @@ func (m *Meta) Delete(key string) error {
|
|||
}
|
||||
|
||||
func (m *Meta) Encode() []byte {
|
||||
// TODO: complete this
|
||||
return []byte("someData")
|
||||
m.enc = m.enc[:headSize]
|
||||
for k, v := range m.data {
|
||||
entry := k + "=" + v + "\t"
|
||||
m.enc = append(m.enc, []byte(entry)...)
|
||||
}
|
||||
// Remove final tab
|
||||
m.enc = m.enc[:len(m.enc)-1]
|
||||
return m.enc
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue