Skip to content

Commit

Permalink
Encoding and timestamp serialization remove from zenoh-ext (#1520)
Browse files Browse the repository at this point in the history
* serialized typeencoding  added, basic types and replyerror encoding removed

* encoding and timestamp serialization removed

* number changed, unused mappings removed

* cargo fmt

* clippy fix

* unused crates removed

* cargo toml corrected

* cargo toml correction

* use fix

* doc fixed, excessive test removed

* use removed

* renumbered constants
  • Loading branch information
milyin authored Oct 9, 2024
1 parent b1f237d commit bdb01fb
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 579 deletions.
40 changes: 1 addition & 39 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ secrecy = { version = "0.8.0", features = ["serde", "alloc"] }
serde = { version = "1.0.210", default-features = false, features = [
"derive",
] } # Default features are disabled due to usage in no_std crates
serde_cbor = "0.11.2"
serde_json = "1.0.128"
serde-pickle = "1.1.1"
serde_yaml = "0.9.34"
static_init = "1.0.3"
stabby = "36.1.1"
Expand Down
79 changes: 1 addition & 78 deletions zenoh-ext/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ use std::{
io::{Read, Write},
marker::PhantomData,
mem::MaybeUninit,
str::FromStr,
};

use zenoh::{
bytes::{Encoding, ZBytes, ZBytesReader, ZBytesWriter},
time::{Timestamp, TimestampId, NTP64},
};
use zenoh::bytes::{ZBytes, ZBytesReader, ZBytesWriter};

#[derive(Debug)]
pub struct ZDeserializeError;
Expand Down Expand Up @@ -461,66 +457,6 @@ impl Deserialize for VarInt<usize> {
}
}

//
// Serialization/deserialization for zenoh types
//

impl Serialize for NTP64 {
fn serialize(&self, serializer: &mut ZSerializer) {
let time = self.as_u64();
time.serialize(serializer);
}
}

impl Deserialize for NTP64 {
fn deserialize(deserializer: &mut ZDeserializer) -> Result<Self, ZDeserializeError> {
let time = u64::deserialize(deserializer)?;
Ok(NTP64(time))
}
}

impl Serialize for TimestampId {
fn serialize(&self, serializer: &mut ZSerializer) {
self.to_le_bytes().serialize(serializer);
}
}

impl Deserialize for TimestampId {
fn deserialize(deserializer: &mut ZDeserializer) -> Result<Self, ZDeserializeError> {
let id = Vec::<u8>::deserialize(deserializer)?;
let id = id.as_slice().try_into().map_err(|_| ZDeserializeError)?;
Ok(id)
}
}

impl Serialize for Timestamp {
fn serialize(&self, serializer: &mut ZSerializer) {
self.get_time().serialize(serializer);
self.get_id().serialize(serializer);
}
}

impl Deserialize for Timestamp {
fn deserialize(deserializer: &mut ZDeserializer) -> Result<Self, ZDeserializeError> {
let time = NTP64::deserialize(deserializer)?;
let id = TimestampId::deserialize(deserializer)?;
Ok(Timestamp::new(time, id))
}
}

impl Serialize for Encoding {
fn serialize(&self, serializer: &mut ZSerializer) {
self.to_string().serialize(serializer);
}
}

impl Deserialize for Encoding {
fn deserialize(deserializer: &mut ZDeserializer) -> Result<Self, ZDeserializeError> {
let encoding = String::deserialize(deserializer)?;
Encoding::from_str(&encoding).map_err(|_| ZDeserializeError)
}
}

#[cfg(test)]
mod tests {
use std::ops::Range;
Expand Down Expand Up @@ -603,17 +539,4 @@ mod tests {
map.insert("hello".to_string(), "world".to_string());
serialize_deserialize!(HashMap<String, String>, map);
}

#[test]
fn timestamp_serialization() {
use std::time::{SystemTime, UNIX_EPOCH};
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().into();
serialize_deserialize!(Timestamp, Timestamp::new(now, TimestampId::rand()));
}

#[test]
fn encoding_serialization() {
serialize_deserialize!(Encoding, Encoding::TEXT_JSON);
serialize_deserialize!(Encoding, Encoding::from_str("text/plain;foobar").unwrap());
}
}
3 changes: 0 additions & 3 deletions zenoh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ petgraph = { workspace = true }
phf = { workspace = true }
rand = { workspace = true, features = ["default"] }
serde = { workspace = true, features = ["default"] }
serde_cbor = { workspace = true }
serde_json = { workspace = true }
serde-pickle = { workspace = true }
serde_yaml = { workspace = true }
socket2 = { workspace = true }
uhlc = { workspace = true, features = ["default"] }
vec_map = { workspace = true }
Expand Down
Loading

0 comments on commit bdb01fb

Please sign in to comment.