writeMapStringInt writes map[string]int using chunk protocol When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info
(buf *ByteBuffer, m map[string]int, hasGenerics bool)
| 301 | // writeMapStringInt writes map[string]int using chunk protocol |
| 302 | // When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info |
| 303 | func writeMapStringInt(buf *ByteBuffer, m map[string]int, hasGenerics bool) { |
| 304 | length := len(m) |
| 305 | buf.WriteVarUint32(uint32(length)) |
| 306 | if length == 0 { |
| 307 | return |
| 308 | } |
| 309 | |
| 310 | remaining := length |
| 311 | for remaining > 0 { |
| 312 | chunkSize := remaining |
| 313 | if chunkSize > MAX_CHUNK_SIZE { |
| 314 | chunkSize = MAX_CHUNK_SIZE |
| 315 | } |
| 316 | |
| 317 | if hasGenerics { |
| 318 | buf.WriteUint8(KEY_DECL_TYPE | VALUE_DECL_TYPE) |
| 319 | buf.WriteUint8(uint8(chunkSize)) |
| 320 | } else { |
| 321 | buf.WriteUint8(0) |
| 322 | buf.WriteUint8(uint8(chunkSize)) |
| 323 | buf.WriteUint8(uint8(STRING)) // key type |
| 324 | buf.WriteUint8(uint8(VARINT64)) // value type (int serialized as varint64) |
| 325 | } |
| 326 | |
| 327 | count := 0 |
| 328 | for k, v := range m { |
| 329 | writeString(buf, k) |
| 330 | buf.WriteVarint64(int64(v)) |
| 331 | count++ |
| 332 | if count >= chunkSize { |
| 333 | break |
| 334 | } |
| 335 | } |
| 336 | remaining -= chunkSize |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | // readMapStringInt reads map[string]int using chunk protocol |
| 341 | func readMapStringInt(ctx *ReadContext) map[string]int { |
no test coverage detected