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

Function writeMapStringInt32

go/fory/map_primitive.go:218–253  ·  view source on GitHub ↗

writeMapStringInt32 writes map[string]int32 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]int32, hasGenerics bool)

Source from the content-addressed store, hash-verified

216// writeMapStringInt32 writes map[string]int32 using chunk protocol
217// When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info
218func writeMapStringInt32(buf *ByteBuffer, m map[string]int32, hasGenerics bool) {
219 length := len(m)
220 buf.WriteVarUint32(uint32(length))
221 if length == 0 {
222 return
223 }
224
225 remaining := length
226 for remaining > 0 {
227 chunkSize := remaining
228 if chunkSize > MAX_CHUNK_SIZE {
229 chunkSize = MAX_CHUNK_SIZE
230 }
231
232 if hasGenerics {
233 buf.WriteUint8(KEY_DECL_TYPE | VALUE_DECL_TYPE)
234 buf.WriteUint8(uint8(chunkSize))
235 } else {
236 buf.WriteUint8(0)
237 buf.WriteUint8(uint8(chunkSize))
238 buf.WriteUint8(uint8(STRING)) // key type
239 buf.WriteUint8(uint8(VARINT32)) // value type
240 }
241
242 count := 0
243 for k, v := range m {
244 writeString(buf, k)
245 buf.WriteVarint32(v)
246 count++
247 if count >= chunkSize {
248 break
249 }
250 }
251 remaining -= chunkSize
252 }
253}
254
255// readMapStringInt32 reads map[string]int32 using chunk protocol
256func readMapStringInt32(ctx *ReadContext) map[string]int32 {

Callers 2

SerializeFunction · 0.85
WriteStringInt32MapMethod · 0.85

Calls 6

writeStringFunction · 0.85
WriteUint8Method · 0.80
uint32Function · 0.50
uint8Function · 0.50
WriteVarUint32Method · 0.45
WriteVarint32Method · 0.45

Tested by

no test coverage detected