This commit is contained in:
parent
d2ecf2e195
commit
576ba23509
3 changed files with 26 additions and 3 deletions
4
domo_lib/Cargo.lock
generated
4
domo_lib/Cargo.lock
generated
|
@ -19,14 +19,14 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "domo_lib"
|
name = "domo_lib"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"domo_proto",
|
"domo_proto",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "domo_proto"
|
name = "domo_proto"
|
||||||
version = "1.0.2"
|
version = "1.0.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"rand",
|
"rand",
|
||||||
|
|
21
domo_lib/src/io.rs
Normal file
21
domo_lib/src/io.rs
Normal 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
|
||||||
|
})
|
||||||
|
}
|
|
@ -2,3 +2,5 @@
|
||||||
pub mod node;
|
pub mod node;
|
||||||
/// State
|
/// State
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
/// IO
|
||||||
|
pub mod io;
|
Loading…
Reference in a new issue