Trait rdkafka::message::Message

source ·
pub trait Message {
    type Headers: Headers;

    // Required methods
    fn key(&self) -> Option<&[u8]>;
    fn payload(&self) -> Option<&[u8]>;
    unsafe fn payload_mut(&mut self) -> Option<&mut [u8]>;
    fn topic(&self) -> &str;
    fn partition(&self) -> i32;
    fn offset(&self) -> i64;
    fn timestamp(&self) -> Timestamp;
    fn headers(&self) -> Option<&Self::Headers>;

    // Provided methods
    fn payload_view<P: ?Sized + FromBytes>(
        &self,
    ) -> Option<Result<&P, P::Error>> { ... }
    fn key_view<K: ?Sized + FromBytes>(&self) -> Option<Result<&K, K::Error>> { ... }
}
Expand description

A generic representation of a Kafka message.

Only read-only methods are provided by this trait, as the underlying storage might not allow modification.

Required Associated Types§

source

type Headers: Headers

The type of headers that this message contains.

Required Methods§

source

fn key(&self) -> Option<&[u8]>

Returns the key of the message, or None if there is no key.

source

fn payload(&self) -> Option<&[u8]>

Returns the payload of the message, or None if there is no payload.

source

unsafe fn payload_mut(&mut self) -> Option<&mut [u8]>

Returns a mutable reference to the payload of the message, or None if there is no payload.

§Safety

librdkafka does not formally guarantee that modifying the payload is safe. Calling this method may therefore result in undefined behavior.

source

fn topic(&self) -> &str

Returns the source topic of the message.

source

fn partition(&self) -> i32

Returns the partition number where the message is stored.

source

fn offset(&self) -> i64

Returns the offset of the message within the partition.

source

fn timestamp(&self) -> Timestamp

Returns the message timestamp.

source

fn headers(&self) -> Option<&Self::Headers>

Returns the headers of the message, or None if there are no headers.

Provided Methods§

source

fn payload_view<P: ?Sized + FromBytes>(&self) -> Option<Result<&P, P::Error>>

Converts the raw bytes of the payload to a reference of the specified type, that points to the same data inside the message and without performing any memory allocation.

source

fn key_view<K: ?Sized + FromBytes>(&self) -> Option<Result<&K, K::Error>>

Converts the raw bytes of the key to a reference of the specified type, that points to the same data inside the message and without performing any memory allocation.

Object Safety§

This trait is not object safe.

Implementors§