Struct websocket::Message [−][src]
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
Implementations
impl<'a> Message<'a>
[src]
pub fn text<S>(data: S) -> Message<'a> where
S: Into<Cow<'a, str>>,
[src]
S: Into<Cow<'a, str>>,
Create a new WebSocket message with text data
pub fn binary<B>(data: B) -> Message<'a> where
B: IntoCowBytes<'a>,
[src]
B: IntoCowBytes<'a>,
Create a new WebSocket message with binary data
pub fn close() -> Message<'a>
[src]
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) -> Message<'a> where
S: Into<Cow<'a, str>>,
[src]
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) -> Message<'a> where
P: IntoCowBytes<'a>,
[src]
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) -> Message<'a> where
P: IntoCowBytes<'a>,
[src]
P: IntoCowBytes<'a>,
Create a pong WebSocket message, usually a response to a ping message
pub fn into_pong(&mut self) -> Result<(), ()>
[src]
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> Clone for Message<'a>
[src]
impl<'a> DataFrame for Message<'a>
[src]
pub fn is_last(&self) -> bool
[src]
pub fn opcode(&self) -> u8
[src]
pub fn reserved(&self) -> &[bool; 3]
[src]
pub fn size(&self) -> usize
[src]
pub fn write_payload(
&self,
socket: &mut dyn Write
) -> Result<(), WebSocketError>
[src]
&self,
socket: &mut dyn Write
) -> Result<(), WebSocketError>
pub fn take_payload(self) -> Vec<u8, Global>ⓘ
[src]
pub fn frame_size(&self, masked: bool) -> usize
[src]
pub fn write_to(
&self,
writer: &mut dyn Write,
mask: bool
) -> Result<(), WebSocketError>
[src]
&self,
writer: &mut dyn Write,
mask: bool
) -> Result<(), WebSocketError>
impl<'a> Debug for Message<'a>
[src]
impl<'a> Eq for Message<'a>
[src]
impl<'m> From<Message<'m>> for OwnedMessage
[src]
pub fn from(message: Message<'m>) -> OwnedMessage
[src]
impl<'m> From<OwnedMessage> for Message<'m>
[src]
pub fn from(message: OwnedMessage) -> Message<'m>
[src]
impl<'a> Message for Message<'a>
[src]
pub fn serialize(
&self,
writer: &mut dyn Write,
masked: bool
) -> Result<(), WebSocketError>
[src]
&self,
writer: &mut dyn Write,
masked: bool
) -> Result<(), WebSocketError>
Attempt to form a message from a series of data frames
pub fn message_size(&self, masked: bool) -> usize
[src]
Returns how many bytes this message will take up
pub fn from_dataframes<D>(
frames: Vec<D, Global>
) -> Result<Message<'a>, WebSocketError> where
D: DataFrame,
[src]
frames: Vec<D, Global>
) -> Result<Message<'a>, WebSocketError> where
D: DataFrame,
Attempt to form a message from a series of data frames
impl<'a> PartialEq<Message<'a>> for Message<'a>
[src]
pub fn eq(&self, other: &Message<'a>) -> bool
[src]
pub fn ne(&self, other: &Message<'a>) -> bool
[src]
impl<'a> StructuralEq for Message<'a>
[src]
impl<'a> StructuralPartialEq for Message<'a>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for Message<'a>
impl<'a> Send for Message<'a>
impl<'a> Sync for Message<'a>
impl<'a> Unpin for Message<'a>
impl<'a> UnwindSafe for Message<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Typeable for T where
T: Any,
T: Any,