readMapStringInt reads map[string]int using chunk protocol
(ctx *ReadContext)
| 339 | |
| 340 | // readMapStringInt reads map[string]int using chunk protocol |
| 341 | func readMapStringInt(ctx *ReadContext) map[string]int { |
| 342 | err := ctx.Err() |
| 343 | buf := ctx.Buffer() |
| 344 | size, ok := readTypedMapSize(ctx) |
| 345 | result := make(map[string]int) |
| 346 | if !ok { |
| 347 | return result |
| 348 | } |
| 349 | result = make(map[string]int, size) |
| 350 | |
| 351 | for size > 0 { |
| 352 | chunkHeader := buf.ReadUint8(err) |
| 353 | if chunkHeader&(TRACKING_KEY_REF|KEY_HAS_NULL|TRACKING_VALUE_REF|VALUE_HAS_NULL) != 0 { |
| 354 | ctx.SetError(DeserializationError("typed map reader does not support ref/null chunks")) |
| 355 | return result |
| 356 | } |
| 357 | |
| 358 | chunkSize := int(buf.ReadUint8(err)) |
| 359 | if ctx.HasError() { |
| 360 | return result |
| 361 | } |
| 362 | if chunkSize == 0 || chunkSize > size { |
| 363 | ctx.SetError(DeserializationErrorf("invalid map chunk size %d for remaining length %d", chunkSize, size)) |
| 364 | return result |
| 365 | } |
| 366 | if (chunkHeader & KEY_DECL_TYPE) == 0 { |
| 367 | if !ctx.readExpectedTypeID(STRING) { |
| 368 | return result |
| 369 | } |
| 370 | } |
| 371 | if (chunkHeader & VALUE_DECL_TYPE) == 0 { |
| 372 | if !ctx.readExpectedTypeID(VARINT64) { |
| 373 | return result |
| 374 | } |
| 375 | } |
| 376 | for i := 0; i < chunkSize; i++ { |
| 377 | k := readString(buf, err) |
| 378 | v := buf.ReadVarint64(err) |
| 379 | result[k] = int(v) |
| 380 | size-- |
| 381 | } |
| 382 | } |
| 383 | return result |
| 384 | } |
| 385 | |
| 386 | // writeMapStringFloat64 writes map[string]float64 using chunk protocol |
| 387 | // When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info |
no test coverage detected