Enum websocket::message::OwnedMessage
[−]
[src]
pub enum OwnedMessage {
Text(String),
Binary(Vec<u8>),
Close(Option<CloseData>),
Ping(Vec<u8>),
Pong(Vec<u8>),
}Represents an owned WebSocket message.
OwnedMessages are generated when the user receives a message (since the data
has to be copied out of the network buffer anyway).
If you would like to create a message out of borrowed data to use for sending
please use the Message struct (which contains a Cow).
Note that OwnedMessage and Message can be converted into each other.
Variants
Text(String)A message containing UTF-8 text data
Binary(Vec<u8>)A message containing binary data
Close(Option<CloseData>)A message which indicates closure of the WebSocket connection. This message may or may not contain data.
Ping(Vec<u8>)A ping message - should be responded to with a pong message. Usually the pong message will be sent with the same data as the received ping message.
Pong(Vec<u8>)A pong message, sent in response to a Ping message, usually containing the same data as the received ping message.
Methods
impl OwnedMessage[src]
pub fn is_close(&self) -> bool[src]
Checks if this message is a close message.
assert!(OwnedMessage::Close(None).is_close());
pub fn is_control(&self) -> bool[src]
Checks if this message is a control message.
Control messages are either Close, Ping, or Pong.
assert!(OwnedMessage::Ping(vec![]).is_control()); assert!(OwnedMessage::Pong(vec![]).is_control()); assert!(OwnedMessage::Close(None).is_control());
pub fn is_data(&self) -> bool[src]
Checks if this message is a data message.
Data messages are either Text or Binary.
assert!(OwnedMessage::Text("1337".to_string()).is_data()); assert!(OwnedMessage::Binary(vec![]).is_data());
pub fn is_ping(&self) -> bool[src]
Checks if this message is a ping message.
Ping messages can come at any time and usually generate a Pong message
response.
assert!(OwnedMessage::Ping("ping".to_string().into_bytes()).is_ping());
pub fn is_pong(&self) -> bool[src]
Checks if this message is a pong message.
Pong messages are usually sent only in response to Ping messages.
assert!(OwnedMessage::Pong("pong".to_string().into_bytes()).is_pong());
Trait Implementations
impl Eq for OwnedMessage[src]
impl PartialEq for OwnedMessage[src]
fn eq(&self, __arg_0: &OwnedMessage) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &OwnedMessage) -> bool[src]
This method tests for !=.
impl Clone for OwnedMessage[src]
fn clone(&self) -> OwnedMessage[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl Debug for OwnedMessage[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result[src]
Formats the value using the given formatter. Read more
impl Message for OwnedMessage[src]
fn serialize(&self, writer: &mut Write, masked: bool) -> WebSocketResult<()>[src]
Attempt to form a message from a series of data frames
fn message_size(&self, masked: bool) -> usize[src]
Returns how many bytes this message will take up
fn from_dataframes<D>(frames: Vec<D>) -> WebSocketResult<Self> where
D: DataFrameTrait, [src]
D: DataFrameTrait,
Attempt to form a message from a series of data frames
impl DataFrame for OwnedMessage[src]
fn is_last(&self) -> bool[src]
Is this dataframe the final dataframe of the message?
fn opcode(&self) -> u8[src]
What type of data does this dataframe contain?
fn reserved(&self) -> &[bool; 3][src]
Reserved bits of this dataframe
fn size(&self) -> usize[src]
How long (in bytes) is this dataframe's payload
fn write_payload(&self, socket: &mut Write) -> WebSocketResult<()>[src]
Write the payload to a writer
fn take_payload(self) -> Vec<u8>[src]
Takes the payload out into a vec
fn frame_size(&self, masked: bool) -> usize[src]
Get's the size of the entire dataframe in bytes, i.e. header and payload. Read more
fn write_to(&self, writer: &mut Write, mask: bool) -> WebSocketResult<()>[src]
Writes a DataFrame to a Writer.
impl<'m> From<Message<'m>> for OwnedMessage[src]
impl<'m> From<OwnedMessage> for Message<'m>[src]
fn from(message: OwnedMessage) -> Self[src]
Performs the conversion.