# Function framing::encode

> Frames the compact envelope JSON `json`.

`zaun_community_protocol::framing::encode` · Function

```rust
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.

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

[Full rustdoc page](/docs/api/rust/zaun-community-protocol/zaun_community_protocol/framing/encode/fn.encode.html)
