pub struct StompCodec {}Expand description
StompCodec implements tokio_util::codec::{Decoder, Encoder} for the
STOMP wire protocol.
Responsibilities:
- Decode incoming bytes into
StompItem::FrameorStompItem::Heartbeat. - Support both NUL-terminated frames and frames using the
content-lengthheader (STOMP 1.2) for binary bodies containing NUL bytes. - Encode
StompItemback into bytes for the wire format and emitcontent-lengthwhen necessary.
Implementations§
Source§impl StompCodec
impl StompCodec
Trait Implementations§
Source§impl Decoder for StompCodec
impl Decoder for StompCodec
Source§fn decode(
&mut self,
src: &mut BytesMut,
) -> Result<Option<Self::Item>, Self::Error>
fn decode( &mut self, src: &mut BytesMut, ) -> Result<Option<Self::Item>, Self::Error>
Decode bytes from src into a StompItem.
Parameters
src: a mutable reference to the read buffer containing bytes from the transport. The decoder may consume bytes from this buffer (using methods likeadvanceorsplit_to) when it successfully decodes a frame. If there are not enough bytes to form a complete frame, this method should returnOk(None)and leavesrcin the same state.
Returns
Ok(Some(StompItem))when a full item (frame or heartbeat) was decoded and bytes were consumed fromsrcaccordingly.Ok(None)when more bytes are required to decode a complete item.Err(io::Error)on protocol or data errors (invalid UTF-8, malformed frames, missing NUL after a content-length body, etc.).
Source§impl Default for StompCodec
impl Default for StompCodec
Source§impl Encoder<StompItem> for StompCodec
impl Encoder<StompItem> for StompCodec
Source§fn encode(
&mut self,
item: StompItem,
dst: &mut BytesMut,
) -> Result<(), Self::Error>
fn encode( &mut self, item: StompItem, dst: &mut BytesMut, ) -> Result<(), Self::Error>
Encode a StompItem into the provided destination buffer.
Parameters
item: theStompItemto encode. The encoder takes ownership of the item (and any containedFrame) and may consume/mutate its contents.dst: destination buffer where encoded bytes should be appended. This is the sameBytesMutprovided by thetokio_util::codecframework (e.g.Framed). Do not replace or reassigndst; instead append bytes into it usingBufMutmethods (put_u8,put_slice,extend_from_slice, etc.). Afterencodereturns the contents ofdstwill be written to the underlying transport.
Returns
Ok(())on success, orErr(io::Error)on encoding-related errors.
Auto Trait Implementations§
impl Freeze for StompCodec
impl RefUnwindSafe for StompCodec
impl Send for StompCodec
impl Sync for StompCodec
impl Unpin for StompCodec
impl UnsafeUnpin for StompCodec
impl UnwindSafe for StompCodec
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