Repository navigation
Closed
Labels
enhancementA request for a new feature or improvement.help wantedThe issue requires extra attention or help from others.needs testingIssues that require additional testing or verification.
Description
Motivation
The byte cursor API provides fixed-width integer reads and writes and advances the cursor only after an operation succeeds. Add a bounded variable-length unsigned integer codec using the same caller-owned storage and error conventions.
Code references:
- std/bytes/cursor.wave — ByteReader and ByteWriter operations
- std/bytes/errors.wave — existing byte-operation error codes
Scope
Add unsigned 64-bit ULEB128 reading and writing, preferably in a focused std/bytes/leb128.wave module. Follow the existing cursor API shape: a reader plus an output pointer for decoding, and a writer plus a u64 value for encoding, returning an i32 status.
Suggested names are bytes_reader_read_uleb128_u64 and bytes_writer_write_uleb128_u64.
The contract is:
- Encode seven payload bits per byte, least-significant group first, with bit 7 indicating continuation. Writers emit the shortest representation.
- Decode at most ten bytes. In the tenth byte, only payload bit 0 may be set and continuation must be clear.
- Accept terminating non-minimal representations within that ten-byte bound, such as
80 00for zero; document this separately from canonical writer output. - Return
BYTES_ERROR_EOFwhen input ends before termination within the permitted length, andBYTES_ERROR_OVERFLOWwhen the encoding cannot represent au64or would require more than ten bytes. Validate the tenth byte before shifting. - Preserve the reader position and output value on every read failure. Validate null pointers and cursor invariants using the existing invalid-input convention.
- Preflight the encoded length and available capacity before writing. Insufficient space returns
BYTES_ERROR_NO_SPACEwithout changing the writer position or any destination bytes.
Completion criteria
- Implement both operations without heap allocation, libc, or a new external dependency.
- Cover exact byte vectors for
0,127,128, every seven-bit length transition, andu64::MAX. - Test truncated encodings, ten continuation bytes, a tenth-byte payload greater than one, valid non-minimal encodings, and decoding consecutive values from a nonzero cursor position.
- Assert unchanged cursor/output state for failed reads and unchanged cursor/buffer state for failed writes, including one-byte-short capacity.
- Test null output pointers and invalid reader/writer state without reading or writing out of bounds.
- Add runnable standard-library regressions under
tests/cases/and a short API example documenting byte counts and error behavior. - Keep all existing fixed-width cursor behavior unchanged.
SLEB128, other integer widths, and WebAssembly-specific parsing are separate extensions.
Metadata
Metadata
Assignees
Labels
enhancementA request for a new feature or improvement.help wantedThe issue requires extra attention or help from others.needs testingIssues that require additional testing or verification.
Activity
Fix typed codegen and expand portable std capabilities (#701)