mirror of https://bitbucket.org/ausocean/av.git
mts/meta: created EncodeAsString and GetAllFromString methods
This commit is contained in:
parent
6855244424
commit
cca292ea17
|
@ -178,6 +178,23 @@ func (m *Data) Encode() []byte {
|
||||||
return m.enc
|
return m.enc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EncodeAsString takes the meta data map and encodes into a string with the data in
|
||||||
|
// TSV format. Unlike encode, the header with version and length of data is not
|
||||||
|
// included. This method is used for storing metadata in the store on vidgrind.
|
||||||
|
func (m *Data) EncodeAsString() string {
|
||||||
|
// Iterate over map and append entries, only adding tab if we're not on the
|
||||||
|
// last entry.
|
||||||
|
var str string
|
||||||
|
for i, k := range m.order {
|
||||||
|
v := m.data[k]
|
||||||
|
str += k + "=" + v
|
||||||
|
if i+1 < len(m.data) {
|
||||||
|
str += "\t"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
// Keys returns all keys in a slice of metadata d.
|
// Keys returns all keys in a slice of metadata d.
|
||||||
func Keys(d []byte) ([]string, error) {
|
func Keys(d []byte) ([]string, error) {
|
||||||
m, err := GetAll(d)
|
m, err := GetAll(d)
|
||||||
|
@ -238,9 +255,15 @@ func GetAllAsMap(d []byte) (map[string]string, error) {
|
||||||
// Skip the header, which is our data length and version.
|
// Skip the header, which is our data length and version.
|
||||||
d = d[headSize:]
|
d = d[headSize:]
|
||||||
|
|
||||||
|
return GetAllFromString(string(d))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllFromString returns a map containing keys and values from a string s containing
|
||||||
|
// metadata.
|
||||||
|
func GetAllFromString(s string) (map[string]string, error) {
|
||||||
// Each metadata entry (key and value) is seperated by a tab, so split at tabs
|
// Each metadata entry (key and value) is seperated by a tab, so split at tabs
|
||||||
// to get individual entries.
|
// to get individual entries.
|
||||||
entries := strings.Split(string(d), "\t")
|
entries := strings.Split(s, "\t")
|
||||||
|
|
||||||
// Go through entries and add to all map.
|
// Go through entries and add to all map.
|
||||||
all := make(map[string]string)
|
all := make(map[string]string)
|
||||||
|
|
Loading…
Reference in New Issue