Skip to content

Commit

Permalink
serialization support for bool
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Oct 4, 2024
1 parent e305a9e commit 7d54ccb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Functions
.. doxygenfunction:: ze_serialize_int64
.. doxygenfunction:: ze_serialize_float
.. doxygenfunction:: ze_serialize_double
.. doxygenfunction:: ze_serialize_bool

.. doxygenfunction:: ze_deserialize_slice
.. doxygenfunction:: ze_deserialize_string
Expand All @@ -145,6 +146,7 @@ Functions
.. doxygenfunction:: ze_deserialize_int64
.. doxygenfunction:: ze_deserialize_float
.. doxygenfunction:: ze_deserialize_double
.. doxygenfunction:: ze_deserialize_bool

.. doxygenfunction:: z_bytes_empty
.. doxygenfunction:: z_bytes_clone
Expand Down Expand Up @@ -179,6 +181,7 @@ Functions
.. doxygenfunction:: ze_serializer_serialize_int64
.. doxygenfunction:: ze_serializer_serialize_float
.. doxygenfunction:: ze_serializer_serialize_double
.. doxygenfunction:: ze_serializer_serialize_bool
.. doxygenfunction:: ze_serializer_serialize_sequence_length

.. doxygenfunction:: ze_deserializer_from_bytes
Expand All @@ -195,6 +198,7 @@ Functions
.. doxygenfunction:: ze_deserializer_deserialize_int64
.. doxygenfunction:: ze_deserializer_deserialize_float
.. doxygenfunction:: ze_deserializer_deserialize_double
.. doxygenfunction:: ze_deserializer_deserialize_bool
.. doxygenfunction:: ze_deserializer_deserialize_sequence_length


Expand Down
18 changes: 18 additions & 0 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -5245,6 +5245,11 @@ z_result_t ze_declare_querying_subscriber(ze_owned_querying_subscriber_t *this_,
struct z_moved_closure_sample_t *callback,
struct ze_querying_subscriber_options_t *options);
#endif
/**
* @brief Deserializes into a bool.
* @return 0 in case of success, negative error code otherwise.
*/
ZENOHC_API z_result_t ze_deserialize_bool(const struct z_loaned_bytes_t *this_, bool *dst);
/**
* @brief Deserializes into a signed integer.
* @return 0 in case of success, negative error code otherwise.
Expand Down Expand Up @@ -5307,6 +5312,11 @@ ZENOHC_API z_result_t ze_deserialize_uint64(const struct z_loaned_bytes_t *this_
* @return 0 in case of success, negative error code otherwise.
*/
ZENOHC_API z_result_t ze_deserialize_uint8(const struct z_loaned_bytes_t *this_, uint8_t *dst);
/**
* @brief Deserializes into a bool.
* @return 0 in case of success, negative error code otherwise.
*/
ZENOHC_API z_result_t ze_deserializer_deserialize_bool(struct ze_deserializer_t *this_, bool *dst);
/**
* @brief Deserializes into a signed integer.
* @return 0 in case of success, negative error code otherwise.
Expand Down Expand Up @@ -5515,6 +5525,10 @@ const ze_loaned_querying_subscriber_t *ze_querying_subscriber_loan(const ze_owne
ZENOHC_API
void ze_querying_subscriber_options_default(struct ze_querying_subscriber_options_t *this_);
#endif
/**
* @brief Serializes a bool.
*/
ZENOHC_API void ze_serialize_bool(struct z_owned_bytes_t *this_, bool val);
/**
* @brief Serializes a data from buffer by.
* @param this_: An uninitialized location in memory where `z_owned_bytes_t` is to be constructed.
Expand Down Expand Up @@ -5610,6 +5624,10 @@ const struct ze_loaned_serializer_t *ze_serializer_loan(const struct ze_owned_se
*/
ZENOHC_API
struct ze_loaned_serializer_t *ze_serializer_loan_mut(struct ze_owned_serializer_t *this_);
/**
* @brief Serializes a bool.
*/
ZENOHC_API void ze_serializer_serialize_bool(struct ze_loaned_serializer_t *this_, bool val);
/**
* @brief Serializes a data from buffer.
* @param this_: A serializer instance.
Expand Down
29 changes: 29 additions & 0 deletions src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ pub extern "C" fn ze_serialize_double(this_: &mut MaybeUninit<z_owned_bytes_t>,
ze_serialize_arithmetic::<f64>(this_, &val);
}

/// @brief Serializes a bool.
#[no_mangle]
pub extern "C" fn ze_serialize_bool(this_: &mut MaybeUninit<z_owned_bytes_t>, val: bool) {
ze_serialize_arithmetic::<bool>(this_, &val);
}

/// @brief Deserializes into an unsigned integer.
/// @return 0 in case of success, negative error code otherwise.
#[no_mangle]
Expand Down Expand Up @@ -255,6 +261,13 @@ pub extern "C" fn ze_deserialize_double(this: &z_loaned_bytes_t, dst: &mut f64)
ze_deserialize_arithmetic::<f64>(this, dst)
}

/// @brief Deserializes into a bool.
/// @return 0 in case of success, negative error code otherwise.
#[no_mangle]
pub extern "C" fn ze_deserialize_bool(this: &z_loaned_bytes_t, dst: &mut bool) -> z_result_t {
ze_deserialize_arithmetic::<bool>(this, dst)
}

/// @brief Serializes a slice.
#[no_mangle]
#[allow(clippy::missing_safety_doc)]
Expand Down Expand Up @@ -452,6 +465,12 @@ pub extern "C" fn ze_serializer_serialize_double(this_: &mut ze_loaned_serialize
ze_serializer_serialize_arithmetic::<f64>(this_, &val);
}

/// @brief Serializes a bool.
#[no_mangle]
pub extern "C" fn ze_serializer_serialize_bool(this_: &mut ze_loaned_serializer_t, val: bool) {
ze_serializer_serialize_arithmetic::<bool>(this_, &val);
}

/// @brief Deserializes into an unsigned integer.
/// @return 0 in case of success, negative error code otherwise.
#[no_mangle]
Expand Down Expand Up @@ -552,6 +571,16 @@ pub extern "C" fn ze_deserializer_deserialize_double(
ze_deserializer_deserialize_arithmetic::<f64>(this, dst)
}

/// @brief Deserializes into a bool.
/// @return 0 in case of success, negative error code otherwise.
#[no_mangle]
pub extern "C" fn ze_deserializer_deserialize_bool(
this: &mut ze_deserializer_t,
dst: &mut bool,
) -> z_result_t {
ze_deserializer_deserialize_arithmetic::<bool>(this, dst)
}

/// @brief Serializes a slice.
#[no_mangle]
pub extern "C" fn ze_serializer_serialize_slice(
Expand Down

0 comments on commit 7d54ccb

Please sign in to comment.