Skip to content

Commit

Permalink
Add support for writing commit metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsabadie-datadog committed Sep 27, 2021
1 parent 12e9aca commit 5bf252a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/topic_partition_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ impl<'a> TopicPartitionListElem<'a> {
let slice: &[u8] = unsafe { ptr_to_slice(self.ptr.metadata, self.ptr.metadata_size) };
from_utf8(slice).map_err(|_| KafkaError::NonUTF8CommitMetadata)
}

/// Set the metadata.
pub fn set_metadata(&mut self, metadata: impl AsRef<str>) {
let metadata = metadata.as_ref();

unsafe {
self.ptr.metadata =
libc::strndup(metadata.as_ptr() as *const _, metadata.len()) as *mut _;
self.ptr.metadata_size = libc::strlen(self.ptr.metadata as *const _);
}
}
}

impl<'a> PartialEq for TopicPartitionListElem<'a> {
Expand Down

0 comments on commit 5bf252a

Please sign in to comment.