Sort numerically-keyed maps by numeric value.
This matches the C++ output and the specification
(https://developers.google.com/protocol-buffers/docs/proto#maps).
Technically we don't have to do this for the wire format,
but it's faster and less code to make them the same.
diff --git a/proto/text_test.go b/proto/text_test.go
index 39861d1..64579e9 100644
--- a/proto/text_test.go
+++ b/proto/text_test.go
@@ -421,10 +421,19 @@
{&proto3pb.Message{Name: "Rob", HeightInCm: 175}, `name:"Rob" height_in_cm:175`},
// empty map
{&pb.MessageWithMap{}, ``},
- // non-empty map; current map format is the same as a repeated struct
+ // non-empty map; map format is the same as a repeated struct,
+ // and they are sorted by key (numerically for numeric keys).
{
- &pb.MessageWithMap{NameMapping: map[int32]string{1234: "Feist"}},
- `name_mapping:<key:1234 value:"Feist" >`,
+ &pb.MessageWithMap{NameMapping: map[int32]string{
+ -1: "Negatory",
+ 7: "Lucky",
+ 1234: "Feist",
+ 6345789: "Otis",
+ }},
+ `name_mapping:<key:-1 value:"Negatory" > ` +
+ `name_mapping:<key:7 value:"Lucky" > ` +
+ `name_mapping:<key:1234 value:"Feist" > ` +
+ `name_mapping:<key:6345789 value:"Otis" >`,
},
// map with nil value; not well-defined, but we shouldn't crash
{