encodeToRadio

fun encodeToRadio(message: ToRadio): ByteArray(source)

Encode a ToRadio into a framed byte array ready for transmission.

This is a wire-layer check — it validates the total serialized envelope size, not the application payload. Application-layer payload size (max DATA_PAYLOAD_LEN bytes) must be enforced by callers before building the ToRadio envelope.

Return

the framed payload (includes 4-byte header)

Parameters

message

the outbound envelope

Throws

if the serialized envelope exceeds MAX_FRAME_SIZE bytes, or if serialization fails. Envelope-overflow is a protocol-layer error (the caller constructed a malformed wire frame, which is distinct from exceeding the application payload limit — that's MeshtasticException.PayloadTooLarge, enforced at RadioClient.send).