@@ -11,6 +11,9 @@ type PackMapSorted map[string]access.Packable
1111
1212// ValueSize returns the size of the packed map's content.
1313func (p PackMapSorted ) ValueSize () int {
14+ if len (p ) == 0 {
15+ return 0
16+ }
1417 size := 0
1518 for k , v := range p {
1619 // Add the size of the key and the size of the packed value.
@@ -26,6 +29,9 @@ func (p PackMapSorted) HeaderType() typetags.Type {
2629
2730// Add packs the map into a byte buffer by sorting keys first for a deterministic result.
2831func (p PackMapSorted ) Write (buf []byte , pos int ) int {
32+ if len (p ) == 0 {
33+ return pos
34+ }
2935 keys := utils .SortKeys (p )
3036 headerSize := len (p )* 2 * access .HeaderTagSize + access .HeaderTagSize
3137 first := pos
@@ -51,6 +57,9 @@ type PackMap map[string]access.Packable
5157
5258// ValueSize returns the size of the packed map's content.
5359func (p PackMap ) ValueSize () int {
60+ if len (p ) == 0 {
61+ return 0
62+ }
5463 size := 0
5564 for k , v := range p {
5665 // Add the size of the key and the size of the packed value.
@@ -66,6 +75,9 @@ func (p PackMap) HeaderType() typetags.Type {
6675
6776// Add packs the map into a byte buffer. This version does not sort keys.
6877func (p PackMap ) Write (buf []byte , pos int ) int {
78+ if len (p ) == 0 {
79+ return pos
80+ }
6981 headerSize := len (p )* 2 * access .HeaderTagSize + access .HeaderTagSize
7082 first := pos
7183 posH := pos
@@ -89,6 +101,9 @@ type PackMapStr map[string]string
89101
90102// ValueSize returns the size of the packed map's content.
91103func (p PackMapStr ) ValueSize () int {
104+ if len (p ) == 0 {
105+ return 0
106+ }
92107 size := 0
93108 for k , v := range p {
94109 // Add the size of the key and the size of the packed value.
@@ -104,6 +119,9 @@ func (p PackMapStr) HeaderType() typetags.Type {
104119
105120// Add packs the map into a byte buffer. This version does not sort keys.
106121func (p PackMapStr ) Write (buf []byte , pos int ) int {
122+ if len (p ) == 0 {
123+ return pos
124+ }
107125 headerSize := len (p )* 2 * access .HeaderTagSize + access .HeaderTagSize
108126 first := pos
109127 posH := pos
@@ -127,6 +145,9 @@ type PackMapStrInt32 map[string]int32
127145
128146// ValueSize returns the size of the packed map's content.
129147func (p PackMapStrInt32 ) ValueSize () int {
148+ if len (p ) == 0 {
149+ return 0
150+ }
130151 size := 0
131152 for k := range p {
132153 size += len (k )
@@ -142,6 +163,9 @@ func (p PackMapStrInt32) HeaderType() typetags.Type {
142163
143164// Write packs the map into a byte buffer. This version does not sort keys.
144165func (p PackMapStrInt32 ) Write (buf []byte , pos int ) int {
166+ if len (p ) == 0 {
167+ return pos
168+ }
145169 headerSize := len (p )* 2 * access .HeaderTagSize + access .HeaderTagSize
146170 first := pos
147171 posH := pos
@@ -166,6 +190,9 @@ type PackMapStrInt64 map[string]int64
166190
167191// ValueSize returns the size of the packed map's content.
168192func (p PackMapStrInt64 ) ValueSize () int {
193+ if len (p ) == 0 {
194+ return 0
195+ }
169196 size := 0
170197 for k := range p {
171198 size += len (k )
@@ -181,6 +208,9 @@ func (p PackMapStrInt64) HeaderType() typetags.Type {
181208
182209// Write packs the map into a byte buffer. This version does not sort keys.
183210func (p PackMapStrInt64 ) Write (buf []byte , pos int ) int {
211+ if len (p ) == 0 {
212+ return pos
213+ }
184214 headerSize := len (p )* 2 * access .HeaderTagSize + access .HeaderTagSize
185215 first := pos
186216 posH := pos
@@ -231,6 +261,9 @@ func (p *PackableMapOrdered) Set(key string, val access.Packable) {
231261
232262// ValueSize returns the size of the packed map's content.
233263func (p * PackableMapOrdered ) ValueSize () int {
264+ if len (p .om .Keys ()) == 0 {
265+ return 0
266+ }
234267 size := 0
235268 for k , v := range p .om .ItemsIter () {
236269 size += len (k ) + v .ValueSize ()
@@ -245,6 +278,9 @@ func (p *PackableMapOrdered) HeaderType() typetags.Type {
245278
246279// Write packs the map into a byte buffer in insertion order.
247280func (p * PackableMapOrdered ) Write (buf []byte , pos int ) int {
281+ if len (p .om .Keys ()) == 0 {
282+ return pos
283+ }
248284 headerSize := len (p .om .Keys ())* 2 * access .HeaderTagSize + access .HeaderTagSize
249285 first := pos
250286 posH := pos
@@ -292,6 +328,24 @@ func (pack PackMapStr) PackInto(p *access.PutAccess) {
292328 bPool .Release (buffer )
293329}
294330
331+ func (pack PackMapStrInt32 ) PackInto (p * access.PutAccess ) {
332+ size := pack .ValueSize ()
333+ buffer := bPool .Acquire (size )
334+ pos := 0
335+ pos = pack .Write (buffer , pos )
336+ p .AppendTagAndValue (typetags .TypeMap , buffer [:pos ])
337+ bPool .Release (buffer )
338+ }
339+
340+ func (pack PackMapStrInt64 ) PackInto (p * access.PutAccess ) {
341+ size := pack .ValueSize ()
342+ buffer := bPool .Acquire (size )
343+ pos := 0
344+ pos = pack .Write (buffer , pos )
345+ p .AppendTagAndValue (typetags .TypeMap , buffer [:pos ])
346+ bPool .Release (buffer )
347+ }
348+
295349// PackInto packs the ordered map into the PutAccess buffer.
296350func (pack * PackableMapOrdered ) PackInto (p * access.PutAccess ) {
297351 size := pack .ValueSize ()
0 commit comments