websocket_base/ws/
message.rs

1//! Provides a trait for WebSocket messages
2//!
3//! See the `ws` module documentation for more information.
4
5use crate::result::WebSocketResult;
6use crate::ws::dataframe::DataFrame as DataFrameable;
7use std::io::Write;
8
9/// A trait for WebSocket messages
10pub trait Message: Sized {
11	/// Writes this message to the writer
12	fn serialize(&self, _: &mut dyn Write, masked: bool) -> WebSocketResult<()>;
13
14	/// Returns how many bytes this message will take up
15	fn message_size(&self, masked: bool) -> usize;
16
17	/// Attempt to form a message from a series of data frames
18	fn from_dataframes<D: DataFrameable>(frames: Vec<D>) -> WebSocketResult<Self>;
19}