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 23, 2021
1 parent 4b7fe5e commit a1f1549
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).expect("metadata is not UTF-8")
}

/// 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 a1f1549

Please sign in to comment.