Sort map keys when serialising map fields to binary and text formats.
This gives deterministic output, albeit somewhat inefficently.
I expect the inefficiency to be dwarfed by the reflection involved
anyway, but it's easy enough to improve this later if needed.
diff --git a/proto/encode.go b/proto/encode.go
index f5050e3..1512d60 100644
--- a/proto/encode.go
+++ b/proto/encode.go
@@ -1101,7 +1101,9 @@
return nil
}
- for _, key := range v.MapKeys() {
+ keys := v.MapKeys()
+ sort.Sort(mapKeys(keys))
+ for _, key := range keys {
val := v.MapIndex(key)
keycopy.Set(key)