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

new serializer API Update #351

Merged
merged 3 commits into from
Oct 1, 2024
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
68 changes: 34 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions zenoh-plugin-dds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//
use std::{
borrow::Cow,
collections::HashMap,
env,
future::Future,
Expand Down Expand Up @@ -698,8 +697,9 @@ impl<'a> DdsPluginRuntime<'a> {
// send replies
for (ke, v) in kvs.drain(..) {
let admin_keyexpr = admin_keyexpr_prefix / &ke;
match ZBytes::try_from(v) {
Ok(payload) => {
match serde_json::to_vec(&v) {
Ok(vec_u8) => {
let payload = ZBytes::from(vec_u8);
if let Err(e) = query
.reply(admin_keyexpr, payload)
.encoding(Encoding::APPLICATION_JSON)
Expand All @@ -708,9 +708,7 @@ impl<'a> DdsPluginRuntime<'a> {
warn!("Error replying to admin query {:?}: {}", query, e);
}
}
Err(e) => {
warn!("Error transforming JSON to admin query {:?}: {}", query, e);
}
Err(e) => warn!("Error transforming JSON to admin query {:?}: {}", query, e),
}
}
}
Expand Down Expand Up @@ -1212,7 +1210,7 @@ impl<'a> DdsPluginRuntime<'a> {
let full_admin_keyexpr = *KE_PREFIX_ADMIN_SPACE / remote_uuid / *KE_PREFIX_DDS / remaining_ke;
if sample.kind() != SampleKind::Delete {
// deserialize payload
let (entity, scope) = match bincode::deserialize::<(DdsEntity, Option<OwnedKeyExpr>)>(&sample.payload().into::<Cow<[u8]>>()) {
let (entity, scope) = match bincode::deserialize::<(DdsEntity, Option<OwnedKeyExpr>)>(&sample.payload().to_bytes()) {
Ok(x) => x,
Err(e) => {
warn!("Failed to deserialize discovery msg for {}: {}", full_admin_keyexpr, e);
Expand Down Expand Up @@ -1292,7 +1290,7 @@ impl<'a> DdsPluginRuntime<'a> {
let full_admin_keyexpr = *KE_PREFIX_ADMIN_SPACE / remote_uuid / *KE_PREFIX_DDS / remaining_ke;
if sample.kind() != SampleKind::Delete {
// deserialize payload
let (entity, scope) = match bincode::deserialize::<(DdsEntity, Option<OwnedKeyExpr>)>(&sample.payload().into::<Cow<[u8]>>()) {
let (entity, scope) = match bincode::deserialize::<(DdsEntity, Option<OwnedKeyExpr>)>(&sample.payload().to_bytes()) {
Ok(x) => x,
Err(e) => {
warn!("Failed to deserialize discovery msg for {}: {}", full_admin_keyexpr, e);
Expand Down
2 changes: 1 addition & 1 deletion zenoh-plugin-dds/src/route_zenoh_dds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ fn do_route_data(s: Sample, topic_name: &str, data_writer: dds_entity_t) {
}

unsafe {
let bs = s.payload().into();
let bs = s.payload().to_bytes().to_vec();
// As per the Vec documentation (see https://doc.rust-lang.org/std/vec/struct.Vec.html#method.into_raw_parts)
// the only way to correctly releasing it is to create a vec using from_raw_parts
// and then have its destructor do the cleanup.
Expand Down