Skip to main content

split_binary

Function split_binary 

Source
pub fn split_binary(
    id: u8,
    payload: &[u8],
    max_plaintext: usize,
) -> Vec<Vec<u8>>
Expand description

Splits a binary message into plaintext frames that each fit max_plaintext.

A message that fits returns exactly one frame, [id][payload]; a larger one returns the fragments of message id BINARY_MESSAGE_ID_FRAGMENT, the first carrying the original id. Every fragment is at most max_plaintext bytes.

The payload is cut into equally sized chunks of max_plaintext - 3 bytes, the capacity of a first fragment, so a continuation frame stays one byte below the limit.

ยงPanics

Panics when id is BINARY_MESSAGE_ID_FRAGMENT, or when max_plaintext is smaller than a first-fragment header plus one payload byte.