Don't strip decode because its good to be backwards compatible still

This commit is contained in:
Asim 2016-05-22 18:43:47 +01:00
parent 2708f9c04b
commit 04bc20798d

View File

@ -54,14 +54,27 @@ func encodeEndpoints(en []*Endpoint) []string {
func decodeEndpoints(tags []string) []*Endpoint { func decodeEndpoints(tags []string) []*Endpoint {
var en []*Endpoint var en []*Endpoint
// use the first format you find
var ver byte
for _, tag := range tags { for _, tag := range tags {
if len(tag) == 0 || tag[0] != 'e' { if len(tag) == 0 || tag[0] != 'e' {
continue continue
} }
// check version
if ver > 0 && tag[1] != ver {
continue
}
var e *Endpoint var e *Endpoint
var buf []byte var buf []byte
// Old encoding was plain
if tag[1] == '=' {
buf = []byte(tag[2:])
}
// New encoding is hex // New encoding is hex
if tag[1] == '-' { if tag[1] == '-' {
buf = decode(tag[2:]) buf = decode(tag[2:])
@ -70,6 +83,9 @@ func decodeEndpoints(tags []string) []*Endpoint {
if err := json.Unmarshal(buf, &e); err == nil { if err := json.Unmarshal(buf, &e); err == nil {
en = append(en, e) en = append(en, e)
} }
// set version
ver = tag[1]
} }
return en return en
} }
@ -90,14 +106,26 @@ func encodeMetadata(md map[string]string) []string {
func decodeMetadata(tags []string) map[string]string { func decodeMetadata(tags []string) map[string]string {
md := make(map[string]string) md := make(map[string]string)
var ver byte
for _, tag := range tags { for _, tag := range tags {
if len(tag) == 0 || tag[0] != 't' { if len(tag) == 0 || tag[0] != 't' {
continue continue
} }
// check version
if ver > 0 && tag[1] != ver {
continue
}
var kv map[string]string var kv map[string]string
var buf []byte var buf []byte
// Old encoding was plain
if tag[1] == '=' {
buf = []byte(tag[2:])
}
// New encoding is hex // New encoding is hex
if tag[1] == '-' { if tag[1] == '-' {
buf = decode(tag[2:]) buf = decode(tag[2:])
@ -109,6 +137,9 @@ func decodeMetadata(tags []string) map[string]string {
md[k] = v md[k] = v
} }
} }
// set version
ver = tag[1]
} }
return md return md
} }
@ -123,6 +154,11 @@ func decodeVersion(tags []string) (string, bool) {
continue continue
} }
// Old encoding was plain
if tag[1] == '=' {
return tag[2:], true
}
// New encoding is hex // New encoding is hex
if tag[1] == '-' { if tag[1] == '-' {
return string(decode(tag[2:])), true return string(decode(tag[2:])), true