pub fn read_handshake<R: AsyncRead>(
reader: Pin<&mut R>,
) -> HandshakeReader<'_, R>
Expand description
Reads an actual handshake data from streams.
ยงExamples
use std::{
io::Result as IOResult,
pin::pin,
time::Duration,
};
use rand::{
Fill,
thread_rng
};
use sheave_core::{
handshake::Version,
readers::read_handshake
};
#[tokio::main]
async fn main() -> IOResult<()> {
let mut reader: [u8; 1536] = [0; 1536];
reader[..4].copy_from_slice((Duration::default().as_millis() as u32).to_be_bytes().as_slice());
reader[4..8].copy_from_slice(<[u8; 4]>::from(Version::UNSIGNED).as_slice());
reader[8..].try_fill(&mut thread_rng()).unwrap();
let compared = reader;
let handshake = read_handshake(pin!(reader.as_slice())).await?;
assert_eq!(compared.as_slice(), handshake.get_bytes());
Ok(())
}