| 632 | } |
| 633 | |
| 634 | bool scanTable(char * dst, TypeInfo * ti) { |
| 635 | if (!ti->firstType || !ti->secondType) return skipValue(); |
| 636 | if (!expect('{')) return false; |
| 637 | Table * tab = (Table*)dst; |
| 638 | uint32_t valueTypeSize = ti->secondType->size; |
| 639 | // clear existing content |
| 640 | if (tab->size) { |
| 641 | table_clear(ctx, *tab, at); |
| 642 | } |
| 643 | if (peek() == '}') { cur++; return true; } |
| 644 | while (true) { |
| 645 | // read key as string (JSON keys are always strings) |
| 646 | string keyStr; |
| 647 | if (!readString(keyStr)) return false; |
| 648 | if (!expect(':')) return false; |
| 649 | // insert key into table based on key type |
| 650 | int64_t index = -1; |
| 651 | bool keyOk = true; |
| 652 | switch (ti->firstType->type) { |
| 653 | // string key |
| 654 | case Type::tString: { |
| 655 | char * key = ctx.allocateString(keyStr, at); |
| 656 | index = tableReserve<char*>(tab, key, valueTypeSize); |
| 657 | break; |
| 658 | } |
| 659 | // integer key types — parse from string |
| 660 | case Type::tBool: { |
| 661 | bool key = keyStr == "true"; |
| 662 | index = tableReserve<bool>(tab, key, valueTypeSize); |
| 663 | break; |
| 664 | } |
| 665 | case Type::tInt8: { |
| 666 | int8_t key = int8_t(atoll(keyStr.c_str())); |
| 667 | index = tableReserve<int8_t>(tab, key, valueTypeSize); |
| 668 | break; |
| 669 | } |
| 670 | case Type::tUInt8: { |
| 671 | uint8_t key = uint8_t(strtoull(keyStr.c_str(), nullptr, 10)); |
| 672 | index = tableReserve<uint8_t>(tab, key, valueTypeSize); |
| 673 | break; |
| 674 | } |
| 675 | case Type::tInt16: { |
| 676 | int16_t key = int16_t(atoll(keyStr.c_str())); |
| 677 | index = tableReserve<int16_t>(tab, key, valueTypeSize); |
| 678 | break; |
| 679 | } |
| 680 | case Type::tUInt16: { |
| 681 | uint16_t key = uint16_t(strtoull(keyStr.c_str(), nullptr, 10)); |
| 682 | index = tableReserve<uint16_t>(tab, key, valueTypeSize); |
| 683 | break; |
| 684 | } |
| 685 | case Type::tInt: { |
| 686 | int32_t key = int32_t(atoll(keyStr.c_str())); |
| 687 | index = tableReserve<int32_t>(tab, key, valueTypeSize); |
| 688 | break; |
| 689 | } |
| 690 | case Type::tUInt: |
| 691 | case Type::tBitfield: { |
nothing calls this directly
no test coverage detected