|
| 1 | +meta: |
| 2 | + id: bite |
| 3 | + title: BITE-encoded file |
| 4 | + file-extension: bite |
| 5 | + endian: le |
| 6 | + bit-endian: le |
| 7 | +seq: |
| 8 | + - id: magic |
| 9 | + contents: 'BITE\0' |
| 10 | + - id: version |
| 11 | + type: u8 |
| 12 | + - id: strings |
| 13 | + type: string_table |
| 14 | + - id: payload |
| 15 | + type: payload |
| 16 | + repeat: eos |
| 17 | +enum: |
| 18 | + tag: |
| 19 | + false: 0 |
| 20 | + true: 1 |
| 21 | + none: 2 |
| 22 | + some: 3 |
| 23 | + int: 4 |
| 24 | + sint: 5 |
| 25 | + i8: 6 |
| 26 | + u8: 7 |
| 27 | + f32: 8 |
| 28 | + f64: 9 |
| 29 | + char: 10 |
| 30 | + bytes: 11 |
| 31 | + str: 12 |
| 32 | + seq: 13 |
| 33 | + map: 14 |
| 34 | + unit_variant: 15 |
| 35 | + newtype_variant: 16 |
| 36 | + struct_variant: 17 |
| 37 | + tuple_variant: 18 |
| 38 | +types: |
| 39 | + unit: |
| 40 | + seq: |
| 41 | + - id: empty |
| 42 | + size: 0 |
| 43 | + payload: |
| 44 | + doc: An encoded value tagged with its serde data type |
| 45 | + seq: |
| 46 | + - id: tag |
| 47 | + type: u8 |
| 48 | + enum: tag |
| 49 | + - id: value |
| 50 | + type: |
| 51 | + switch-on: tag |
| 52 | + cases: |
| 53 | + 'tag::false': unit |
| 54 | + 'tag::true': unit |
| 55 | + 'tag::none': unit |
| 56 | + 'tag::some': payload |
| 57 | + 'tag::int': varint |
| 58 | + 'tag::sint': varint |
| 59 | + 'tag::i8': u8 |
| 60 | + 'tag::u8': u8 |
| 61 | + 'tag::f32': f32 |
| 62 | + 'tag::f64': f64 |
| 63 | + 'tag::char': varint |
| 64 | + 'tag::bytes': payload_bytes |
| 65 | + 'tag::str': varint |
| 66 | + 'tag::seq': payload_seq |
| 67 | + 'tag::map': payload_map |
| 68 | + 'tag::unit_variant': unit |
| 69 | + 'tag::newtype_variant': payload |
| 70 | + 'tag::struct_variant': payload_variant |
| 71 | + 'tag::tuple_variant': payload_variant |
| 72 | + payload_variant: |
| 73 | + doc: A hint to the deserializer that a given enum variant is next in the stream |
| 74 | + seq: |
| 75 | + - id: variant_id |
| 76 | + type: varint |
| 77 | + payload_seq: |
| 78 | + seq: |
| 79 | + - id: num_elements |
| 80 | + type: varint |
| 81 | + - id: num_element_bytes |
| 82 | + type: varint |
| 83 | + if: num_elements.value > 0 |
| 84 | + doc: The number of subsequent bytes holding the encoded elements of this sequence |
| 85 | + - id: elements |
| 86 | + type: payload |
| 87 | + if: num_elements.value > 0 |
| 88 | + size: num_element_bytes.value |
| 89 | + repeat: expr |
| 90 | + repeat-expr: num_elements.value |
| 91 | + payload_map: |
| 92 | + seq: |
| 93 | + - id: num_elements |
| 94 | + type: varint |
| 95 | + - id: num_key_bytes |
| 96 | + type: varint |
| 97 | + if: num_elements.value > 0 |
| 98 | + doc: The number of subsequent bytes holding the encoded keys of this map |
| 99 | + - id: keys |
| 100 | + type: payload |
| 101 | + if: num_elements.value > 0 |
| 102 | + size: num_key_bytes.value |
| 103 | + repeat: expr |
| 104 | + repeat-expr: num_elements.value |
| 105 | + - id: num_value_bytes |
| 106 | + type: varint |
| 107 | + if: num_elements.value > 0 |
| 108 | + doc: The number of subsequent bytes holding the encoded values of this map |
| 109 | + - id: values |
| 110 | + type: payload |
| 111 | + if: num_elements.value > 0 |
| 112 | + size: num_value_bytes.value |
| 113 | + repeat: expr |
| 114 | + repeat-expr: num_elements.value |
| 115 | + payload_bytes: |
| 116 | + seq: |
| 117 | + - id: num_bytes |
| 118 | + type: varint |
| 119 | + - id: bytes |
| 120 | + size: num_bytes.value |
| 121 | + strings_table: |
| 122 | + doc: The interned strings table |
| 123 | + seq: |
| 124 | + - id: num_strings |
| 125 | + type: varint |
| 126 | + - id: string_entries |
| 127 | + type: string_entry |
| 128 | + repeat: expr |
| 129 | + repeat-expr: num_strings.value |
| 130 | + string_entry: |
| 131 | + doc: An entry in the interned string table |
| 132 | + seq: |
| 133 | + - id: string_len |
| 134 | + type: varint |
| 135 | + - id: string_data |
| 136 | + type: str |
| 137 | + size: string_len.value |
| 138 | + encoding: UTF-8 |
| 139 | + varint: |
| 140 | + doc: A variable-length encoded integer value |
| 141 | + seq: |
| 142 | + - id: varint_groups |
| 143 | + type: varint_group |
| 144 | + repeat: until |
| 145 | + repeat-until: not _.has_next |
| 146 | + instances: |
| 147 | + last: |
| 148 | + value: varint_groups.size - 1 |
| 149 | + value: |
| 150 | + value: >- |
| 151 | + groups[last].value |
| 152 | + + (last >= 1 ? (varint_groups[last - 1].value << 7) : 0) |
| 153 | + + (last >= 2 ? (varint_groups[last - 2].value << 14) : 0) |
| 154 | + + (last >= 3 ? (varint_groups[last - 3].value << 21) : 0) |
| 155 | + + (last >= 4 ? (varint_groups[last - 4].value << 28) : 0) |
| 156 | + + (last >= 5 ? (varint_groups[last - 5].value << 35) : 0) |
| 157 | + + (last >= 6 ? (varint_groups[last - 6].value << 42) : 0) |
| 158 | + + (last >= 7 ? (varint_groups[last - 7].value << 49) : 0) |
| 159 | + doc: Resulting value as normal integer |
| 160 | + varint_group: |
| 161 | + seq: |
| 162 | + - id: b |
| 163 | + type: u1 |
| 164 | + instances: |
| 165 | + has_next: |
| 166 | + value: (b & 0b1000_0000) != 0 |
| 167 | + doc: If true, then we have more bytes to read |
| 168 | + value: |
| 169 | + value: b & 0b0111_1111 |
| 170 | + doc: The 7-bit (base128) numeric value chunk of this group |
0 commit comments