pub struct Frame<T> { /* private fields */ }Expand description
Implementations§
Source§impl<T> Frame<T>
impl<T> Frame<T>
Sourcepub fn encoding_type(&self) -> u16
pub fn encoding_type(&self) -> u16
Returns the 16-bits encoding type of self. You may want to
convert this value to an EncodingType, which allows
for nice pattern matching.
§Examples
use minisofh::{EncodingType, Frame};
let frame = Frame::new(0xF500, &[] as &[u8]);
let encoding_type = EncodingType::new(frame.encoding_type());
assert_eq!(encoding_type, Some(EncodingType::Json));Sourcepub fn payload(&self) -> &T
pub fn payload(&self) -> &T
Returns an immutable reference to the payload of self, i.e.
without its header.
§Examples
use minisofh::Frame;
let frame = Frame::new(0x0, &[42u8] as &[u8]);
assert_eq!(frame.payload(), &[42]);Sourcepub fn payload_mut(&mut self) -> &mut T
pub fn payload_mut(&mut self) -> &mut T
Returns a mutable reference to the payload of self.
Sourcepub fn serialize<W>(&self, writer: &mut W) -> Result<usize>where
W: Write,
pub fn serialize<W>(&self, writer: &mut W) -> Result<usize>where
W: Write,
Serializes self to a Writer. This requires copying and thus is
potentially expensive.
§Examples
use minisofh::Frame;
// Message_Length:
// ~~~~~~~~~~~~~
// Encoding_Type: ~~~~~~~~~
// Message: ~~
let bytes = &[0u8, 0, 0, 7, 0x0, 0x0, 42] as &[u8];
let frame = Frame::<&[u8]>::deserialize(bytes).unwrap();
let buffer = &mut Vec::new();
frame.serialize(buffer).unwrap();
assert_eq!(&buffer[..], bytes);Source§impl<'a> Frame<&'a [u8]>
impl<'a> Frame<&'a [u8]>
Sourcepub fn deserialize(data: &'a [u8]) -> Result<Self, Error>
pub fn deserialize(data: &'a [u8]) -> Result<Self, Error>
Tries to deserialize a Frame from data. Returns an Err if
invalid. Zero-copy.
This function ignores trailing bytes that are not part of the message.
§Examples
use minisofh::Frame;
// Message_Length: ~~~~~~~~~~~
// Encoding_Type: ~~~~~~~~~
// Message: ~~
let frame = Frame::<&[u8]>::deserialize(&[0, 0, 0, 7, 0x0, 0x0, 42]).unwrap();
assert_eq!(frame.payload(), &[42]);Trait Implementations§
Source§impl<T> Encoder<Frame<T>> for TokioCodec
Available on crate feature utils-tokio-codec only.
impl<T> Encoder<Frame<T>> for TokioCodec
Available on crate feature
utils-tokio-codec only.impl<T: Copy> Copy for Frame<T>
impl<T: Eq> Eq for Frame<T>
impl<T> StructuralPartialEq for Frame<T>
Auto Trait Implementations§
impl<T> Freeze for Frame<T>where
T: Freeze,
impl<T> RefUnwindSafe for Frame<T>where
T: RefUnwindSafe,
impl<T> Send for Frame<T>where
T: Send,
impl<T> Sync for Frame<T>where
T: Sync,
impl<T> Unpin for Frame<T>where
T: Unpin,
impl<T> UnsafeUnpin for Frame<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Frame<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more