pub mod command;
pub mod frame;
pub mod message;
pub mod protocol;
use std::convert::TryInto;
pub use self::{command::*, frame::*, message::*};
pub(crate) use protocol::*;
#[derive(Debug, Default)]
pub struct Greeting {
as_server: bool,
}
impl Greeting {
pub fn build() -> Self {
Default::default()
}
pub fn as_server(&mut self, as_server: bool) -> &mut Self {
self.as_server = as_server;
self
}
pub fn into_parts(&self) -> ([u8; 12], [u8; 52]) {
let raw = self.as_bytes();
let partial = raw[..=11].try_into().unwrap();
let remaining = raw[12..].try_into().unwrap();
(partial, remaining)
}
pub fn as_bytes(&self) -> [u8; 64] {
let mut raw = [0u8; 64];
raw[0] = 0xFF; raw[9] = 0x7F;
raw[10] = 3;
raw[11] = 0;
raw[12] = 0x4E;
raw[13] = 0x55;
raw[14] = 0x4C;
raw[15] = 0x4C;
raw[32] = self.as_server as u8;
raw
}
}