On this page

0083. Codec wire rules and vec.to_bytes

Context

Codec generators need deterministic wire rules and a way to construct arbitrary bytes. String literals cannot construct a byte >= 0x80; existing bytes operations only expose, slice or concatenate bytes that already exist.

Decision

Add the kernel method vec<u8>.to_bytes() -> bytes. It copies every element into fresh storage in O(n), including NULs, high bytes and empty inputs. It performs no UTF-8 validation. Other element types retain the existing method-not-found error. The IR intrinsic has class Fresh, uses ordinary destination/region placement and charges its byte buffer to the interpreter sandbox heap budget. The C helper is feature-gated and enabled only when the intrinsic occurs in emitted functions; programs without it retain byte-identical emitted C.

M9.6's path-dependent codec package will implement these wire rules:

Alternatives considered

Consequences

Binary output and Unicode escape decoding become expressible in Harness. The primitive adds no diagnostic code or dependency. Step 6.1 documents the method in the vector reference; M9.5 Step 5.8 owns the LANGUAGE.md budget move. Later M9.6 steps implement and test the codec rules. IDs 0081/0082 remain reserved by ADR-0078.