Skip to main content

encode

Function encode 

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

Frames the compact envelope JSON json (§5.1).

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 (§5.1); 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.

§Errors

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