readMapStringString reads map[string]string using chunk protocol
(ctx *ReadContext)
| 81 | |
| 82 | // readMapStringString reads map[string]string using chunk protocol |
| 83 | func readMapStringString(ctx *ReadContext) map[string]string { |
| 84 | err := ctx.Err() |
| 85 | buf := ctx.Buffer() |
| 86 | size, ok := readTypedMapSize(ctx) |
| 87 | result := make(map[string]string) |
| 88 | if !ok { |
| 89 | return result |
| 90 | } |
| 91 | result = make(map[string]string, size) |
| 92 | |
| 93 | for size > 0 { |
| 94 | chunkHeader := buf.ReadUint8(err) |
| 95 | |
| 96 | if chunkHeader&(TRACKING_KEY_REF|KEY_HAS_NULL|TRACKING_VALUE_REF|VALUE_HAS_NULL) != 0 { |
| 97 | ctx.SetError(DeserializationError("typed map reader does not support ref/null chunks")) |
| 98 | return result |
| 99 | } |
| 100 | |
| 101 | chunkSize := int(buf.ReadUint8(err)) |
| 102 | if ctx.HasError() { |
| 103 | return result |
| 104 | } |
| 105 | if chunkSize == 0 || chunkSize > size { |
| 106 | ctx.SetError(DeserializationErrorf("invalid map chunk size %d for remaining length %d", chunkSize, size)) |
| 107 | return result |
| 108 | } |
| 109 | |
| 110 | if (chunkHeader & KEY_DECL_TYPE) == 0 { |
| 111 | if !ctx.readExpectedTypeID(STRING) { |
| 112 | return result |
| 113 | } |
| 114 | } |
| 115 | if (chunkHeader & VALUE_DECL_TYPE) == 0 { |
| 116 | if !ctx.readExpectedTypeID(STRING) { |
| 117 | return result |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | for i := 0; i < chunkSize; i++ { |
| 122 | k := readString(buf, err) |
| 123 | v := readString(buf, err) |
| 124 | result[k] = v |
| 125 | size-- |
| 126 | } |
| 127 | } |
| 128 | return result |
| 129 | } |
| 130 | |
| 131 | // writeMapStringInt64 writes map[string]int64 using chunk protocol |
| 132 | // When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info |
no test coverage detected