#[repr(C)]pub struct TimestampFormat {
pub seconds: u32,
pub fraction: u32,
}Expand description
NTP Timestamp Format - Used in packet headers and other places with limited word size. It includes a 32-bit unsigned seconds field spanning 136 years and a 32-bit fraction field resolving 232 picoseconds.
The prime epoch is 0 h 1 January 1900 UTC, when all bits are zero.
§Layout
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Seconds |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Fraction |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+Fields§
§seconds: u32Seconds since 1900-01-01 00:00:00 UTC (32-bit unsigned).
fraction: u32Fractional seconds (32-bit unsigned, resolution of ~232 picoseconds).
Trait Implementations§
Source§impl Clone for TimestampFormat
impl Clone for TimestampFormat
Source§fn clone(&self) -> TimestampFormat
fn clone(&self) -> TimestampFormat
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ConstPackedSizeBytes for TimestampFormat
impl ConstPackedSizeBytes for TimestampFormat
Source§const PACKED_SIZE_BYTES: usize = 8
const PACKED_SIZE_BYTES: usize = 8
Source§impl Debug for TimestampFormat
impl Debug for TimestampFormat
Source§impl Default for TimestampFormat
impl Default for TimestampFormat
Source§fn default() -> TimestampFormat
fn default() -> TimestampFormat
Source§impl From<Instant> for TimestampFormat
impl From<Instant> for TimestampFormat
Source§fn from(t: Instant) -> TimestampFormat
fn from(t: Instant) -> TimestampFormat
Converts a Unix Instant to a 32-bit NTP timestamp.
Note: This truncates to 32 bits, losing era information. The resulting
protocol::TimestampFormat is correct for NTPv4 on-wire use, but the era must
be inferred by the receiver using a pivot-based approach (see timestamp_to_instant).
Source§impl From<TimestampFormat> for Instant
Available on crate feature std only.
impl From<TimestampFormat> for Instant
std only.Source§fn from(t: TimestampFormat) -> Instant
fn from(t: TimestampFormat) -> Instant
Converts a 32-bit NTP timestamp to a Unix Instant, using the current system
time as a pivot for era disambiguation.
This is correct for live NTP usage where timestamps are close to “now”.
For offline or replay scenarios, use timestamp_to_instant with an explicit pivot.
Source§impl FromBytes for TimestampFormat
impl FromBytes for TimestampFormat
Source§fn from_bytes(buf: &[u8]) -> Result<(TimestampFormat, usize), ParseError>
fn from_bytes(buf: &[u8]) -> Result<(TimestampFormat, usize), ParseError>
buf.Source§impl Hash for TimestampFormat
impl Hash for TimestampFormat
Source§impl Ord for TimestampFormat
impl Ord for TimestampFormat
Source§fn cmp(&self, other: &TimestampFormat) -> Ordering
fn cmp(&self, other: &TimestampFormat) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TimestampFormat
impl PartialEq for TimestampFormat
Source§impl PartialOrd for TimestampFormat
impl PartialOrd for TimestampFormat
Source§impl ReadFromBytes for TimestampFormat
impl ReadFromBytes for TimestampFormat
Source§fn read_from_bytes<R>(reader: R) -> Result<TimestampFormat, Error>where
R: ReadBytesExt,
fn read_from_bytes<R>(reader: R) -> Result<TimestampFormat, Error>where
R: ReadBytesExt,
Source§impl ToBytes for TimestampFormat
impl ToBytes for TimestampFormat
Source§fn to_bytes(&self, buf: &mut [u8]) -> Result<usize, ParseError>
fn to_bytes(&self, buf: &mut [u8]) -> Result<usize, ParseError>
ParseError::BufferTooShort if buf is too short.