Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
p-avital committed Mar 8, 2024
1 parent 769d824 commit 1b09b30
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
9 changes: 1 addition & 8 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,6 @@ typedef struct z_owned_closure_reply_t {
* A data sample.
*
* A sample is the value associated to a given resource at a given point in time.
*
* Members:
* z_keyexpr_t keyexpr: The resource key of this data sample.
* z_bytes_t payload: The value of this data sample.
* z_encoding_t encoding: The encoding of the value of this data sample.
* z_sample_kind_t kind: The kind of this data sample (PUT or DELETE).
* z_timestamp_t timestamp: The timestamp of this data sample.
* z_attachment_t attachment: The attachment of this data sample.
*/
typedef struct z_sample_t {
const void *_inner;
Expand Down Expand Up @@ -2503,6 +2495,7 @@ ZENOHC_API void zc_sample_drop(struct zc_owned_sample_t *sample);
* Calling this function using a dropped sample is undefined behaviour.
*/
ZENOHC_API struct z_sample_t zc_sample_loan(const struct zc_owned_sample_t *sample);
ZENOHC_API struct zc_owned_sample_t zc_sample_null(void);
/**
* Increments the session's reference count, returning a new owning handle.
*/
Expand Down
16 changes: 5 additions & 11 deletions src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ pub extern "C" fn z_qos_default() -> z_qos_t {
/// A data sample.
///
/// A sample is the value associated to a given resource at a given point in time.
///
/// Members:
/// z_keyexpr_t keyexpr: The resource key of this data sample.
/// z_bytes_t payload: The value of this data sample.
/// z_encoding_t encoding: The encoding of the value of this data sample.
/// z_sample_kind_t kind: The kind of this data sample (PUT or DELETE).
/// z_timestamp_t timestamp: The timestamp of this data sample.
/// z_attachment_t attachment: The attachment of this data sample.
#[repr(C)]
pub struct z_sample_t<'a> {
_inner: &'a (),
Expand All @@ -177,9 +169,6 @@ impl<'a> core::ops::Deref for z_sample_t<'a> {

impl<'a> z_sample_t<'a> {
pub fn new(sample: &'a Sample) -> Self {
if !sample.value.payload.zslices().count() <= 1 {
panic!("Attempted to construct z_sample_t from discontiguous buffer, this is definitely a bug in zenoh-c, please report it.")
};
z_sample_t {
_inner: unsafe { core::mem::transmute(sample) },
}
Expand Down Expand Up @@ -285,6 +274,11 @@ pub extern "C" fn zc_sample_drop(sample: &mut zc_owned_sample_t) {
core::mem::drop(sample.take());
}

#[no_mangle]
pub extern "C" fn zc_sample_null() -> zc_owned_sample_t {
None.into()
}

/// A :c:type:`z_encoding_t` integer `prefix`.
///
/// - **Z_ENCODING_PREFIX_EMPTY**
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ trait GuardedTransmute<D> {
fn transmute(self) -> D;
}

/// For internal use only.
///
/// This macro is used to establish the equivalence between a Rust type (first parameter) and a C layout (second parameter).
///
/// It automatically implements `From`, `Deref` and `DerefMut` to make writing code around these equivalent types.
///
/// Because carrying around the proper semantics of lifetimes is hard, this macro fails to produce working code when lifetimes are
/// present in either parameter. You may then call it with the `noderefs` prefix to avoid the offending implementations being defined.
#[macro_export]
macro_rules! impl_guarded_transmute {
($src_type:ty, $dst_type:ty) => {
Expand Down

0 comments on commit 1b09b30

Please sign in to comment.