3.0 KiB
3.0 KiB
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.cmakeupdated toINTERNAL_DEPS Functional Memory;tests/package/InstalledComponents.cmakeupdated to passMemory CoreforBinary/Foundationcomponent checks.- New
include/Void/Binary/Budget.hpp:BinaryErrorCode,make_error,DecodeLimits,DecodeBudget(overflow-safe cumulative field bytes and RAIIDepthGuard). - Extended
include/Void/Binary/Reader.hpp:kBinaryErrorDomaincodes, pre-consume endian check,readLittle/readBig, strictreadBool, explicitreadF32/readF64(IEEE binary32/64, no default endian),checkpoint/rollback/Transaction,readBytesChecked/subreaderChecked. - New
include/Void/Binary/Writer.hpp: non-owning mutableWriterwith pre-write capacity checks, overlappingmemmove-safewriteBytes, explicit-endianwrite/writeLittle/writeBig/writeBool/writeF32/writeF64/writeString, andcheckpoint/rollbackPosition. - New
include/Void/Binary/ByteBuffer.hpp: PMR-backed boundedByteBuffer(max_bytes,0ceiling for empty-only, self-aliasingappend,std::bad_alloc->allocation_failed, preserves committed bytes on failure) and zero-copyFrozenBytesviafreeze(). - Tests in
tests/standalone/Binary/{Reader,Writer,ByteBuffer}.cppand expandedtests/package/Binary/main.cpp.
3. Exact files and interfaces
src/Binary/module.cmake,tests/package/InstalledComponents.cmake,tests/package/Binary/main.cppinclude/Void/Binary/{Budget,Reader,Writer,ByteBuffer}.hpptests/standalone/Binary/{Reader,Writer,ByteBuffer}.cpp
4. Edge cases
- Truncated or unsupported-endian operations leave cursor position and destination buffer untouched.
readBoolaccepts only0x00/0x01without consuming invalid bytes; IEEE float width/IEC-559 checked viastatic_assert.- Shared cumulative
DecodeBudgetenforces total bytes and depth across nestedsubreaderChecked. ByteBufferwithBudgetResourcepreserves previously written data on ceiling or OOM failure;freeze()preserves underlying pointer with zero copy.
5. Acceptance criteria
Reader*,Writer*,ByteBuffer*, andVoidInstalledComponentConsumerspass under-DVOID_WARNINGS_AS_ERRORS=ON.
6. Verification commands
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'