#![allow(dead_code)]
use simple_endian::Endianize;
pub const USERNAME_UNITS: usize = 16;
pub const TEXT_UNITS: usize = 64;
pub mod msg_type {
pub const HELLO: u16 = 1;
pub const CHAT: u16 = 2;
pub const QUIT: u16 = 3;
pub const SERVER_MSG: u16 = 4;
pub const ERROR: u16 = 5;
}
#[derive(Endianize, Clone, Copy, Debug, Default)]
#[endian(be)]
pub struct FrameHeader {
pub msg_type: u16,
pub len_bytes: u16,
pub request_id: u32,
}
#[derive(Endianize, Clone, Debug, Default)]
#[endian(be)]
pub struct Hello {
#[text(utf32, units = 16, pad = "space")]
pub username: String,
}
#[derive(Endianize, Clone, Debug, Default)]
#[endian(be)]
pub struct Chat {
#[text(utf32, units = 16, pad = "space")]
pub from: String,
#[text(utf32, units = 64, pad = "space")]
pub text: String,
}
#[derive(Endianize, Clone, Copy, Debug, Default)]
#[endian(be)]
pub struct Quit {
pub reason_code: u16,
pub _reserved: u16,
}
#[derive(Endianize, Clone, Debug, Default)]
#[endian(be)]
pub struct ServerMsg {
#[text(utf32, units = 64, pad = "space")]
pub text: String,
}
#[derive(Endianize, Clone, Debug, Default)]
#[endian(be)]
pub struct ErrorMsg {
pub code: u16,
pub _reserved: u16,
#[text(utf32, units = 64, pad = "space")]
pub message: String,
}
impl FrameHeader {
pub fn with_len(msg_type: u16, request_id: u32, len_bytes: u16) -> Self {
Self {
msg_type,
len_bytes,
request_id,
}
}
}