* Sets the length of either a RIFF object or the number of items in an array. * This lets us load an object or an array of arbitrary size * @param length The length of the sought object/array */
| 729 | * @param length The length of the sought object/array |
| 730 | */ |
| 731 | void SlSetLength(size_t length) |
| 732 | { |
| 733 | assert(_sl.action == SLA_SAVE); |
| 734 | |
| 735 | switch (_sl.need_length) { |
| 736 | case NL_WANTLENGTH: |
| 737 | _sl.need_length = NL_NONE; |
| 738 | if ((_sl.block_mode == CH_TABLE || _sl.block_mode == CH_SPARSE_TABLE) && _sl.expect_table_header) { |
| 739 | _sl.expect_table_header = false; |
| 740 | SlWriteArrayLength(length + 1); |
| 741 | break; |
| 742 | } |
| 743 | |
| 744 | switch (_sl.block_mode) { |
| 745 | case CH_RIFF: |
| 746 | /* Ugly encoding of >16M RIFF chunks |
| 747 | * The lower 24 bits are normal |
| 748 | * The uppermost 4 bits are bits 24:27 */ |
| 749 | assert(length < (1 << 28)); |
| 750 | SlWriteUint32((uint32_t)((length & 0xFFFFFF) | ((length >> 24) << 28))); |
| 751 | break; |
| 752 | case CH_TABLE: |
| 753 | case CH_ARRAY: |
| 754 | assert(_sl.last_array_index <= _sl.array_index); |
| 755 | while (++_sl.last_array_index <= _sl.array_index) { |
| 756 | SlWriteArrayLength(1); |
| 757 | } |
| 758 | SlWriteArrayLength(length + 1); |
| 759 | break; |
| 760 | case CH_SPARSE_TABLE: |
| 761 | case CH_SPARSE_ARRAY: |
| 762 | SlWriteArrayLength(length + 1 + SlGetArrayLength(_sl.array_index)); // Also include length of sparse index. |
| 763 | SlWriteSparseIndex(_sl.array_index); |
| 764 | break; |
| 765 | default: NOT_REACHED(); |
| 766 | } |
| 767 | break; |
| 768 | |
| 769 | case NL_CALCLENGTH: |
| 770 | _sl.obj_len += (int)length; |
| 771 | break; |
| 772 | |
| 773 | default: NOT_REACHED(); |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * Save/Load bytes. These do not need to be converted to Little/Big Endian |
no test coverage detected