nodedb_cluster/wire_version/types.rs
1// SPDX-License-Identifier: BUSL-1.1
2
3//! Wire protocol version newtype.
4
5/// Opaque wrapper around a `u16` wire-protocol version number.
6///
7/// v1 is the implicit "no envelope" world — messages serialized directly
8/// without any outer `Versioned<T>` wrapper. v2 is the first explicit version
9/// emitted by [`crate::wire_version::envelope::encode_versioned`].
10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub struct WireVersion(pub u16);
12
13impl WireVersion {
14 /// v1: legacy — no `Versioned<T>` envelope. Raw inner type bytes.
15 pub const V1: WireVersion = WireVersion(1);
16
17 /// v2: first explicit envelope version. Introduced alongside this module.
18 /// `encode_versioned` always emits v2; `decode_versioned` falls back to v1
19 /// if the outer envelope is absent or unparseable.
20 pub const CURRENT: WireVersion = WireVersion(2);
21}
22
23impl std::fmt::Display for WireVersion {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 write!(f, "v{}", self.0)
26 }
27}