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

Function writeMapStringString

go/fory/map_primitive.go:30–69  ·  view source on GitHub ↗

============================================================================ Optimized map serializers for common types ============================================================================ writeMapStringString writes map[string]string using chunk protocol When hasGenerics=true, element types

(buf *ByteBuffer, m map[string]string, hasGenerics bool)

Source from the content-addressed store, hash-verified

28// writeMapStringString writes map[string]string using chunk protocol
29// When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info
30func writeMapStringString(buf *ByteBuffer, m map[string]string, hasGenerics bool) {
31 length := len(m)
32 buf.WriteVarUint32(uint32(length))
33 if length == 0 {
34 return
35 }
36
37 // WriteData chunks of entries
38 remaining := length
39 for remaining > 0 {
40 chunkSize := remaining
41 if chunkSize > MAX_CHUNK_SIZE {
42 chunkSize = MAX_CHUNK_SIZE
43 }
44
45 if hasGenerics {
46 // Element types are known from generics, set DECL_TYPE flags
47 buf.WriteUint8(KEY_DECL_TYPE | VALUE_DECL_TYPE)
48 buf.WriteUint8(uint8(chunkSize))
49 } else {
50 // Write type info for generic reader compatibility
51 buf.WriteUint8(0)
52 buf.WriteUint8(uint8(chunkSize))
53 buf.WriteUint8(uint8(STRING)) // key type
54 buf.WriteUint8(uint8(STRING)) // value type
55 }
56
57 // WriteData chunk entries
58 count := 0
59 for k, v := range m {
60 writeString(buf, k)
61 writeString(buf, v)
62 count++
63 if count >= chunkSize {
64 break
65 }
66 }
67 remaining -= chunkSize
68 }
69}
70
71func readTypedMapSize(ctx *ReadContext) (int, bool) {
72 size := ctx.ReadCollectionLength()

Callers 4

SerializeFunction · 0.85
WriteDataMethod · 0.85
WriteMethod · 0.85
WriteStringStringMapMethod · 0.85

Calls 5

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

Tested by

no test coverage detected