sheave_core::readers

Function read_extended_timestamp

Source
pub fn read_extended_timestamp<R: AsyncRead>(
    reader: Pin<&mut R>,
) -> ExtendedTimestampReader<'_, R>
Expand description

Reads an extended timestamp from streams.

ยงExamples

use std::{
    io::Result as IOResult,
    pin::pin,
    time::Duration
};
use rand::random;
use sheave_core::readers::read_extended_timestamp;

#[tokio::main]
async fn main() -> IOResult<()> {
    let extended_timestamp = Duration::from_millis(random::<u32>() as u64);
    let reader: [u8; 4] = (extended_timestamp.as_millis() as u32).to_be_bytes();
    let result = read_extended_timestamp(pin!(reader.as_slice())).await?;
    assert_eq!(extended_timestamp, result);
    Ok(())
}