Initial Commit
This commit is contained in:
37
src/messages/mod.rs
Normal file
37
src/messages/mod.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
mod debug_message;
|
||||
mod device_info;
|
||||
mod experimental;
|
||||
mod header;
|
||||
mod hello;
|
||||
mod message_type;
|
||||
mod ping;
|
||||
mod state;
|
||||
|
||||
pub use debug_message::*;
|
||||
pub use device_info::*;
|
||||
pub use experimental::*;
|
||||
pub use header::*;
|
||||
pub use hello::*;
|
||||
pub use message_type::*;
|
||||
pub use ping::*;
|
||||
pub use state::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Message {
|
||||
DeviceInfo(Box<DeviceInfo>),
|
||||
State(State),
|
||||
Ping(Ping),
|
||||
DebugMessage(DebugMessage),
|
||||
Experimental(Experimental),
|
||||
// Hello(Hello),
|
||||
}
|
||||
|
||||
// helper to read fixed-size chunks
|
||||
pub(super) fn take<const N: usize>(bytes: &mut &[u8]) -> Result<[u8; N], &'static str> {
|
||||
if bytes.len() < N {
|
||||
return Err("buffer too small");
|
||||
}
|
||||
let (head, tail) = bytes.split_at(N);
|
||||
*bytes = tail;
|
||||
Ok(head.try_into().unwrap())
|
||||
}
|
||||
Reference in New Issue
Block a user