Skip to content

Commit a24bee3

Browse files
committed
Use base64 encoding
1 parent 3889218 commit a24bee3

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

resolver/map.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
package resolver
2020

2121
import (
22-
"encoding/json"
22+
"encoding/base64"
2323
"sort"
24+
"strings"
2425
)
2526

2627
type addressMapEntry struct {
@@ -184,17 +185,19 @@ func NewEndpointMap() *EndpointMap {
184185
}
185186
}
186187

188+
// encodeEndpoint returns a string that uniquely identifies the unordered set of
189+
// addresses within an endpoint.
187190
func encodeEndpoint(e Endpoint) endpointMapKey {
188191
addrs := make([]string, 0, len(e.Addresses))
192+
// base64 encoding the address strings restricts the characters present
193+
// within the strings. This allows us to use a delimiter without the need of
194+
// escape characters.
189195
for _, addr := range e.Addresses {
190-
addrs = append(addrs, addr.String())
196+
addrs = append(addrs, base64.StdEncoding.EncodeToString([]byte(addr.String())))
191197
}
192198
sort.Strings(addrs)
193-
encoded, err := json.Marshal(addrs)
194-
if err != nil {
195-
panic("Failed to marshal []string to JSON: " + err.Error())
196-
}
197-
return endpointMapKey(encoded)
199+
// " " should not appear in base64 encoded strings.
200+
return endpointMapKey(strings.Join(addrs, " "))
198201
}
199202

200203
// Get returns the value for the address in the map, if present.

0 commit comments

Comments
 (0)