Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add default encoding for publisher #520

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ typedef struct z_owned_closure_zid_t {
* Options passed to the `z_declare_publisher()` function.
*/
typedef struct z_publisher_options_t {
/**
* Default encoding for messages put by this publisher.
*/
struct z_owned_encoding_t *encoding;
/**
* The congestion control to apply when routing messages from this publisher.
*/
Expand Down
12 changes: 11 additions & 1 deletion src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// ZettaScale Zenoh team, <zenoh@zettascale.tech>
//

use std::{mem::MaybeUninit, ptr};
use std::{
mem::MaybeUninit,
ptr::{self, null_mut},
};

use zenoh::{
prelude::*,
Expand All @@ -32,6 +35,8 @@ use crate::{
/// Options passed to the `z_declare_publisher()` function.
#[repr(C)]
pub struct z_publisher_options_t {
/// Default encoding for messages put by this publisher.
pub encoding: *mut z_owned_encoding_t,
/// The congestion control to apply when routing messages from this publisher.
pub congestion_control: z_congestion_control_t,
/// The priority of messages from this publisher.
Expand All @@ -46,6 +51,7 @@ pub struct z_publisher_options_t {
#[no_mangle]
pub extern "C" fn z_publisher_options_default(this: &mut z_publisher_options_t) {
*this = z_publisher_options_t {
encoding: null_mut(),
congestion_control: CongestionControl::default().into(),
priority: Priority::default().into(),
is_express: false,
Expand Down Expand Up @@ -89,6 +95,10 @@ pub extern "C" fn z_declare_publisher(
.priority(options.priority.into())
.express(options.is_express)
.allowed_destination(options.allowed_destination.into());
if let Some(encoding) = unsafe { options.encoding.as_mut() } {
let encoding = std::mem::take(encoding.as_rust_type_mut());
p = p.encoding(encoding);
}
}
match p.wait() {
Err(e) => {
Expand Down