open_dis_rust/common/
clock_time.rs

1//     open-dis-rust - Rust implementation of the IEEE 1278.1-2012 Distributed Interactive
2//                     Simulation (DIS) application protocol
3//     Copyright (C) 2023 Cameron Howell
4//
5//     Licensed under the BSD 2-Clause License
6
7use bytes::{Buf, BufMut, BytesMut};
8
9#[derive(Copy, Clone, Debug, Default)]
10/// Implemented according to IEEE 1278.1-2012 ยง6.2.14
11pub struct ClockTime {
12    /// The hours since 0000h 1 January 1970 UTC (The Epoch)
13    pub hour: u32,
14    /// Time past the hour indicated in the hour field
15    pub time_past_hour: u32,
16}
17
18impl ClockTime {
19    #[must_use]
20    pub fn new(h: u32, p: u32) -> Self {
21        ClockTime {
22            hour: h,
23            time_past_hour: p,
24        }
25    }
26
27    pub fn serialize(&self, buf: &mut BytesMut) {
28        buf.put_u32(self.hour);
29        buf.put_u32(self.time_past_hour);
30    }
31
32    pub fn decode(buf: &mut BytesMut) -> ClockTime {
33        ClockTime {
34            hour: buf.get_u32(),
35            time_past_hour: buf.get_u32(),
36        }
37    }
38}