pub trait Framing:
Send
+ Sync
+ 'static
+ Unpin {
// Required method
fn try_framing(
&mut self,
buffer: &[u8],
) -> Result<Option<FramingAdvanceResult>, FramingError>;
// Provided methods
fn advance(&mut self) { ... }
fn next_buffer_size(&self) -> Option<NonZeroUsize> { ... }
}Expand description
Splits data stream into frames. For example, for implmenting JSON-RPC over TCP, this would split the stream into JSON-RPC objects delimited by objects.
Required Methods§
Sourcefn try_framing(
&mut self,
buffer: &[u8],
) -> Result<Option<FramingAdvanceResult>, FramingError>
fn try_framing( &mut self, buffer: &[u8], ) -> Result<Option<FramingAdvanceResult>, FramingError>
Advance internal parsing status
§Returns
Ok(Some(Range))if a frame is found. Returns the range, represents(valid_data_end, next_frame_start)respectively.Ok(None)if a frame is not found. The buffer should be kept as-is, and the nextSelf::advancecall should be called with the same buffer, but extended with more data from the underlying transport.Err(...)if any error occurs during framing.
Provided Methods§
Sourcefn next_buffer_size(&self) -> Option<NonZeroUsize>
fn next_buffer_size(&self) -> Option<NonZeroUsize>
Returns hint for the next buffer size. This is used to pre-allocate the buffer for the
next Self::advance call.