mirror of https://bitbucket.org/ausocean/av.git
stream/mts: added meta.go file to contain struct and methods relating to Metadata and operations
This commit is contained in:
parent
87ded6bf2e
commit
8f5a2352b2
|
@ -29,10 +29,7 @@ LICENSE
|
|||
package mts
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/ausocean/av/stream/mts/pes"
|
||||
|
@ -93,49 +90,6 @@ const (
|
|||
// global Meta
|
||||
var meta Meta
|
||||
|
||||
type Meta struct {
|
||||
mu sync.RWMutex
|
||||
data map[string]string
|
||||
}
|
||||
|
||||
// Add adds metadata with key and val, if already exists return error
|
||||
func (m *Meta) Add(key, val string) error {
|
||||
m.mu.Lock()
|
||||
if _, exists := m.data[key]; !exists {
|
||||
return errors.New(fmt.Sprintf("Metadata for: %v already exists", key))
|
||||
}
|
||||
m.data[key] = val
|
||||
m.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// All returns the a copy of the map containing the meta data
|
||||
func (m *Meta) All() map[string]string {
|
||||
var cpy map[string]string
|
||||
for k, v := range m.data {
|
||||
cpy[k] = v
|
||||
}
|
||||
return cpy
|
||||
}
|
||||
|
||||
// Get returns the meta data for the passed key
|
||||
func (m *Meta) Get(key string) (string, error) {
|
||||
val, ok := m.data[key]
|
||||
if !ok {
|
||||
return "", errors.New("Key does not exist in metadata map")
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// Remove deletes a meta entry in the map and returns error if it doesn’t exist
|
||||
func (m *Meta) Delete(key string) error {
|
||||
if _, ok := m.data[key]; ok {
|
||||
delete(m.data, key)
|
||||
return nil
|
||||
}
|
||||
return errors.New("Trying to delete map entry that doesn't exist")
|
||||
}
|
||||
|
||||
// updateMeta ...
|
||||
func updateMeta(b []byte) error {
|
||||
var p psi.PSIBytes
|
||||
|
|
Loading…
Reference in New Issue