Skip to main content

format_data_frames

Function format_data_frames 

Source
pub fn format_data_frames(
    messages: &[Bytes],
    is_binary: bool,
    is_json: bool,
) -> String
Expand description

Format event: data SSE frames for a batch of messages from a single read.

For JSON streams, all messages are batched into a single event: data frame containing one JSON array — maintaining the 1:1 data-to-control relationship the spec requires (PROTOCOL.md §5.8). Without batching, the client would concatenate separate [...][...] arrays, producing invalid JSON.

For binary/text streams, each message gets its own event: data frame.

Returns an empty string if messages is empty.