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

Function writeMapIntInt

go/fory/map_primitive.go:732–767  ·  view source on GitHub ↗

writeMapIntInt writes map[int]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[int]int, hasGenerics bool)

Source from the content-addressed store, hash-verified

730// writeMapIntInt writes map[int]int using chunk protocol
731// When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info
732func writeMapIntInt(buf *ByteBuffer, m map[int]int, hasGenerics bool) {
733 length := len(m)
734 buf.WriteVarUint32(uint32(length))
735 if length == 0 {
736 return
737 }
738
739 remaining := length
740 for remaining > 0 {
741 chunkSize := remaining
742 if chunkSize > MAX_CHUNK_SIZE {
743 chunkSize = MAX_CHUNK_SIZE
744 }
745
746 if hasGenerics {
747 buf.WriteUint8(KEY_DECL_TYPE | VALUE_DECL_TYPE)
748 buf.WriteUint8(uint8(chunkSize))
749 } else {
750 buf.WriteUint8(0)
751 buf.WriteUint8(uint8(chunkSize))
752 buf.WriteUint8(uint8(VARINT64)) // key type (int serialized as varint64)
753 buf.WriteUint8(uint8(VARINT64)) // value type
754 }
755
756 count := 0
757 for k, v := range m {
758 buf.WriteVarint64(int64(k))
759 buf.WriteVarint64(int64(v))
760 count++
761 if count >= chunkSize {
762 break
763 }
764 }
765 remaining -= chunkSize
766 }
767}
768
769// readMapIntInt reads map[int]int using chunk protocol
770func readMapIntInt(ctx *ReadContext) map[int]int {

Callers 4

SerializeFunction · 0.85
WriteDataMethod · 0.85
WriteMethod · 0.85
WriteIntIntMapMethod · 0.85

Calls 6

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

Tested by

no test coverage detected