use bytes::Bytes;
use crate::Opcode;
#[derive(Debug)]
pub struct Message {
pub opcode: Opcode,
pub payload: Bytes,
}
impl Message {
pub fn text(text: &str) -> Self {
Self {
opcode: Opcode::Text,
payload: Bytes::copy_from_slice(text.as_bytes()),
}
}
pub fn close() -> Self {
Self {
opcode: Opcode::Close,
payload: Bytes::new(),
}
}
pub fn pong() -> Self {
Self {
opcode: Opcode::Pong,
payload: Bytes::new(),
}
}
}