readMapStringBool reads map[string]bool using chunk protocol
(ctx *ReadContext)
| 509 | |
| 510 | // readMapStringBool reads map[string]bool using chunk protocol |
| 511 | func readMapStringBool(ctx *ReadContext) map[string]bool { |
| 512 | err := ctx.Err() |
| 513 | buf := ctx.Buffer() |
| 514 | size, ok := readTypedMapSize(ctx) |
| 515 | result := make(map[string]bool) |
| 516 | if !ok { |
| 517 | return result |
| 518 | } |
| 519 | result = make(map[string]bool, size) |
| 520 | |
| 521 | for size > 0 { |
| 522 | chunkHeader := buf.ReadUint8(err) |
| 523 | if chunkHeader&(TRACKING_KEY_REF|KEY_HAS_NULL|TRACKING_VALUE_REF|VALUE_HAS_NULL) != 0 { |
| 524 | ctx.SetError(DeserializationError("typed map reader does not support ref/null chunks")) |
| 525 | return result |
| 526 | } |
| 527 | |
| 528 | chunkSize := int(buf.ReadUint8(err)) |
| 529 | if ctx.HasError() { |
| 530 | return result |
| 531 | } |
| 532 | if chunkSize == 0 || chunkSize > size { |
| 533 | ctx.SetError(DeserializationErrorf("invalid map chunk size %d for remaining length %d", chunkSize, size)) |
| 534 | return result |
| 535 | } |
| 536 | |
| 537 | keyDeclType := (chunkHeader & KEY_DECL_TYPE) != 0 |
| 538 | valDeclType := (chunkHeader & VALUE_DECL_TYPE) != 0 |
| 539 | if !keyDeclType { |
| 540 | if !ctx.readExpectedTypeID(STRING) { |
| 541 | return result |
| 542 | } |
| 543 | } |
| 544 | if !valDeclType { |
| 545 | if !ctx.readExpectedTypeID(BOOL) { |
| 546 | return result |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | for i := 0; i < chunkSize; i++ { |
| 551 | k := readString(buf, err) |
| 552 | v := buf.ReadBool(err) |
| 553 | result[k] = v |
| 554 | size-- |
| 555 | } |
| 556 | } |
| 557 | return result |
| 558 | } |
| 559 | |
| 560 | // writeMapInt32Int32 writes map[int32]int32 using chunk protocol |
| 561 | // When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info |
no test coverage detected