Skip to content

Function framing::encode

zaun_community_protocol::framing::encode · Function

pub fn encode(json: &str, budget: usize, frag_id: FragId) -> Result<EncodedFrame, EncodeError>

Frames the compact envelope JSON json.

budget is the per-message budget of the whole message text, prefix and header included, measured as written inside a JSON string (escaped_len): each message is cut by what it really costs, so text with few quotes fills a message. The host derives the budget from simplex_client::limits; this crate never depends on simplex-client. A frame that fits in one message is sent whole; otherwise it is split greedily at UTF-8 character boundaries. frag_id is used only when fragmenting.

EncodeError when the envelope is larger than max_frame, needs more than 32 fragments, or the budget is below MIN_BUDGET.

Full rustdoc page