refactor(proto): Remove Clock::None and default to Clock::Both

Simplify clock parameter negotiation by rejecting the ambiguous 'None' value.
This commit is contained in:
Nils Andreas Svee committed 2026-05-10 20:56:43 +07:00
1 parent cf74887bdf
commit 34dd2ee5d2
2 files changed
+27 -4

No files matched your search

+11 -1
View File
@@ -139,7 +139,7 @@ mod tests {
assert_eq!(
echo_header_len(
false,
&params(ReceivedStats::None, StampAt::None, Clock::None)
&params(ReceivedStats::None, StampAt::None, Clock::Both)
),
16
);
@@ -180,6 +180,16 @@ mod tests {
);
}
#[test]
fn no_timestamp_layout_ignores_clock() {
for clock in [Clock::Wall, Clock::Monotonic, Clock::Both] {
assert_eq!(
echo_header_len(false, &params(ReceivedStats::None, StampAt::None, clock)),
16
);
}
}
#[test]
fn negotiated_length_never_smaller_than_header() {
let mut p = params(ReceivedStats::Both, StampAt::Both, Clock::Both);
+16 -3
View File
@@ -151,10 +151,9 @@ impl TryFrom<i64> for StampAt {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(i64)]
pub enum Clock {
#[default]
None = 0,
Wall = 1,
Monotonic = 2,
#[default]
Both = 3,
}
@@ -173,7 +172,6 @@ impl TryFrom<i64> for Clock {
fn try_from(value: i64) -> Result<Self> {
match value {
0 => Ok(Self::None),
1 => Ok(Self::Wall),
2 => Ok(Self::Monotonic),
3 => Ok(Self::Both),
@@ -232,4 +230,19 @@ mod tests {
let params = Params::decode(&encoded).unwrap();
assert_eq!(params.protocol_version, 1);
}
#[test]
fn explicit_clock_zero_is_rejected() {
let mut encoded = Vec::new();
varint::encode_uvarint(7, &mut encoded);
varint::encode_varint(0, &mut encoded);
assert_eq!(
Params::decode(&encoded),
Err(ProtoError::InvalidEnum {
name: "Clock",
value: 0,
})
);
}
}