pub type NtpShortFormat = super::message::NtpShortFormat;
pub type NtpTimestamp = super::message::NtpTimestamp;
impl NtpTimestamp {
pub const fn zero() -> Self {
Self::from_raw(0)
}
}
#[cfg(test)]
mod tests {
use super::{NtpShortFormat, NtpTimestamp};
#[test]
fn ntp_fixed_point_short_format_preserves_raw_wire_value() {
let value = NtpShortFormat::from_raw(0x0001_8000);
assert_eq!(value.raw(), 0x0001_8000);
assert_eq!(value.integer(), 1);
assert_eq!(value.fraction(), 0x8000);
}
#[test]
fn ntp_fixed_point_short_format_supports_optional_seconds_view() {
let value = NtpShortFormat::from_parts(2, 0x4000);
assert_eq!(value.raw(), 0x0002_4000);
assert_eq!(value.as_seconds(), 2.25);
}
#[test]
fn ntp_timestamp_preserves_raw_wire_value() {
let value = NtpTimestamp::from_raw(0x83aa_7e80_8000_0000);
assert_eq!(value.raw(), 0x83aa_7e80_8000_0000);
assert_eq!(value.seconds(), 0x83aa_7e80);
assert_eq!(value.fraction(), 0x8000_0000);
}
#[test]
fn ntp_timestamp_zero_constructor_is_unspecified_value() {
let value = NtpTimestamp::zero();
assert_eq!(value.raw(), 0);
assert_eq!(value.seconds(), 0);
assert_eq!(value.fraction(), 0);
assert!(value.is_zero());
}
#[test]
fn ntp_timestamp_seconds_view_is_helper_behavior() {
let value = NtpTimestamp::from_parts(1, 0x8000_0000);
assert_eq!(value.raw(), 0x0000_0001_8000_0000);
assert_eq!(value.as_seconds(), 1.5);
}
}