Framed Encoder
Runtime entry point for the @FramedBy slicing-scheme encode emit. The KSP-generated @FramedBy codec calls encode, which:
Allocates a GrowableWriteBuffer with a slack region at the front sized to fit the worst-case header bytes plus the worst-case framing prefix.
Positions the growable past the slack region and invokes writeBody to write the body fields into the buffer.
Computes
bodyBytes = position - maxSlackand asks framingCodec for the actual prefix width viawireSize(bodyBytes, context).asExact.Right-flushes the prefix (and optional header) into the slack region so the wire bytes lie contiguously:
[header?][prefix][body].Returns a ReadBuffer slice spanning exactly those wire bytes.
Body bytes are never moved — the slicing scheme leaves them at offset maxSlack and writes the prefix backwards into the slack instead. This is what makes the emit zero-memcpy for the body content (the design's headline property).
For a class with @FramedBy(codec, after = ""), headerWireWidth is 0 and writeHeader is null. For after = "X", headerWireWidth is the Exact wire width of X and writeHeader writes that field into the supplied buffer (the framework owns the header write so the gap between header and prefix is zero — eliminating the 1-byte memmove that an "in-variant header write" would otherwise require).