Просмотр исходного кода

Don't sort map keys when encoding a map field in wire format.

This was a miscommunication; I heard that the map keys were meant
to be sorted, but that statement was only meant to apply to the
text format. With this change we match the C++ behaviour.

Fixes #86.
David Symonds 10 лет назад
Родитель
Сommit
efcaa340c1
1 измененных файлов с 2 добавлено и 3 удалено
  1. 2 3
      proto/encode.go

+ 2 - 3
proto/encode.go

@@ -1115,9 +1115,8 @@ func (o *Buffer) enc_new_map(p *Properties, base structPointer) error {
 		return nil
 	}
 
-	keys := v.MapKeys()
-	sort.Sort(mapKeys(keys))
-	for _, key := range keys {
+	// Don't sort map keys. It is not required by the spec, and C++ doesn't do it.
+	for _, key := range v.MapKeys() {
 		val := v.MapIndex(key)
 
 		// The only illegal map entry values are nil message pointers.