stream/mts/meta/meta.go: renamed Metadata struct to Data

This commit is contained in:
saxon 2019-02-06 09:59:55 +10:30
parent 9b5eb558ef
commit d523677627
1 changed files with 8 additions and 8 deletions

View File

@ -56,7 +56,7 @@ var (
// Metadata provides functionality for the storage and encoding of metadata // Metadata provides functionality for the storage and encoding of metadata
// using a map. // using a map.
type Metadata struct { type Data struct {
mu sync.RWMutex mu sync.RWMutex
data map[string]string data map[string]string
order []string order []string
@ -64,8 +64,8 @@ type Metadata struct {
} }
// New returns a pointer to a new Metadata. // New returns a pointer to a new Metadata.
func New() *Metadata { func New() *Data {
return &Metadata{ return &Data{
data: make(map[string]string), data: make(map[string]string),
enc: []byte{ enc: []byte{
0x00, // Reserved byte 0x00, // Reserved byte
@ -77,7 +77,7 @@ func New() *Metadata {
} }
// Add adds metadata with key and val. // Add adds metadata with key and val.
func (m *Metadata) Add(key, val string) { func (m *Data) Add(key, val string) {
m.mu.Lock() m.mu.Lock()
defer m.mu.Unlock() defer m.mu.Unlock()
m.data[key] = val m.data[key] = val
@ -91,7 +91,7 @@ func (m *Metadata) Add(key, val string) {
} }
// All returns the a copy of the map containing the meta data. // All returns the a copy of the map containing the meta data.
func (m *Metadata) All() map[string]string { func (m *Data) All() map[string]string {
m.mu.Lock() m.mu.Lock()
cpy := make(map[string]string) cpy := make(map[string]string)
for k, v := range m.data { for k, v := range m.data {
@ -102,7 +102,7 @@ func (m *Metadata) All() map[string]string {
} }
// Get returns the meta data for the passed key. // Get returns the meta data for the passed key.
func (m *Metadata) Get(key string) (string, error) { func (m *Data) Get(key string) (string, error) {
m.mu.Lock() m.mu.Lock()
val, ok := m.data[key] val, ok := m.data[key]
m.mu.Unlock() m.mu.Unlock()
@ -113,7 +113,7 @@ func (m *Metadata) Get(key string) (string, error) {
} }
// Delete deletes a meta entry in the map and returns error if it doesnt exist. // Delete deletes a meta entry in the map and returns error if it doesnt exist.
func (m *Metadata) Delete(key string) error { func (m *Data) Delete(key string) error {
m.mu.Lock() m.mu.Lock()
defer m.mu.Unlock() defer m.mu.Unlock()
if _, ok := m.data[key]; ok { if _, ok := m.data[key]; ok {
@ -132,7 +132,7 @@ func (m *Metadata) Delete(key string) error {
// Encode takes the meta data map and encodes into a byte slice with header // Encode takes the meta data map and encodes into a byte slice with header
// describing the version, length of data and data in TSV format. // describing the version, length of data and data in TSV format.
func (m *Metadata) Encode() []byte { func (m *Data) Encode() []byte {
m.enc = m.enc[:headSize] m.enc = m.enc[:headSize]
// Iterate over map and append entries, only adding tab if we're not on the // Iterate over map and append entries, only adding tab if we're not on the