feat: io
All checks were successful
ci/woodpecker/push/lib Pipeline was successful

This commit is contained in:
Strix 2024-03-10 19:34:13 +01:00
parent d2ecf2e195
commit 576ba23509
No known key found for this signature in database
GPG key ID: 5F35B3B8537287A7
3 changed files with 26 additions and 3 deletions

4
domo_lib/Cargo.lock generated
View file

@ -19,14 +19,14 @@ dependencies = [
[[package]]
name = "domo_lib"
version = "0.3.0"
version = "0.3.1"
dependencies = [
"domo_proto",
]
[[package]]
name = "domo_proto"
version = "1.0.2"
version = "1.0.3"
dependencies = [
"crc32fast",
"rand",

21
domo_lib/src/io.rs Normal file
View file

@ -0,0 +1,21 @@
use std::io;
use std::io::Read;
use domo_proto::packet::{Packet, PACKET_HEADER_SIZE};
pub fn try_read_packet(read_handle: &mut dyn Read) -> io::Result<Packet> {
let mut header = [0_u8; PACKET_HEADER_SIZE];
read_handle.read(header.as_mut_slice())?;
if header[0] != 1 {
return Err(io::Error::new(io::ErrorKind::InvalidData, "Invalid version"));
}
let mut body = vec![];
body.reserve(u16::from_be_bytes([header[0x12], header[0x13]]) as usize);
read_handle.read_exact(&mut body)?;
Packet::try_from({
let mut data = vec![];
data.extend(header);
data.extend(body);
data
})
}

View file

@ -1,4 +1,6 @@
/// Node abstraction
pub mod node;
/// State
pub mod state;
pub mod state;
/// IO
pub mod io;