Skip to main content

Protocol

Trait Protocol 

Source
pub trait Protocol: Send + Sync {
    // Required methods
    fn subprotocol(&self) -> &str;
    fn encode(&self, command: &Command) -> Result<Vec<u8>, Error>;
    fn decode(&self, payload: &[u8]) -> Result<Incoming, Error>;
}
Expand description

Translates between Action Cable commands and the bytes on the wire. It is the seam where an Action Cable protocol plugs in.

One protocol speaks one subprotocol. A client offers every protocol it was given and speaks the one the server picks, so supporting a new protocol means adding one rather than replacing the list.

Required Methods§

Source

fn subprotocol(&self) -> &str

The name this protocol negotiates under.

Source

fn encode(&self, command: &Command) -> Result<Vec<u8>, Error>

Turns a command into one outgoing message.

Source

fn decode(&self, payload: &[u8]) -> Result<Incoming, Error>

Turns one incoming message into a frame the client understands. A frame of Kind::Message must carry a message; the client drops one that doesn’t, where the Go client delivers an empty message.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§