pub struct BorrowedMessage<'a> { /* private fields */ }
Expand description

A zero-copy Kafka message.

Provides a read-only access to headers owned by a Kafka consumer or producer or by an OwnedMessage struct.

§Consumers

BorrowedMessages coming from consumers are removed from the consumer buffer once they are dropped. Holding references to too many messages will cause the memory of the consumer to fill up and the consumer to block until some of the BorrowedMessages are dropped.

§Conversion to owned

To transform a BorrowedMessage into a OwnedMessage, use the detach method.

Implementations§

source§

impl<'a> BorrowedMessage<'a>

source

pub fn ptr(&self) -> *mut RDKafkaMessage

Returns a pointer to the RDKafkaMessage.

source

pub fn topic_ptr(&self) -> *mut RDKafkaTopic

Returns a pointer to the message’s RDKafkaTopic

source

pub fn key_len(&self) -> usize

Returns the length of the key field of the message.

source

pub fn payload_len(&self) -> usize

Returns the length of the payload field of the message.

source

pub fn detach(&self) -> OwnedMessage

Clones the content of the BorrowedMessage and returns an OwnedMessage that can outlive the consumer.

This operation requires memory allocation and can be expensive.

Trait Implementations§

source§

impl<'a> Debug for BorrowedMessage<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Message for BorrowedMessage<'a>

§

type Headers = BorrowedHeaders

The type of headers that this message contains.
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. Read more
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<&BorrowedHeaders>

Returns the headers of the message, or None if there are no headers.
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.
source§

impl<'a> Send for BorrowedMessage<'a>

source§

impl<'a> Sync for BorrowedMessage<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for BorrowedMessage<'a>

§

impl<'a> Unpin for BorrowedMessage<'a>

§

impl<'a> UnwindSafe for BorrowedMessage<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more