Files
Library/docs/agent-workflow/tasks/M-BINARY-02-03.md
T

36 lines
3.0 KiB
Markdown

# Binary Writer, Owning ByteBuffer, DecodeBudget, and Endian Codecs
Task ID: M-BINARY-02, M-BINARY-03
Phase: P1
Status: APPROVED
Contracts: C-01, C-02, C-04, C-07
## 1. Context and baseline
`include/Void/Binary/Reader.hpp` provides non-owning bounds-checked reading with native-endian defaults, while Binary lacks `Writer`, `ByteBuffer`, cumulative decode budgets, transaction/rollback helpers, strict bool/IEEE float codecs, and `kBinaryErrorDomain` codes.
## 2. Deliverables
- `src/Binary/module.cmake` updated to `INTERNAL_DEPS Functional Memory`; `tests/package/InstalledComponents.cmake` updated to pass `Memory Core` for `Binary`/`Foundation` component checks.
- New `include/Void/Binary/Budget.hpp`: `BinaryErrorCode`, `make_error`, `DecodeLimits`, `DecodeBudget` (overflow-safe cumulative field bytes and RAII `DepthGuard`).
- Extended `include/Void/Binary/Reader.hpp`: `kBinaryErrorDomain` codes, pre-consume endian check, `readLittle`/`readBig`, strict `readBool`, explicit `readF32`/`readF64` (IEEE binary32/64, no default endian), `checkpoint`/`rollback`/`Transaction`, `readBytesChecked`/`subreaderChecked`.
- New `include/Void/Binary/Writer.hpp`: non-owning mutable `Writer` with pre-write capacity checks, overlapping `memmove`-safe `writeBytes`, explicit-endian `write`/`writeLittle`/`writeBig`/`writeBool`/`writeF32`/`writeF64`/`writeString`, and `checkpoint`/`rollbackPosition`.
- New `include/Void/Binary/ByteBuffer.hpp`: PMR-backed bounded `ByteBuffer` (`max_bytes`, `0` ceiling for empty-only, self-aliasing `append`, `std::bad_alloc` -> `allocation_failed`, preserves committed bytes on failure) and zero-copy `FrozenBytes` via `freeze()`.
- Tests in `tests/standalone/Binary/{Reader,Writer,ByteBuffer}.cpp` and expanded `tests/package/Binary/main.cpp`.
## 3. Exact files and interfaces
- `src/Binary/module.cmake`, `tests/package/InstalledComponents.cmake`, `tests/package/Binary/main.cpp`
- `include/Void/Binary/{Budget,Reader,Writer,ByteBuffer}.hpp`
- `tests/standalone/Binary/{Reader,Writer,ByteBuffer}.cpp`
## 4. Edge cases
- Truncated or unsupported-endian operations leave cursor position and destination buffer untouched.
- `readBool` accepts only `0x00`/`0x01` without consuming invalid bytes; IEEE float width/IEC-559 checked via `static_assert`.
- Shared cumulative `DecodeBudget` enforces total bytes and depth across nested `subreaderChecked`.
- `ByteBuffer` with `BudgetResource` preserves previously written data on ceiling or OOM failure; `freeze()` preserves underlying pointer with zero copy.
## 5. Acceptance criteria
- `Reader*`, `Writer*`, `ByteBuffer*`, and `VoidInstalledComponentConsumers` pass under `-DVOID_WARNINGS_AS_ERRORS=ON`.
## 6. Verification commands
```sh
dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-p1-binary -G Ninja -DVOID_ENABLED_MODULES="Binary;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-p1-binary && /tmp/void-p1-binary/tests/VoidTests --filter "Reader*|Writer*|ByteBuffer*" && ctest --test-dir /tmp/void-p1-binary --output-on-failure --timeout 60'
```