| ... | ... | @@ -1303,6 +1303,13 @@ fn takeMultipleOf7Leb128(r: *Reader, comptime Result: type) TakeLeb128Error!Resu |
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | /// Left-aligns data such that `r.seek` becomes zero. |
| 1306 | /// |
| 1307 | /// If `r.seek` is not already zero then `buffer` is mutated, making it illegal |
| 1308 | /// to call this function with a const-casted `buffer`, such as in the case of |
| 1309 | /// `fixed`. This issue can be avoided: |
| 1310 | /// * in implementations, by attempting a read before a rebase, in which |
| 1311 | /// case the read will return `error.EndOfStream`, preventing the rebase. |
| 1312 | /// * in usage, by copying into a mutable buffer before initializing `fixed`. |
| 1306 | 1313 | pub fn rebase(r: *Reader) void { |
| 1307 | 1314 | if (r.seek == 0) return; |
| 1308 | 1315 | const data = r.buffer[r.seek..r.end]; |
| ... | ... | @@ -1315,6 +1322,13 @@ pub fn rebase(r: *Reader) void { |
| 1315 | 1322 | /// if necessary. |
| 1316 | 1323 | /// |
| 1317 | 1324 | /// Asserts `capacity` is within the buffer capacity. |
| 1325 | /// |
| 1326 | /// If the rebase occurs then `buffer` is mutated, making it illegal to call |
| 1327 | /// this function with a const-casted `buffer`, such as in the case of `fixed`. |
| 1328 | /// This issue can be avoided: |
| 1329 | /// * in implementations, by attempting a read before a rebase, in which |
| 1330 | /// case the read will return `error.EndOfStream`, preventing the rebase. |
| 1331 | /// * in usage, by copying into a mutable buffer before initializing `fixed`. |
| 1318 | 1332 | pub fn rebaseCapacity(r: *Reader, capacity: usize) void { |
| 1319 | 1333 | if (r.end > r.buffer.len - capacity) rebase(r); |
| 1320 | 1334 | } |