============================================================================ 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)
| 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 |
| 30 | func 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 | |
| 71 | func readTypedMapSize(ctx *ReadContext) (int, bool) { |
| 72 | size := ctx.ReadCollectionLength() |
no test coverage detected