Skip to main content

naia_shared/
protocol_id.rs

1use naia_serde::SerdeInternal;
2
3/// A unique identifier for a Protocol configuration.
4///
5/// Computed as a BLAKE3 hash of sorted channel, message, and component names.
6/// Used during handshake to detect protocol mismatches between client and server.
7#[derive(SerdeInternal, Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
8pub struct ProtocolId(u64);
9
10impl ProtocolId {
11    /// Create a new ProtocolId from a raw u64 value.
12    /// This is primarily used for testing protocol mismatch scenarios.
13    pub fn new(value: u64) -> Self {
14        Self(value)
15    }
16
17    /// Get the raw u64 value.
18    pub fn value(&self) -> u64 {
19        self.0
20    }
21}
22
23impl std::fmt::Display for ProtocolId {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        write!(f, "ProtocolId({:016x})", self.0)
26    }
27}