diff --git a/Cargo.lock b/Cargo.lock index 4d5cfce..a0c136e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -1205,7 +1205,7 @@ dependencies = [ [[package]] name = "iggy-py" -version = "0.2.5" +version = "0.2.6" dependencies = [ "bytes", "iggy", diff --git a/src/lib.rs b/src/lib.rs index 0ac0648..b2ead09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ mod topic; use client::IggyClient; use pyo3::prelude::*; -use receive_message::{PollingStrategy, ReceiveMessage}; +use receive_message::{MessageState, PollingStrategy, ReceiveMessage}; use send_message::SendMessage; use stream::StreamDetails; use topic::TopicDetails; @@ -20,5 +20,6 @@ fn iggy_py(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; Ok(()) } diff --git a/src/receive_message.rs b/src/receive_message.rs index 006ace9..9c231c8 100644 --- a/src/receive_message.rs +++ b/src/receive_message.rs @@ -1,4 +1,5 @@ use iggy::messages::poll_messages::PollingStrategy as RustPollingStrategy; +use iggy::models::messages::MessageState as RustMessageState; use iggy::models::messages::PolledMessage as RustReceiveMessage; use pyo3::prelude::*; use pyo3::types::PyBytes; @@ -20,6 +21,15 @@ impl ReceiveMessage { } } +#[pyclass(eq, eq_int)] +#[derive(PartialEq)] +pub enum MessageState { + Available, + Unavailable, + Poisoned, + MarkedForDeletion, +} + #[pymethods] impl ReceiveMessage { /// Retrieves the payload of the received message. @@ -35,6 +45,46 @@ impl ReceiveMessage { pub fn offset(&self) -> u64 { self.inner.offset } + + /// Retrieves the timestamp of the received message. + /// + /// The timestamp represents the time of the message within its topic. + pub fn timestamp(&self) -> u64 { + self.inner.timestamp + } + + /// Retrieves the id of the received message. + /// + /// The id represents unique identifier of the message within its topic. + pub fn id(&self) -> u128 { + self.inner.id + } + + /// Retrieves the checksum of the received message. + /// + /// The checksum represents the integrity of the message within its topic. + pub fn checksum(&self) -> u32 { + self.inner.checksum + } + + /// Retrieves the Message's state of the received message. + /// + /// State represents the state of the response. + pub fn state(&self) -> MessageState { + match self.inner.state { + RustMessageState::Available => MessageState::Available, + RustMessageState::Unavailable => MessageState::Unavailable, + RustMessageState::Poisoned => MessageState::Poisoned, + RustMessageState::MarkedForDeletion => MessageState::MarkedForDeletion, + } + } + + /// Retrieves the length of the received message. + /// + /// The length represents the length of the payload. + pub fn length(&self) -> u32 { + self.inner.length + } } #[derive(Clone, Copy)]