primitives/types/identifiers/
protocol_info.rs

1/// Static protocol information, used for logging and tagging messages for domain separation.
2///
3/// To ensure uniqueness, the `tag` should be a unique integer for each protocol.
4/// The `name` is a human-readable identifier for the protocol, useful for logging and debugging.
5///
6/// Use the `macros::new_protocol!` macro to create instances of this struct, which ensures
7/// that protocol tags are unique at compile time.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub struct ProtocolInfo {
10    /// A unique tag for the protocol, used for domain separation in signatures and hashes.
11    tag: u16,
12    /// The name of the protocol, used for logging and debugging.
13    name: &'static str,
14}
15
16impl ProtocolInfo {
17    /// Create a new `ProtocolInfo` instance. Warning! This does not check for tag uniqueness.
18    /// It is recommended to use the `macros::new_protocol!` macro instead.
19    pub const fn new(name: &'static str, tag: u16) -> Self {
20        Self { name, tag }
21    }
22
23    /// Get the name of the protocol.
24    pub const fn name(&self) -> &'static str {
25        self.name
26    }
27
28    /// Get the unique tag of the protocol.
29    pub const fn tag(&self) -> u16 {
30        self.tag
31    }
32}