MCPcopy Create free account
hub / github.com/apache/fory / writeMapStringInt

Function writeMapStringInt

go/fory/map_primitive.go:303–338  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
303func 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
341func readMapStringInt(ctx *ReadContext) map[string]int {

Callers 4

SerializeFunction · 0.85
WriteDataMethod · 0.85
WriteMethod · 0.85
WriteStringIntMapMethod · 0.85

Calls 7

writeStringFunction · 0.85
WriteUint8Method · 0.80
uint32Function · 0.50
uint8Function · 0.50
int64Function · 0.50
WriteVarUint32Method · 0.45
WriteVarint64Method · 0.45

Tested by

no test coverage detected