Skip to main content

StompCodec

Struct StompCodec 

Source
pub struct StompCodec {}
Expand description

StompCodec implements tokio_util::codec::{Decoder, Encoder} for the STOMP wire protocol.

Responsibilities:

  • Decode incoming bytes into StompItem::Frame or StompItem::Heartbeat.
  • Support both NUL-terminated frames and frames using the content-length header (STOMP 1.2) for binary bodies containing NUL bytes.
  • Encode StompItem back into bytes for the wire format and emit content-length when necessary.

Implementations§

Source§

impl StompCodec

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl Decoder for StompCodec

Source§

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 like advance or split_to) when it successfully decodes a frame. If there are not enough bytes to form a complete frame, this method should return Ok(None) and leave src in the same state.

Returns

  • Ok(Some(StompItem)) when a full item (frame or heartbeat) was decoded and bytes were consumed from src accordingly.
  • 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§

type Item = StompItem

The type of decoded frames.
Source§

type Error = Error

The type of unrecoverable frame decoding errors. Read more
Source§

fn decode_eof( &mut self, buf: &mut BytesMut, ) -> Result<Option<Self::Item>, Self::Error>

A default method available to be called when there are no more bytes available to be read from the underlying I/O. Read more
Source§

fn framed<T>(self, io: T) -> Framed<T, Self>
where T: AsyncRead + AsyncWrite, Self: Sized,

Provides a Stream and Sink interface for reading and writing to this Io object, using Decode and Encode to read and write the raw data. Read more
Source§

impl Default for StompCodec

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Encoder<StompItem> for StompCodec

Source§

fn encode( &mut self, item: StompItem, dst: &mut BytesMut, ) -> Result<(), Self::Error>

Encode a StompItem into the provided destination buffer.

Parameters

  • item: the StompItem to encode. The encoder takes ownership of the item (and any contained Frame) and may consume/mutate its contents.
  • dst: destination buffer where encoded bytes should be appended. This is the same BytesMut provided by the tokio_util::codec framework (e.g. Framed). Do not replace or reassign dst; instead append bytes into it using BufMut methods (put_u8, put_slice, extend_from_slice, etc.). After encode returns the contents of dst will be written to the underlying transport.

Returns

  • Ok(()) on success, or Err(io::Error) on encoding-related errors.
Source§

type Error = Error

The type of encoding errors. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.