Files
otd-ipc-rs/src/messages/mod.rs
2026-02-26 20:35:09 +01:00

41 lines
807 B
Rust

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, Clone)]
pub enum Message {
None,
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], Box<dyn std::error::Error>> {
if bytes.len() < N {
return Err("buffer too small".into());
}
let (head, tail) = bytes.split_at(N);
*bytes = tail;
Ok(head.try_into()?)
}