From 57d1dba2fb809d8f8874842138b773abdeb7267d Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 6 Feb 2019 12:16:44 +1030 Subject: [PATCH] stream/mts/meta/meta.go: updated meta.NewWith so that it just uses meta.New, and now ti can add an abitrary number of things to the map. It also overwrites keys that have been repeated --- stream/mts/meta/meta.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/stream/mts/meta/meta.go b/stream/mts/meta/meta.go index 97725252..a2d56e1a 100644 --- a/stream/mts/meta/meta.go +++ b/stream/mts/meta/meta.go @@ -76,18 +76,18 @@ func New() *Data { } } -func NewWith(key, data string) *Data { - meta := &Data{ - 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 - }, +// NewWith creates a meta.Data and fills map with initial data given. If there +// is repeated key, then the latter overwrites the prior. +func NewWith(data [][2]string) *Data { + m := New() + m.order = make([]string, 0, len(data)) + for _, d := range data { + if _, exists := m.data[d[0]]; !exists { + m.order = append(m.order, d[0]) + } + m.data[d[0]] = d[1] } - meta.Add(key, data) - return meta + return m } // Add adds metadata with key and val.