about summary refs log tree commit diff
path: root/gatherer-api/src/lib.rs
blob: 055985f012ef1d41948f672a4394ef6af45683cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::io::Read;

use gny::blobby::{BinRead, Configuration};

pub mod request;
pub mod response;

pub fn read_packet<R: Read>(reader: &mut R, buffer: &mut [u8]) -> Result<usize, std::io::Error> {
	let (packet_len, reader) = {
		let mut br = BinRead::new(reader, Configuration::default());
		(br.u16().unwrap(), br.into_inner())
	};

	reader.read_exact(&mut buffer[..packet_len as usize])?;
	tracing::trace!("read packet of len={packet_len}");
	Ok(packet_len as usize)
}