Struct websocket::message::Message
[−]
[src]
pub struct Message<'a> { pub opcode: Type, pub cd_status_code: Option<u16>, pub payload: Cow<'a, [u8]>, }
Represents a WebSocket message.
This message also has the ability to not own its payload, and stores its entire payload in
chunks that get written in order when the message gets sent. This makes the write_payload
allocate less memory than the payload
method (which creates a new buffer every time).
Incidentally this (the default implementation of Message) implements the DataFrame trait because this message just gets sent as one single DataFrame.
Fields
opcode: Type
Type of WebSocket message
cd_status_code: Option<u16>
Optional status code to send when closing a connection. (only used if this message is of Type::Close)
payload: Cow<'a, [u8]>
Main payload
Methods
impl<'a> Message<'a>
[src]
fn text<S>(data: S) -> Self where S: Into<Cow<'a, str>>
Create a new WebSocket message with text data
fn binary<B>(data: B) -> Self where B: IntoCowBytes<'a>
Create a new WebSocket message with binary data
fn close() -> Self
Create a new WebSocket message that signals the end of a WebSocket connection, although messages can still be sent after sending this
fn close_because<S>(code: u16, reason: S) -> Self where S: Into<Cow<'a, str>>
Create a new WebSocket message that signals the end of a WebSocket connection and provide a text reason and a status code for why. Messages can still be sent after sending this message.
fn ping<P>(data: P) -> Self where P: IntoCowBytes<'a>
Create a ping WebSocket message, a pong is usually sent back after sending this with the same data
fn pong<P>(data: P) -> Self where P: IntoCowBytes<'a>
Create a pong WebSocket message, usually a response to a ping message
fn into_pong(&mut self) -> Result<(), ()>
Convert a ping message to a pong, keeping the data. This will fail if the original message is not a ping.
Trait Implementations
impl<'a> Debug for Message<'a>
[src]
impl<'a> Clone for Message<'a>
[src]
fn clone(&self) -> Message<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<'a> PartialEq for Message<'a>
[src]
fn eq(&self, __arg_0: &Message<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Message<'a>) -> bool
This method tests for !=
.
impl<'a> DataFrame for Message<'a>
[src]
fn is_last(&self) -> bool
Is this dataframe the final dataframe of the message?
fn opcode(&self) -> u8
What type of data does this dataframe contain?
fn reserved<'b>(&'b self) -> &'b [bool; 3]
Reserved bits of this dataframe
fn payload<'b>(&'b self) -> Cow<'b, [u8]>
Entire payload of the dataframe. If not known then implement write_payload as that is the actual method used when sending the dataframe over the wire. Read more
fn size(&self) -> usize
How long (in bytes) is this dataframe's payload
fn write_payload<W>(&self, socket: &mut W) -> WebSocketResult<()> where W: Write
Write the payload to a writer
fn write_to<W>(&self, writer: &mut W, mask: bool) -> WebSocketResult<()> where W: Write
Writes a DataFrame to a Writer.
impl<'a, 'b> Message<'b, &'b Message<'a>> for Message<'a>
[src]
type DataFrameIterator = Take<Repeat<&'b Message<'a>>>
The iterator type returned by dataframes
fn dataframes(&'b self) -> Self::DataFrameIterator
Turns this message into an iterator over data frames
fn from_dataframes<D>(frames: Vec<D>) -> WebSocketResult<Self> where D: DataFrame
Attempt to form a message from a series of data frames