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
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use crate::packet_reader::PacketReader;
use std::time::SystemTime;
#[derive(Copy, Clone, PartialEq)]
pub struct Timestamp {
time: u64,
}
impl Timestamp {
pub fn now() -> Self {
let time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("timing error!")
.as_secs();
Timestamp { time }
}
pub fn write(&self, buffer: &mut Vec<u8>) {
buffer.write_u64::<BigEndian>(self.time).unwrap();
}
pub fn read(reader: &mut PacketReader) -> Self {
let cursor = reader.get_cursor();
let time = cursor.read_u64::<BigEndian>().unwrap();
Timestamp { time }
}
}