From: Scott Worley Date: Tue, 10 Oct 2023 22:45:38 +0000 (-0700) Subject: server: Combine ago & clock to get original event time X-Git-Tag: v0.1.0~15 X-Git-Url: http://git.scottworley.com/tattlekey/commitdiff_plain/f9625e91cfed21a65b720609ed1d8a7e7c0f36bd?hp=143d53ed1d795c5c5f6e0773ab3c71700d3ef9a0 server: Combine ago & clock to get original event time --- diff --git a/server/src/main.rs b/server/src/main.rs index c4c0b19..c31f873 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -15,6 +15,7 @@ // along with this program. If not, see . use std::net::UdpSocket; +use std::time::{Duration, SystemTime}; const MESSAGE_SIZE: usize = 12; @@ -29,17 +30,20 @@ struct MessageKey { struct Message { key: MessageKey, ago: u32, + t: SystemTime, } impl From<&[u8; MESSAGE_SIZE]> for Message { fn from(value: &[u8; MESSAGE_SIZE]) -> Self { + let ago = u32::from_be_bytes(value[8..=11].try_into().expect("I can't count")); Self { key: MessageKey { epoch: u32::from_be_bytes(value[0..=3].try_into().expect("I can't count")), device: u16::from_be_bytes(value[4..=5].try_into().expect("I can't count")), seq: u16::from_be_bytes(value[6..=7].try_into().expect("I can't count")), }, - ago: u32::from_be_bytes(value[8..=11].try_into().expect("I can't count")), + ago, + t: SystemTime::now() - Duration::new(ago.into(), 0), } } }