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
for _, e := range en {
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))
}
}
@ -58,27 +54,14 @@ func encodeEndpoints(en []*Endpoint) []string {
func decodeEndpoints(tags []string) []*Endpoint {
var en []*Endpoint
// use the first format you find
var ver byte
for _, tag := range tags {
if len(tag) == 0 || tag[0] != 'e' {
continue
}
// check version
if ver > 0 && tag[1] != ver {
continue
}
var e *Endpoint
var buf []byte
// Old encoding was plain
if tag[1] == '=' {
buf = []byte(tag[2:])
}
// New encoding is hex
if tag[1] == '-' {
buf = decode(tag[2:])
@ -87,9 +70,6 @@ func decodeEndpoints(tags []string) []*Endpoint {
if err := json.Unmarshal(buf, &e); err == nil {
en = append(en, e)
}
// set version
ver = tag[1]
}
return en
}
@ -100,9 +80,6 @@ func encodeMetadata(md map[string]string) []string {
if b, err := json.Marshal(map[string]string{
k: v,
}); err == nil {
// old encoding
// TODO: remove in 09/2016
tags = append(tags, "t="+string(b))
// new encoding
tags = append(tags, "t-"+encode(b))
}
@ -113,26 +90,14 @@ func encodeMetadata(md map[string]string) []string {
func decodeMetadata(tags []string) map[string]string {
md := make(map[string]string)
var ver byte
for _, tag := range tags {
if len(tag) == 0 || tag[0] != 't' {
continue
}
// check version
if ver > 0 && tag[1] != ver {
continue
}
var kv map[string]string
var buf []byte
// Old encoding was plain
if tag[1] == '=' {
buf = []byte(tag[2:])
}
// New encoding is hex
if tag[1] == '-' {
buf = decode(tag[2:])
@ -144,21 +109,12 @@ func decodeMetadata(tags []string) map[string]string {
md[k] = v
}
}
// set version
ver = tag[1]
}
return md
}
func encodeVersion(v string) []string {
return []string{
// old encoding,
// TODO: remove in 09/2016
"v=" + v,
// new encoding,
"v-" + encode([]byte(v)),
}
return []string{"v-" + encode([]byte(v))}
}
func decodeVersion(tags []string) (string, bool) {
@ -167,11 +123,6 @@ func decodeVersion(tags []string) (string, bool) {
continue
}
// Old encoding was plain
if tag[1] == '=' {
return tag[2:], true
}
// New encoding is hex
if tag[1] == '-' {
return string(decode(tag[2:])), true