hanabi-core 0.1.0-alpha.2

Core library for Hanabi
Documentation
use std::num::NonZeroU64;

#[derive(Debug, Clone, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
pub struct Message {
    metadata: MessageMetadata,
    data: bytes::Bytes,
}

impl Message {
    pub fn new(metadata: MessageMetadata, data: bytes::Bytes) -> Self {
        Self { metadata, data }
    }

    pub fn metadata(&self) -> &MessageMetadata {
        &self.metadata
    }

    pub fn data(&self) -> &bytes::Bytes {
        &self.data
    }
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
pub struct MessageMetadata {
    topic: String,
    timestamp: NonZeroU64,
}

impl MessageMetadata {
    pub fn new(topic: String, timestamp: NonZeroU64) -> Self {
        Self { topic, timestamp }
    }

    pub fn topic(&self) -> &str {
        &self.topic
    }

    pub fn timestamp(&self) -> NonZeroU64 {
        self.timestamp
    }
}