indexbus_typed/
meta.rs

1/// Expected message identity for receive-side filtering.
2///
3/// This identity is stored in the v1 envelope header and validated by typed receive helpers.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct MsgMeta {
6    /// Schema identifier for the message family.
7    pub schema_id: u64,
8    /// Message type identifier within the schema.
9    pub msg_type: u32,
10    /// Message version.
11    pub msg_version: u16,
12    /// Header flags.
13    ///
14    /// Most callers leave this as `0` and use [`MsgMeta::with_flags`] when needed.
15    pub flags: u16,
16}
17
18/// Const helper for constructing [`MsgMeta`] with the common default `flags = 0`.
19#[inline]
20pub const fn meta(schema_id: u64, msg_type: u32, msg_version: u16) -> MsgMeta {
21    MsgMeta::new(schema_id, msg_type, msg_version)
22}
23
24/// Compile-time message identity.
25///
26/// This exists to avoid repeating `MsgMeta::new(...)` at every publish/recv call-site.
27///
28/// Layering note: this is defined in `indexbus-typed` (not `indexbus-core`) to keep Layer 0
29/// explicit and stable.
30pub trait IndexbusMsgSpec {
31    /// Compile-time message identity.
32    const META: MsgMeta;
33}
34
35impl MsgMeta {
36    #[inline]
37    /// Construct a message identity with default `flags = 0`.
38    pub const fn new(schema_id: u64, msg_type: u32, msg_version: u16) -> Self {
39        Self {
40            schema_id,
41            msg_type,
42            msg_version,
43            flags: 0,
44        }
45    }
46
47    #[inline]
48    /// Return a copy of this identity with `flags` updated.
49    pub const fn with_flags(mut self, flags: u16) -> Self {
50        self.flags = flags;
51        self
52    }
53}