Frame

Enum Frame 

Source
pub enum Frame {
    Subscribe {
        id: u64,
        channel: String,
    },
    Unsubscribe {
        id: u64,
        channel: String,
    },
    Publish {
        id: Option<u64>,
        channel: String,
        event: Option<String>,
        payload: Vec<u8>,
    },
    Presence {
        id: u64,
        channel: String,
        action: PresenceAction,
        data: Option<Value>,
    },
    Ack {
        id: u64,
    },
    Error {
        id: u64,
        code: u16,
        message: String,
    },
    Ping {
        timestamp: Option<u64>,
    },
    Pong {
        timestamp: Option<u64>,
    },
    Connect {
        version: u8,
        token: Option<String>,
    },
    Connected {
        connection_id: String,
        version: u8,
        heartbeat: u32,
    },
}
Expand description

A protocol frame.

Frames are the messages exchanged between clients and servers. Each frame type has specific fields relevant to its operation.

Variants§

§

Subscribe

Subscribe to a channel.

Fields

§id: u64

Request ID for acknowledgment.

§channel: String

Channel name to subscribe to.

§

Unsubscribe

Unsubscribe from a channel.

Fields

§id: u64

Request ID for acknowledgment.

§channel: String

Channel name to unsubscribe from.

§

Publish

Publish a message to a channel.

Fields

§id: Option<u64>

Optional request ID for acknowledgment.

§channel: String

Target channel.

§event: Option<String>

Optional event name.

§payload: Vec<u8>

Message payload.

§

Presence

Presence update.

Fields

§id: u64

Request ID.

§channel: String

Channel name.

§action: PresenceAction

Presence action.

§data: Option<Value>

Optional presence metadata.

§

Ack

Acknowledgment of a request.

Fields

§id: u64

ID of the acknowledged request.

§

Error

Error response.

Fields

§id: u64

ID of the failed request (0 if not applicable).

§code: u16

Error code.

§message: String

Human-readable error message.

§

Ping

Keepalive ping.

Fields

§timestamp: Option<u64>

Optional timestamp.

§

Pong

Keepalive pong.

Fields

§timestamp: Option<u64>

Echoed timestamp from ping.

§

Connect

Initial connection handshake.

Fields

§version: u8

Protocol version.

§token: Option<String>

Optional authentication token.

§

Connected

Connection established response.

Fields

§connection_id: String

Unique connection identifier.

§version: u8

Negotiated protocol version.

§heartbeat: u32

Recommended heartbeat interval in milliseconds.

Implementations§

Source§

impl Frame

Source

pub fn frame_type(&self) -> FrameType

Get the frame type.

Source

pub fn subscribe(id: u64, channel: impl Into<String>) -> Self

Create a new Subscribe frame.

Source

pub fn unsubscribe(id: u64, channel: impl Into<String>) -> Self

Create a new Unsubscribe frame.

Source

pub fn publish(channel: impl Into<String>, payload: impl Into<Vec<u8>>) -> Self

Create a new Publish frame.

Source

pub fn publish_with_ack( id: u64, channel: impl Into<String>, payload: impl Into<Vec<u8>>, ) -> Self

Create a new Publish frame with ID for acknowledgment.

Source

pub fn ack(id: u64) -> Self

Create a new Ack frame.

Source

pub fn error(id: u64, code: u16, message: impl Into<String>) -> Self

Create a new Error frame.

Source

pub fn ping() -> Self

Create a new Ping frame.

Source

pub fn ping_with_timestamp(timestamp: u64) -> Self

Create a new Ping frame with timestamp.

Source

pub fn pong(timestamp: Option<u64>) -> Self

Create a new Pong frame.

Source

pub fn connect(version: u8, token: Option<String>) -> Self

Create a new Connect frame.

Source

pub fn connected( connection_id: impl Into<String>, version: u8, heartbeat: u32, ) -> Self

Create a new Connected frame.

Trait Implementations§

Source§

impl Clone for Frame

Source§

fn clone(&self) -> Frame

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Frame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Frame

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Frame

Source§

fn eq(&self, other: &Frame) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Frame

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Frame

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnwindSafe for Frame

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,