synapse-primitives 0.0.2

Core types and ID hashing for Synapse RPC framework
Documentation
//! Synapse Core - Encoding utilities and optimizations
//!
//! This crate provides efficient encoding utilities for the Synapse gateway system:
//!
//! - **id**: Strongly-typed identifiers (ServiceId, InterfaceId, MethodId, etc.)
//! - **siphash**: Name-to-ID mapping using SipHash for stable numeric identifiers
//! - **semver**: Decimal semantic version packing into u32
//! - **flags**: Bitfield flag packing for efficient boolean storage
//! - **binary**: Fixed-size binary encodings (UUIDs, timestamps)

pub mod flags;
pub mod id;
pub mod semver;
pub mod siphash;

// Re-export commonly used types
pub use flags::{Flags32, Flags64};
pub use id::{HeaderKeyId, InstanceId, InterfaceId, MethodId, MetricId, ServiceId};
pub use semver::{PackedVersion, VersionError};
pub use uuid::Uuid;

/// Convert a UUID to the wire type
pub fn uuid_bytes(id: Uuid) -> bytes::Bytes {
    bytes::Bytes::copy_from_slice(id.as_bytes())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_integration_example() {
        // Interface ID from name
        let interface_id = siphash::hash_name_u32("mensa.user.v2.UserInterface");
        assert_ne!(interface_id, 0);

        // Version packing
        let version = semver::pack_version(2, 3, 1).unwrap();
        assert_eq!(version.as_u32(), 2_003_001);

        // Flags
        let mut flags = Flags64::new();
        flags.set(0, true);
        assert!(flags.get(0));

        // UUID
        let uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap();
        assert_eq!(uuid.as_bytes().len(), 16);
    }
}