1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
pub(crate) mod combined_record;
pub(crate) mod compressed;
pub(crate) mod entry;
pub(crate) mod hashed;
pub(crate) mod locator;
pub(crate) mod owned;
use tokio::io::{AsyncRead, AsyncReadExt};
pub(crate) async fn read_string<R: AsyncRead + Unpin>(reader: R, length: usize) -> std::io::Result<String> {
let mut buffer = String::with_capacity(length);
reader.take(length as u64).read_to_string(&mut buffer).await?;
Ok(buffer)
}
pub(crate) async fn read_bytes<R: AsyncRead + Unpin>(reader: R, length: usize) -> std::io::Result<Vec<u8>> {
let mut buffer = Vec::with_capacity(length);
reader.take(length as u64).read_to_end(&mut buffer).await?;
Ok(buffer)
}
macro_rules! poll_result_ok {
($poll:expr) => {
match $poll {
Ok(inner) => inner,
Err(err) => return Poll::Ready(Err(err)),
}
};
}
use poll_result_ok;