Framed By
Marks a @ProtocolMessage class (typically a sealed parent) with a framing length prefix that is computed from — and bounds — the body's wire size.
The framework owns framing: the encode path emits the prefix carrying the encoded body's byte count, the decode path reads the prefix, narrows buffer.limit() to bound the body, and asserts strict consumption. @FramedBy is structural and handles both fixed-size and variable-size bodies uniformly.
Sealed-parent composition: when applied to a @ProtocolMessage sealed parent, every variant inherits the framing rule. There is no per-variant override — protocols whose framing varies by variant are out of scope for this annotation. Validator enforces that every variant of a @FramedBy parent has the named after field as a FixedSize discriminator.
Parameters
A KClass referencing a Kotlin object that implements BoundingLengthCodec<UInt>. The codec drives prefix wire format (var-byte-int, fixed-width, etc.) and provides maxWireSize so the emitter can size the slack region for the slicing scheme.
Names a sibling constructor field that the prefix sits immediately after on the wire. Empty (default) means the prefix is at offset 0. The named field must exist, have Exact wire width, and — when the class carries @PacketType — be the discriminator.
@ProtocolMessage
@FramedBy(MqttRemainingLengthCodec::class, after = "header")
sealed interface MqttPacket {
// Each variant declares its own header field; the framework writes
// the prefix between header and body, computed from body bytes.
}