From f9625e91cfed21a65b720609ed1d8a7e7c0f36bd Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Tue, 10 Oct 2023 15:45:38 -0700 Subject: [PATCH] server: Combine ago & clock to get original event time --- server/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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), } } } -- 2.44.1