Skip to main content

encode_chunk_frame

Function encode_chunk_frame 

Source
pub fn encode_chunk_frame(
    payload: &[u8],
) -> Result<Vec<u8>, MessageValidationError>
Expand description

Encode one ClientMessage::ChunkData frame body directly from its payload.

Byte-identical to encode_message(&ClientMessage::ChunkData(ChunkData::new(payload)?)) — pinned by encode_chunk_frame_matches_the_generic_encoder — but it copies the payload once instead of twice. The generic path owns the bytes to build the frame (Vec<u8>) and postcard copies them again into its output buffer.

This is the single-buffer door, for callers that need the whole frame as one Vec<u8>. The serve paths do not use it: they encode headers only (encode_chunk_frame_headers) and send the payload uncopied beside them.

The non-empty floor is checked here rather than inherited from ChunkData::new, since no ChunkData is built. That keeps the ADR 005 §Non-empty chunk invariant true of every frame this crate can emit, by either door.

§Errors

MessageValidationError::EmptyChunk for a zero-length payload, or MessageValidationError::ChunkTooLarge if the frame would exceed crate::framing::MAX_MESSAGE_SIZE.