Strip old encoding

This commit is contained in:
Asim 2016-05-22 18:34:47 +01:00
parent c0eac7dda8
commit 06ee80fd0a

View File

@ -45,10 +45,6 @@ func encodeEndpoints(en []*Endpoint) []string {
var tags []string var tags []string
for _, e := range en { for _, e := range en {
if b, err := json.Marshal(e); err == nil { if b, err := json.Marshal(e); err == nil {
// old encoding
// TODO: remove in 09/2016
tags = append(tags, "e="+string(b))
// new encoding
tags = append(tags, "e-"+encode(b)) tags = append(tags, "e-"+encode(b))
} }
} }
@ -58,27 +54,14 @@ 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:])
@ -87,9 +70,6 @@ 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
} }
@ -100,9 +80,6 @@ func encodeMetadata(md map[string]string) []string {
if b, err := json.Marshal(map[string]string{ if b, err := json.Marshal(map[string]string{
k: v, k: v,
}); err == nil { }); err == nil {
// old encoding
// TODO: remove in 09/2016
tags = append(tags, "t="+string(b))
// new encoding // new encoding
tags = append(tags, "t-"+encode(b)) tags = append(tags, "t-"+encode(b))
} }
@ -113,26 +90,14 @@ 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:])
@ -144,21 +109,12 @@ func decodeMetadata(tags []string) map[string]string {
md[k] = v md[k] = v
} }
} }
// set version
ver = tag[1]
} }
return md return md
} }
func encodeVersion(v string) []string { func encodeVersion(v string) []string {
return []string{ return []string{"v-" + encode([]byte(v))}
// old encoding,
// TODO: remove in 09/2016
"v=" + v,
// new encoding,
"v-" + encode([]byte(v)),
}
} }
func decodeVersion(tags []string) (string, bool) { func decodeVersion(tags []string) (string, bool) {
@ -167,11 +123,6 @@ 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