From f3d96943fed865c532adc8e7cc7a07cb7382e7a3 Mon Sep 17 00:00:00 2001 From: Gabrielius Mickevicius Date: Tue, 2 Feb 2016 17:50:36 +0000 Subject: [PATCH] encode unknown protocol addresses as strings --- codec.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/codec.go b/codec.go index 64e7d04..5003621 100644 --- a/codec.go +++ b/codec.go @@ -211,6 +211,13 @@ func addressStringToBytes(p Protocol, s string) ([]byte, error) { return b, nil } + // otherwise just encode the bare string + if p.Size == LengthPrefixedVarSize { + b := []byte(s) + size := CodeToVarint(len(b)) + return append(size, b...), nil + } + return []byte{}, fmt.Errorf("failed to parse %s addr: unknown", p.Name) } @@ -240,5 +247,15 @@ func addressBytesToString(p Protocol, b []byte) (string, error) { return m.B58String(), nil } + // otherwise just decode to bare string + if p.Size == LengthPrefixedVarSize { + size, n := ReadVarintCode(b) + b = b[n:] + if len(b) != size { + panic("inconsistent lengths") + } + return string(b), nil + } + return "", fmt.Errorf("unknown protocol") }