[−][src]Struct websocket::message::Message
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]
impl<'a> Message<'a>
pub fn text<S>(data: S) -> Self where
S: Into<Cow<'a, str>>,
[src]
pub fn text<S>(data: S) -> Self where
S: Into<Cow<'a, str>>,
Create a new WebSocket message with text data
pub fn binary<B>(data: B) -> Self where
B: IntoCowBytes<'a>,
[src]
pub fn binary<B>(data: B) -> Self where
B: IntoCowBytes<'a>,
Create a new WebSocket message with binary data
pub fn close() -> Self
[src]
pub 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
pub fn close_because<S>(code: u16, reason: S) -> Self where
S: Into<Cow<'a, str>>,
[src]
pub 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.
pub fn ping<P>(data: P) -> Self where
P: IntoCowBytes<'a>,
[src]
pub 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
pub fn pong<P>(data: P) -> Self where
P: IntoCowBytes<'a>,
[src]
pub fn pong<P>(data: P) -> Self where
P: IntoCowBytes<'a>,
Create a pong WebSocket message, usually a response to a ping message
pub fn into_pong(&mut self) -> Result<(), ()>
[src]
pub 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> DataFrame for Message<'a>
[src]
impl<'a> DataFrame for Message<'a>
fn is_last(&self) -> bool
[src]
fn is_last(&self) -> bool
Is this dataframe the final dataframe of the message?
fn opcode(&self) -> u8
[src]
fn opcode(&self) -> u8
What type of data does this dataframe contain?
fn reserved(&self) -> &[bool; 3]
[src]
fn reserved(&self) -> &[bool; 3]
Reserved bits of this dataframe
fn size(&self) -> usize
[src]
fn size(&self) -> usize
How long (in bytes) is this dataframe's payload
fn write_payload(&self, socket: &mut dyn Write) -> WebSocketResult<()>
[src]
fn write_payload(&self, socket: &mut dyn Write) -> WebSocketResult<()>
Write the payload to a writer
fn take_payload(self) -> Vec<u8>
[src]
fn take_payload(self) -> Vec<u8>
Takes the payload out into a vec
fn frame_size(&self, masked: bool) -> usize
[src]
fn frame_size(&self, masked: bool) -> usize
Get's the size of the entire dataframe in bytes, i.e. header and payload. Read more
fn write_to(&self, writer: &mut dyn Write, mask: bool) -> WebSocketResult<()>
[src]
fn write_to(&self, writer: &mut dyn Write, mask: bool) -> WebSocketResult<()>
Writes a DataFrame to a Writer.
impl<'a> Message for Message<'a>
[src]
impl<'a> Message for Message<'a>
fn serialize(&self, writer: &mut dyn Write, masked: bool) -> WebSocketResult<()>
[src]
fn serialize(&self, writer: &mut dyn Write, masked: bool) -> WebSocketResult<()>
Attempt to form a message from a series of data frames
fn message_size(&self, masked: bool) -> usize
[src]
fn message_size(&self, masked: bool) -> usize
Returns how many bytes this message will take up
fn from_dataframes<D>(frames: Vec<D>) -> WebSocketResult<Self> where
D: DataFrameTrait,
[src]
fn from_dataframes<D>(frames: Vec<D>) -> WebSocketResult<Self> where
D: DataFrameTrait,
Attempt to form a message from a series of data frames
impl<'a> PartialEq<Message<'a>> for Message<'a>
[src]
impl<'a> PartialEq<Message<'a>> for Message<'a>
fn eq(&self, other: &Message<'a>) -> bool
[src]
fn eq(&self, other: &Message<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Message<'a>) -> bool
[src]
fn ne(&self, other: &Message<'a>) -> bool
This method tests for !=
.
impl<'m> From<Message<'m>> for OwnedMessage
[src]
impl<'m> From<Message<'m>> for OwnedMessage
impl<'m> From<OwnedMessage> for Message<'m>
[src]
impl<'m> From<OwnedMessage> for Message<'m>
fn from(message: OwnedMessage) -> Self
[src]
fn from(message: OwnedMessage) -> Self
Performs the conversion.
impl<'a> Clone for Message<'a>
[src]
impl<'a> Clone for Message<'a>
fn clone(&self) -> 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[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a> Eq for Message<'a>
[src]
impl<'a> Eq for Message<'a>
impl<'a> Debug for Message<'a>
[src]
impl<'a> Debug for Message<'a>
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Typeable for T where
T: Any,
[src]
impl<T> Typeable for T where
T: Any,
impl<T> Erased for T
[src]
impl<T> Erased for T