diff --git a/Cargo.lock b/Cargo.lock index c36a369..37464f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -694,12 +694,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "half" -version = "1.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" - [[package]] name = "hashbrown" version = "0.14.5" @@ -795,12 +789,6 @@ dependencies = [ "serde", ] -[[package]] -name = "iter-read" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c397ca3ea05ad509c4ec451fea28b4771236a376ca1c69fd5143aae0cf8f93c4" - [[package]] name = "itertools" version = "0.10.5" @@ -1862,29 +1850,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-pickle" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c762ad136a26407c6a80825813600ceeab5e613660d93d79a41f0ec877171e71" -dependencies = [ - "byteorder", - "iter-read", - "num-bigint", - "num-traits", - "serde", -] - -[[package]] -name = "serde_cbor" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" -dependencies = [ - "half", - "serde", -] - [[package]] name = "serde_derive" version = "1.0.210" @@ -2789,7 +2754,7 @@ dependencies = [ [[package]] name = "zenoh" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "ahash", "async-trait", @@ -2807,10 +2772,7 @@ dependencies = [ "rand", "rustc_version", "serde", - "serde-pickle", - "serde_cbor", "serde_json", - "serde_yaml", "socket2", "tokio", "tokio-util", @@ -2857,7 +2819,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "zenoh-collections", ] @@ -2865,7 +2827,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "tracing", "uhlc 0.8.0", @@ -2876,12 +2838,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" [[package]] name = "zenoh-config" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "json5", "num_cpus", @@ -2902,7 +2864,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "lazy_static", "tokio", @@ -2913,7 +2875,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "aes", "hmac", @@ -2926,7 +2888,7 @@ dependencies = [ [[package]] name = "zenoh-ext" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "bincode", "flume", @@ -2943,7 +2905,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "hashbrown", "keyed-set", @@ -2957,7 +2919,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "zenoh-config", "zenoh-link-commons", @@ -2974,7 +2936,7 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "flume", @@ -2997,7 +2959,7 @@ dependencies = [ [[package]] name = "zenoh-link-quic" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "base64 0.22.1", @@ -3022,7 +2984,7 @@ dependencies = [ [[package]] name = "zenoh-link-tcp" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "socket2", @@ -3039,7 +3001,7 @@ dependencies = [ [[package]] name = "zenoh-link-tls" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "base64 0.22.1", @@ -3066,7 +3028,7 @@ dependencies = [ [[package]] name = "zenoh-link-udp" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "socket2", @@ -3085,7 +3047,7 @@ dependencies = [ [[package]] name = "zenoh-link-unixsock_stream" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "nix", @@ -3103,7 +3065,7 @@ dependencies = [ [[package]] name = "zenoh-link-ws" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "futures-util", @@ -3123,7 +3085,7 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "proc-macro2", "quote", @@ -3134,7 +3096,7 @@ dependencies = [ [[package]] name = "zenoh-plugin-trait" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "git-version", "libloading", @@ -3150,7 +3112,7 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "const_format", "rand", @@ -3164,7 +3126,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "anyhow", ] @@ -3172,7 +3134,7 @@ dependencies = [ [[package]] name = "zenoh-runtime" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "lazy_static", "ron", @@ -3185,7 +3147,7 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "event-listener", "futures", @@ -3198,7 +3160,7 @@ dependencies = [ [[package]] name = "zenoh-task" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "futures", "tokio", @@ -3211,7 +3173,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "crossbeam-utils", @@ -3244,7 +3206,7 @@ dependencies = [ [[package]] name = "zenoh-util" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "const_format", @@ -3269,7 +3231,7 @@ dependencies = [ [[package]] name = "zenoh_backend_traits" version = "1.0.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#d3768b87d23599f791af2de0c0d8fbe41f079431" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#bdb01fb0ea39ba7849ebf4cb87495f81368bcc94" dependencies = [ "async-trait", "const_format", diff --git a/src/lib.rs b/src/lib.rs index cf05d45..d5b41ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,13 +18,12 @@ use async_trait::async_trait; use rocksdb::{ColumnFamilyDescriptor, Options, WriteBatch, DB}; use tokio::sync::Mutex; use tracing::{debug, error, trace, warn}; -use uhlc::NTP64; use zenoh::{ bytes::{Encoding, ZBytes}, - internal::{bail, zenoh_home, zerror, Value}, + internal::{bail, buffers::ZSlice, zenoh_home, zerror, Value}, key_expr::OwnedKeyExpr, query::Parameters, - time::Timestamp, + time::{Timestamp, TimestampId, NTP64}, try_init_log_from_env, Error, Result as ZResult, }; use zenoh_backend_traits::{ @@ -500,16 +499,68 @@ fn get_kv(db: &DB, key: Option) -> ZResult); + +impl DataInfo { + pub fn as_tuple(&self) -> DataInfoTuple { + let timestamp_time = self.timestamp.get_time().as_u64(); + let timestamp_id = self.timestamp.get_id().to_le_bytes(); + let encoding_id = self.encoding.id(); + let encoding_schema = self + .encoding + .schema() + .map(|s| s.to_vec()) + .unwrap_or_default(); + let deleted = self.deleted; + ( + timestamp_time, + timestamp_id, + deleted, + encoding_id, + encoding_schema, + ) + } + pub fn from_tuple( + (timestamp_time, timestamp_id, deleted, encoding_id, encoding_schema): DataInfoTuple, + ) -> ZResult { + let timestamp_id = TimestampId::try_from(timestamp_id)?; + let timestamp = Timestamp::new(NTP64(timestamp_time), timestamp_id); + let encoding_schema = if encoding_schema.is_empty() { + None + } else { + Some(ZSlice::from(encoding_schema)) + }; + let encoding = Encoding::new(encoding_id, encoding_schema); + Ok(DataInfo { + timestamp, + deleted, + encoding, + }) + } +} + fn encode_data_info(encoding: Encoding, timestamp: &Timestamp, deleted: bool) -> ZResult> { - let bytes = z_serialize(&(encoding, deleted, timestamp)); + let data_info = DataInfo { + timestamp: *timestamp, + deleted, + encoding, + }; + let bytes = z_serialize(&data_info.as_tuple()); Ok(bytes.to_bytes().into_owned()) } fn decode_data_info(buf: &[u8]) -> ZResult<(Encoding, Timestamp, bool)> { let bytes = ZBytes::from(buf); - let (encoding, deleted, timestamp) = z_deserialize(&bytes) + let tuple: DataInfoTuple = z_deserialize(&bytes) .map_err(|_| zerror!("Failed to decode data-info (encoding, deleted, timestamp)"))?; - Ok((encoding, timestamp, deleted)) + let data_info = DataInfo::from_tuple(tuple)?; + Ok((data_info.encoding, data_info.timestamp, data_info.deleted)) } fn rocksdb_err_to_zerr(err: rocksdb::Error) -> Error {