Skip to main content

decode_frame

Function decode_frame 

Source
pub fn decode_frame(bytes: &[u8]) -> Result<Frame<'_>>
Expand description

Decodes one Noise transport plaintext into a Frame.

The first byte of a plaintext is its binary message id: id BINARY_MESSAGE_ID_JSON introduces a UTF-8 JSON body and every other id introduces a binary body. Cleartext handshake messages do not travel through Noise, carry no id byte and are JSON text the caller parses directly; this function never sees them.

Fragment frames (id BINARY_MESSAGE_ID_FRAGMENT) are classified like any other binary message, with the payload starting at the flags byte. A session hands the plaintexts themselves to a Reassembler, which needs the id byte of each fragment, and decodes only the message the reassembler completes.

ยงErrors

Returns an error for an empty plaintext, which is always a protocol error, and for a JSON body that is not valid UTF-8.