[−][src]Struct framed::bytes::Codec
Contains methods for encoding and decoding byte slices with a specific configuration.
Construct an instance from a Config
instance with the
Config::to_codec
method.
Methods
impl Codec
[src]
pub fn encode_to_slice(
&mut self,
p: &Payload,
dest: &mut Encoded
) -> Result<usize>
[src]
&mut self,
p: &Payload,
dest: &mut Encoded
) -> Result<usize>
Encode the supplied payload data as a frame at the beginning of
the supplied buffer dest
. Available from no_std
crates.
Returns the number of bytes it has written to the buffer.
Panics
This function will panic if dest
is not large enough for the encoded frame.
Ensure dest.len() >= max_encoded_len(p.len())
.
pub fn encode_to_box(&mut self, p: &Payload) -> Result<BoxEncoded>
[src]
Encode the supplied payload data as a frame and return it on the heap.
pub fn encode_to_writer<W: Write>(
&mut self,
p: &Payload,
w: &mut W
) -> Result<usize>
[src]
&mut self,
p: &Payload,
w: &mut W
) -> Result<usize>
Encode the supplied payload data as a frame and write it to the
supplied Write
.
This function will not call flush
on the writer; the caller must do
so if this is required.
Returns the length of the frame it has written.
pub fn decode_to_slice(&mut self, e: &Encoded, dest: &mut [u8]) -> Result<usize>
[src]
Decode the supplied encoded frame, placing the payload at the
beginning of the supplied buffer dest
. Available from no_std
crates.
When reading from a stream, the caller can continue reading data
and buffering it until a FRAME_END_SYMBOL
is read, then pass the
whole buffer including FRAME_END_SYMBOL
to this function for
decoding.
If there is more than 1 FRAME_END_SYMBOL within e
, the result
is undefined. Make sure you only pass 1 frame at a time.
Returns the length of the payload it has decoded.
Errors
Returns Err(Error::EofDuringFrame
) if e
contains >= 1 bytes of
a frame, but not a complete frame. A complete frame should have
FRAME_END_SYMBOL
as the last byte.
Returns Err(Error::EofBeforeFrame
) if e.len()
is 0.
Panics
This function will panic if dest
is not large enough for the decoded frame.
Ensure dest.len() >= e.len()
.
pub fn decode_to_box(&mut self, e: &Encoded) -> Result<BoxPayload>
[src]
Decode the supplied encoded frame, returning the payload on the heap.
pub fn decode_from_reader<R: Read>(
&mut self,
r: &mut dyn Read
) -> Result<BoxPayload>
[src]
&mut self,
r: &mut dyn Read
) -> Result<BoxPayload>
Reads bytes from the supplied Read
until it has a complete
encoded frame, then decodes the frame, returning the payload on the heap.
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,