| 556 | // ---- scan variant: {"fieldName":val} (single key) ---- |
| 557 | |
| 558 | bool scanVariant(char * dst, TypeInfo * ti) { |
| 559 | if (!expect('{')) return false; |
| 560 | if (peek() == '}') { cur++; return true; } |
| 561 | // read the single key |
| 562 | string key; |
| 563 | if (!readString(key)) return false; |
| 564 | if (!expect(':')) return false; |
| 565 | // find matching variant field |
| 566 | int fidx = -1; |
| 567 | for (uint32_t i = 0; i < ti->argCount; i++) { |
| 568 | if (ti->argNames[i] && key == ti->argNames[i]) { |
| 569 | fidx = int(i); |
| 570 | break; |
| 571 | } |
| 572 | } |
| 573 | if (fidx >= 0) { |
| 574 | // set variant index |
| 575 | *(int32_t*)dst = fidx; |
| 576 | int offset = getVariantFieldOffset(ti, fidx); |
| 577 | if (!scanValue(dst + offset, ti->argTypes[fidx])) return false; |
| 578 | } else { |
| 579 | if (!skipValue()) return false; |
| 580 | } |
| 581 | // consume remaining entries (should be just the closing brace) |
| 582 | skipWS(); |
| 583 | if (cur < end && *cur == ',') { |
| 584 | cur++; |
| 585 | // skip any extra key-value pairs |
| 586 | while (true) { |
| 587 | if (!skipString()) return false; |
| 588 | if (!expect(':')) return false; |
| 589 | if (!skipValue()) return false; |
| 590 | skipWS(); |
| 591 | if (cur >= end) return false; |
| 592 | if (*cur == '}') { cur++; return true; } |
| 593 | if (*cur != ',') return false; |
| 594 | cur++; |
| 595 | } |
| 596 | } |
| 597 | if (!expect('}')) return false; |
| 598 | return true; |
| 599 | } |
| 600 | |
| 601 | // ---- scan table: {"key":val, ...} ---- |
| 602 |
nothing calls this directly
no test coverage detected