// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::net::UdpSocket;
+use std::time::{Duration, SystemTime};
const MESSAGE_SIZE: usize = 12;
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),
}
}
}