Fix Size for maps.
This was terribly broken, but we got lucky for small map entries.
The old code was trying to compute the size of the tag codes for
the key and value, but that's the responsibility of the sizer for
the particular key and value. What size_new_map needs to account for
is the length of the tag code and length varint of the map entry itself.
Fixes #21.
diff --git a/proto/encode.go b/proto/encode.go
index cd826e9..d1abc33 100644
--- a/proto/encode.go
+++ b/proto/encode.go
@@ -1128,10 +1128,12 @@
keycopy.Set(key)
valcopy.Set(val)
- // Tag codes are two bytes per map entry.
- n += 2
- n += p.mkeyprop.size(p.mkeyprop, keybase)
- n += p.mvalprop.size(p.mvalprop, valbase)
+ // Tag codes for key and val are the responsibility of the sub-sizer.
+ keysize := p.mkeyprop.size(p.mkeyprop, keybase)
+ valsize := p.mvalprop.size(p.mvalprop, valbase)
+ entry := keysize + valsize
+ // Add on tag code and length of map entry itself.
+ n += len(p.tagcode) + sizeVarint(uint64(entry)) + entry
}
return n
}