readMapStringInt32 reads map[string]int32 using chunk protocol
(ctx *ReadContext)
| 254 | |
| 255 | // readMapStringInt32 reads map[string]int32 using chunk protocol |
| 256 | func readMapStringInt32(ctx *ReadContext) map[string]int32 { |
| 257 | err := ctx.Err() |
| 258 | buf := ctx.Buffer() |
| 259 | size, ok := readTypedMapSize(ctx) |
| 260 | result := make(map[string]int32) |
| 261 | if !ok { |
| 262 | return result |
| 263 | } |
| 264 | result = make(map[string]int32, size) |
| 265 | |
| 266 | for size > 0 { |
| 267 | chunkHeader := buf.ReadUint8(err) |
| 268 | if chunkHeader&(TRACKING_KEY_REF|KEY_HAS_NULL|TRACKING_VALUE_REF|VALUE_HAS_NULL) != 0 { |
| 269 | ctx.SetError(DeserializationError("typed map reader does not support ref/null chunks")) |
| 270 | return result |
| 271 | } |
| 272 | |
| 273 | chunkSize := int(buf.ReadUint8(err)) |
| 274 | if ctx.HasError() { |
| 275 | return result |
| 276 | } |
| 277 | if chunkSize == 0 || chunkSize > size { |
| 278 | ctx.SetError(DeserializationErrorf("invalid map chunk size %d for remaining length %d", chunkSize, size)) |
| 279 | return result |
| 280 | } |
| 281 | if (chunkHeader & KEY_DECL_TYPE) == 0 { |
| 282 | if !ctx.readExpectedTypeID(STRING) { |
| 283 | return result |
| 284 | } |
| 285 | } |
| 286 | if (chunkHeader & VALUE_DECL_TYPE) == 0 { |
| 287 | if !ctx.readExpectedTypeID(VARINT32) { |
| 288 | return result |
| 289 | } |
| 290 | } |
| 291 | for i := 0; i < chunkSize; i++ { |
| 292 | k := readString(buf, err) |
| 293 | v := buf.ReadVarint32(err) |
| 294 | result[k] = v |
| 295 | size-- |
| 296 | } |
| 297 | } |
| 298 | return result |
| 299 | } |
| 300 | |
| 301 | // writeMapStringInt writes map[string]int using chunk protocol |
| 302 | // When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info |
no test coverage detected