Skip to content

Commit

Permalink
Merge pull request #351 from ZettaScaleLabs/feat/new_serialization
Browse files Browse the repository at this point in the history
new serializer API Update
  • Loading branch information
milyin authored Oct 1, 2024
2 parents c499491 + eb7394f commit 58c1c73
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 43 deletions.
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, <[email protected]>
//
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

0 comments on commit 58c1c73

Please sign in to comment.