diff --git a/commons/zenoh-codec/src/core/encoding.rs b/commons/zenoh-codec/src/core/encoding.rs index 8e8627d05a..4b2e2248c9 100644 --- a/commons/zenoh-codec/src/core/encoding.rs +++ b/commons/zenoh-codec/src/core/encoding.rs @@ -21,7 +21,7 @@ use zenoh_protocol::core::{Encoding, EncodingPrefix}; impl LCodec<&Encoding> for Zenoh080 { fn w_len(self, x: &Encoding) -> usize { - 1 + self.w_len(x.suffix()) + self.w_len(x.prefix()) + self.w_len(x.suffix()) } } @@ -34,6 +34,7 @@ where fn write(self, writer: &mut W, x: &Encoding) -> Self::Output { let zodec = Zenoh080Bounded::::new(); zodec.write(&mut *writer, x.prefix())?; + let zodec = Zenoh080Bounded::::new(); zodec.write(&mut *writer, x.suffix())?; Ok(()) } @@ -48,6 +49,7 @@ where fn read(self, reader: &mut R) -> Result { let zodec = Zenoh080Bounded::::new(); let prefix: EncodingPrefix = zodec.read(&mut *reader)?; + let zodec = Zenoh080Bounded::::new(); let suffix: String = zodec.read(&mut *reader)?; let mut encoding: Encoding = Encoding::new(prefix); diff --git a/plugins/zenoh-plugin-rest/src/lib.rs b/plugins/zenoh-plugin-rest/src/lib.rs index 94f1b64ca4..32148044c4 100644 --- a/plugins/zenoh-plugin-rest/src/lib.rs +++ b/plugins/zenoh-plugin-rest/src/lib.rs @@ -27,7 +27,7 @@ use std::sync::Arc; use tide::http::Mime; use tide::sse::Sender; use tide::{Request, Response, Server, StatusCode}; -use zenoh::encoding::EncodingMapping; +use zenoh::encoding::{DefaultEncodingMapping, EncodingMapping}; use zenoh::plugins::{RunningPluginTrait, ZenohPlugin}; use zenoh::prelude::r#async::*; use zenoh::properties::Properties; @@ -50,19 +50,19 @@ const RAW_KEY: &str = "_raw"; fn value_to_json(value: Value) -> String { // @TODO: transcode to JSON when implemented in Value match &value.encoding { - p if p.starts_with(DefaultEncoder::TEXT_PLAIN) - || p.starts_with(DefaultEncoder::APP_XWWW_FORM_URLENCODED) => + p if p.starts_with(DefaultEncoding::TEXT_PLAIN) + || p.starts_with(DefaultEncoding::APP_XWWW_FORM_URLENCODED) => { // convert to Json string for special characters escaping serde_json::json!(value.to_string()).to_string() } - p if p.starts_with(DefaultEncoder::APP_PROPERTIES) => { + p if p.starts_with(DefaultEncoding::APP_PROPERTIES) => { // convert to Json string for special characters escaping serde_json::json!(*Properties::from(value.to_string())).to_string() } - p if p.starts_with(DefaultEncoder::APP_JSON) - || p.starts_with(DefaultEncoder::APP_INTEGER) - || p.starts_with(DefaultEncoder::APP_FLOAT) => + p if p.starts_with(DefaultEncoding::APP_JSON) + || p.starts_with(DefaultEncoding::APP_INTEGER) + || p.starts_with(DefaultEncoding::APP_FLOAT) => { value.to_string() } @@ -404,7 +404,7 @@ async fn query(mut req: Request<(Arc, String)>) -> tide::Result match DefaultEncoder::parse(m.to_string().as_str()) { + Some(m) => match DefaultEncodingMapping::parse(m.to_string().as_str()) { Ok(e) => e, Err(e) => { return Ok(response( @@ -453,7 +453,7 @@ async fn write(mut req: Request<(Arc, String)>) -> tide::Result match DefaultEncoder::parse(m.to_string().as_str()) { + Some(m) => match DefaultEncodingMapping::parse(m.to_string().as_str()) { Ok(e) => e, Err(e) => { return Ok(response( diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs b/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs index f196bd6e50..964c6f77da 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs @@ -22,7 +22,7 @@ use std::collections::{HashMap, HashSet}; use std::str::{self, FromStr}; use std::time::{SystemTime, UNIX_EPOCH}; use zenoh::buffers::ZBuf; -use zenoh::encoding::EncodingMapping; +use zenoh::encoding::{DefaultEncodingMapping, EncodingMapping}; use zenoh::prelude::r#async::*; use zenoh::query::ConsolidationMode; use zenoh::time::{Timestamp, NTP64}; @@ -694,7 +694,8 @@ fn construct_update(data: String) -> Update { for slice in result.3 { payload.push_zslice(slice.to_vec().into()); } - let value = Value::new(payload).encoding(DefaultEncoder::parse(result.2.as_str()).unwrap()); // @TODO: remove the unwrap() + let value = + Value::new(payload).encoding(DefaultEncodingMapping::parse(result.2.as_str()).unwrap()); // @TODO: remove the unwrap() let data = StoredData { value, timestamp: Timestamp::from_str(&result.1).unwrap(), // @TODO: remove the unwrap() diff --git a/zenoh/src/admin.rs b/zenoh/src/admin.rs index ff300b1a5e..d5f0d47886 100644 --- a/zenoh/src/admin.rs +++ b/zenoh/src/admin.rs @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // use crate::{ - encoding::DefaultEncoder, + encoding::DefaultEncoding, keyexpr, prelude::sync::{KeyExpr, Locality, SampleKind}, queryable::Query, @@ -143,7 +143,7 @@ impl TransportMulticastEventHandler for Handler { let expr = WireExpr::from(&(*KE_PREFIX / own_zid / *KE_TRANSPORT_UNICAST / zid)) .to_owned(); let info = DataInfo { - encoding: Some(DefaultEncoder::APP_JSON), + encoding: Some(DefaultEncoding::APP_JSON), ..Default::default() }; self.session.handle_data( @@ -189,7 +189,7 @@ impl TransportPeerEventHandler for PeerHandler { let mut s = DefaultHasher::new(); link.hash(&mut s); let info = DataInfo { - encoding: Some(DefaultEncoder::APP_JSON), + encoding: Some(DefaultEncoding::APP_JSON), ..Default::default() }; self.session.handle_data( diff --git a/zenoh/src/encoding.rs b/zenoh/src/encoding.rs index 4ee9da419b..a042e4295e 100644 --- a/zenoh/src/encoding.rs +++ b/zenoh/src/encoding.rs @@ -31,15 +31,9 @@ pub trait EncodingMapping { S: Into; } -/// Default encoder provided with Zenoh to facilitate the encoding and decoding -/// of Values in the Rust API. Please note that Zenoh does not impose any -/// encoding and users are free to use any encoder they like. -#[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct DefaultEncoder; +pub struct DefaultEncodingMapping; -pub struct DefaultMapping; - -impl DefaultMapping { +impl DefaultEncodingMapping { pub const EMPTY: EncodingPrefix = 0; pub const APP_OCTET_STREAM: EncodingPrefix = 1; pub const APP_CUSTOM: EncodingPrefix = 2; @@ -61,30 +55,6 @@ impl DefaultMapping { pub const IMAGE_JPEG: EncodingPrefix = 18; pub const IMAGE_PNG: EncodingPrefix = 19; pub const IMAGE_GIF: EncodingPrefix = 20; -} - -impl DefaultEncoder { - pub const EMPTY: Encoding = Encoding::new(DefaultMapping::EMPTY); - pub const APP_OCTET_STREAM: Encoding = Encoding::new(DefaultMapping::APP_OCTET_STREAM); - pub const APP_CUSTOM: Encoding = Encoding::new(2); - pub const TEXT_PLAIN: Encoding = Encoding::new(3); - pub const APP_PROPERTIES: Encoding = Encoding::new(4); - pub const APP_JSON: Encoding = Encoding::new(5); - pub const APP_SQL: Encoding = Encoding::new(6); - pub const APP_INTEGER: Encoding = Encoding::new(7); - pub const APP_FLOAT: Encoding = Encoding::new(8); - pub const APP_XML: Encoding = Encoding::new(9); - pub const APP_XHTML_XML: Encoding = Encoding::new(10); - pub const APP_XWWW_FORM_URLENCODED: Encoding = Encoding::new(11); - pub const TEXT_JSON: Encoding = Encoding::new(12); - pub const TEXT_HTML: Encoding = Encoding::new(13); - pub const TEXT_XML: Encoding = Encoding::new(14); - pub const TEXT_CSS: Encoding = Encoding::new(15); - pub const TEXT_CSV: Encoding = Encoding::new(16); - pub const TEXT_JAVASCRIPT: Encoding = Encoding::new(17); - pub const IMAGE_JPEG: Encoding = Encoding::new(18); - pub const IMAGE_PNG: Encoding = Encoding::new(19); - pub const IMAGE_GIF: Encoding = Encoding::new(20); // A perfect hashmap for fast lookup of prefixes pub(super) const KNOWN_PREFIX: phf::OrderedMap = phf_ordered_map! { @@ -137,47 +107,78 @@ impl DefaultEncoder { }; } -impl EncodingMapping for DefaultEncoder { - // Given a numeric prefix ID returns its string representation - fn prefix_to_str(&self, p: zenoh_protocol::core::EncodingPrefix) -> &'static str { +impl EncodingMapping for DefaultEncodingMapping { + /// Given a numeric prefix ID returns its string representation + fn prefix_to_str(&self, p: EncodingPrefix) -> &'static str { match Self::KNOWN_PREFIX.get(&p) { Some(p) => p, None => "unknown", } } - // Given the string representation of a prefix returns its prefix ID. - // Empty is returned in case the prefix is unknown. - fn str_to_prefix(&self, s: &str) -> zenoh_protocol::core::EncodingPrefix { + /// Given the string representation of a prefix returns its prefix ID. + /// Empty is returned in case the prefix is unknown. + fn str_to_prefix(&self, s: &str) -> EncodingPrefix { match Self::KNOWN_STRING.get(s) { Some(p) => *p, - None => Self::EMPTY.prefix(), + None => Self::EMPTY, } } - // Parse a string into a valid Encoding. This functions performs the necessary - // prefix mapping and suffix substring when parsing the input. + /// Parse a string into a valid Encoding. This functions performs the necessary + /// prefix mapping and suffix substring when parsing the input. fn parse(t: S) -> ZResult where S: Into, { fn _parse(mut t: String) -> ZResult { if t.is_empty() { - return Ok(DefaultEncoder::EMPTY); + return Ok(DefaultEncoding::EMPTY); } // Skip empty string mapping - for (s, p) in DefaultEncoder::KNOWN_STRING.entries().skip(1) { + for (s, p) in DefaultEncodingMapping::KNOWN_STRING.entries().skip(1) { if let Some(i) = t.find(s) { return Encoding::new(*p).with_suffix(t.split_off(i + s.len())); } } - DefaultEncoder::EMPTY.with_suffix(t.to_string()) + DefaultEncoding::EMPTY.with_suffix(t) } _parse(t.into()) } } +/// Default encoder provided with Zenoh to facilitate the encoding and decoding +/// of Values in the Rust API. Please note that Zenoh does not impose any +/// encoding and users are free to use any encoder they like. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct DefaultEncoding; + +impl DefaultEncoding { + pub const EMPTY: Encoding = Encoding::new(DefaultEncodingMapping::EMPTY); + pub const APP_OCTET_STREAM: Encoding = Encoding::new(DefaultEncodingMapping::APP_OCTET_STREAM); + pub const APP_CUSTOM: Encoding = Encoding::new(DefaultEncodingMapping::APP_CUSTOM); + pub const TEXT_PLAIN: Encoding = Encoding::new(DefaultEncodingMapping::TEXT_PLAIN); + pub const APP_PROPERTIES: Encoding = Encoding::new(DefaultEncodingMapping::APP_PROPERTIES); + pub const APP_JSON: Encoding = Encoding::new(DefaultEncodingMapping::APP_JSON); + pub const APP_SQL: Encoding = Encoding::new(DefaultEncodingMapping::APP_SQL); + pub const APP_INTEGER: Encoding = Encoding::new(DefaultEncodingMapping::APP_INTEGER); + pub const APP_FLOAT: Encoding = Encoding::new(DefaultEncodingMapping::APP_FLOAT); + pub const APP_XML: Encoding = Encoding::new(DefaultEncodingMapping::APP_XML); + pub const APP_XHTML_XML: Encoding = Encoding::new(DefaultEncodingMapping::APP_XHTML_XML); + pub const APP_XWWW_FORM_URLENCODED: Encoding = + Encoding::new(DefaultEncodingMapping::APP_XWWW_FORM_URLENCODED); + pub const TEXT_JSON: Encoding = Encoding::new(DefaultEncodingMapping::TEXT_JSON); + pub const TEXT_HTML: Encoding = Encoding::new(DefaultEncodingMapping::TEXT_HTML); + pub const TEXT_XML: Encoding = Encoding::new(DefaultEncodingMapping::TEXT_XML); + pub const TEXT_CSS: Encoding = Encoding::new(DefaultEncodingMapping::TEXT_CSS); + pub const TEXT_CSV: Encoding = Encoding::new(DefaultEncodingMapping::TEXT_CSV); + pub const TEXT_JAVASCRIPT: Encoding = Encoding::new(DefaultEncodingMapping::TEXT_JAVASCRIPT); + pub const IMAGE_JPEG: Encoding = Encoding::new(DefaultEncodingMapping::IMAGE_JPEG); + pub const IMAGE_PNG: Encoding = Encoding::new(DefaultEncodingMapping::IMAGE_PNG); + pub const IMAGE_GIF: Encoding = Encoding::new(DefaultEncodingMapping::IMAGE_GIF); +} + // Encoder pub trait Encoder { fn encode(t: T) -> Value; @@ -188,18 +189,18 @@ pub trait Decoder { } // Bytes conversion -impl Encoder for DefaultEncoder { +impl Encoder for DefaultEncoding { fn encode(t: ZBuf) -> Value { Value { payload: t, - encoding: DefaultEncoder::APP_OCTET_STREAM, + encoding: DefaultEncoding::APP_OCTET_STREAM, } } } -impl Decoder for DefaultEncoder { +impl Decoder for DefaultEncoding { fn decode(v: &Value) -> ZResult { - if v.encoding == DefaultEncoder::APP_OCTET_STREAM { + if v.encoding == DefaultEncoding::APP_OCTET_STREAM { Ok(v.payload.clone()) } else { Err(zerror!("{:?} can not be converted into String", v).into()) @@ -207,32 +208,32 @@ impl Decoder for DefaultEncoder { } } -impl Encoder> for DefaultEncoder { +impl Encoder> for DefaultEncoding { fn encode(t: Vec) -> Value { Self::encode(ZBuf::from(t)) } } -impl Encoder<&[u8]> for DefaultEncoder { +impl Encoder<&[u8]> for DefaultEncoding { fn encode(t: &[u8]) -> Value { Self::encode(t.to_vec()) } } -impl Decoder> for DefaultEncoder { +impl Decoder> for DefaultEncoding { fn decode(v: &Value) -> ZResult> { let v: ZBuf = Self::decode(v)?; Ok(v.contiguous().to_vec()) } } -impl<'a> Encoder> for DefaultEncoder { +impl<'a> Encoder> for DefaultEncoding { fn encode(t: Cow<'a, [u8]>) -> Value { Self::encode(ZBuf::from(t.to_vec())) } } -impl<'a> Decoder> for DefaultEncoder { +impl<'a> Decoder> for DefaultEncoding { fn decode(v: &Value) -> ZResult> { let v: Vec = Self::decode(v)?; Ok(Cow::Owned(v)) @@ -240,24 +241,24 @@ impl<'a> Decoder> for DefaultEncoder { } // String -impl Encoder for DefaultEncoder { +impl Encoder for DefaultEncoding { fn encode(s: String) -> Value { Value { payload: ZBuf::from(s.into_bytes()), - encoding: DefaultEncoder::TEXT_PLAIN, + encoding: DefaultEncoding::TEXT_PLAIN, } } } -impl Encoder<&str> for DefaultEncoder { +impl Encoder<&str> for DefaultEncoding { fn encode(s: &str) -> Value { Self::encode(s.to_string()) } } -impl Decoder for DefaultEncoder { +impl Decoder for DefaultEncoding { fn decode(v: &Value) -> ZResult { - if v.encoding == DefaultEncoder::TEXT_PLAIN { + if v.encoding == DefaultEncoding::TEXT_PLAIN { String::from_utf8(v.payload.contiguous().to_vec()).map_err(|e| zerror!("{}", e).into()) } else { Err(zerror!("{:?} can not be converted into String", v).into()) @@ -265,13 +266,13 @@ impl Decoder for DefaultEncoder { } } -impl<'a> Encoder> for DefaultEncoder { +impl<'a> Encoder> for DefaultEncoding { fn encode(s: Cow<'a, str>) -> Value { Self::encode(s.to_string()) } } -impl<'a> Decoder> for DefaultEncoder { +impl<'a> Decoder> for DefaultEncoding { fn decode(v: &Value) -> ZResult> { let v: String = Self::decode(v)?; Ok(Cow::Owned(v)) @@ -279,7 +280,7 @@ impl<'a> Decoder> for DefaultEncoder { } // Sample -impl Encoder for DefaultEncoder { +impl Encoder for DefaultEncoding { fn encode(t: Sample) -> Value { t.value } @@ -288,7 +289,7 @@ impl Encoder for DefaultEncoder { // Integers macro_rules! impl_int { ($t:ty, $encoding:expr) => { - impl Encoder<$t> for DefaultEncoder { + impl Encoder<$t> for DefaultEncoding { fn encode(t: $t) -> Value { Value { payload: ZBuf::from(t.to_string().into_bytes()), @@ -297,13 +298,13 @@ macro_rules! impl_int { } } - impl Encoder<&$t> for DefaultEncoder { + impl Encoder<&$t> for DefaultEncoding { fn encode(t: &$t) -> Value { Self::encode(*t) } } - impl Decoder<$t> for DefaultEncoder { + impl Decoder<$t> for DefaultEncoding { fn decode(v: &Value) -> ZResult<$t> { if v.encoding == $encoding { let v: $t = std::str::from_utf8(&v.payload.contiguous()) @@ -319,41 +320,41 @@ macro_rules! impl_int { }; } -impl_int!(u8, DefaultEncoder::APP_INTEGER); -impl_int!(u16, DefaultEncoder::APP_INTEGER); -impl_int!(u32, DefaultEncoder::APP_INTEGER); -impl_int!(u64, DefaultEncoder::APP_INTEGER); -impl_int!(usize, DefaultEncoder::APP_INTEGER); +impl_int!(u8, DefaultEncoding::APP_INTEGER); +impl_int!(u16, DefaultEncoding::APP_INTEGER); +impl_int!(u32, DefaultEncoding::APP_INTEGER); +impl_int!(u64, DefaultEncoding::APP_INTEGER); +impl_int!(usize, DefaultEncoding::APP_INTEGER); -impl_int!(i8, DefaultEncoder::APP_INTEGER); -impl_int!(i16, DefaultEncoder::APP_INTEGER); -impl_int!(i32, DefaultEncoder::APP_INTEGER); -impl_int!(i64, DefaultEncoder::APP_INTEGER); -impl_int!(isize, DefaultEncoder::APP_INTEGER); +impl_int!(i8, DefaultEncoding::APP_INTEGER); +impl_int!(i16, DefaultEncoding::APP_INTEGER); +impl_int!(i32, DefaultEncoding::APP_INTEGER); +impl_int!(i64, DefaultEncoding::APP_INTEGER); +impl_int!(isize, DefaultEncoding::APP_INTEGER); // Floats -impl_int!(f32, DefaultEncoder::APP_FLOAT); -impl_int!(f64, DefaultEncoder::APP_FLOAT); +impl_int!(f32, DefaultEncoding::APP_FLOAT); +impl_int!(f64, DefaultEncoding::APP_FLOAT); // JSON -impl Encoder<&serde_json::Value> for DefaultEncoder { +impl Encoder<&serde_json::Value> for DefaultEncoding { fn encode(t: &serde_json::Value) -> Value { Value { payload: ZBuf::from(t.to_string().into_bytes()), - encoding: DefaultEncoder::APP_JSON, + encoding: DefaultEncoding::APP_JSON, } } } -impl Encoder for DefaultEncoder { +impl Encoder for DefaultEncoding { fn encode(t: serde_json::Value) -> Value { Self::encode(&t) } } -impl Decoder for DefaultEncoder { +impl Decoder for DefaultEncoding { fn decode(v: &Value) -> ZResult { - if v.encoding == DefaultEncoder::APP_JSON || v.encoding == DefaultEncoder::TEXT_JSON { + if v.encoding == DefaultEncoding::APP_JSON || v.encoding == DefaultEncoding::TEXT_JSON { let r: serde_json::Value = serde::Deserialize::deserialize( &mut serde_json::Deserializer::from_slice(&v.payload.contiguous()), ) @@ -366,24 +367,24 @@ impl Decoder for DefaultEncoder { } // Properties -impl Encoder<&Properties> for DefaultEncoder { +impl Encoder<&Properties> for DefaultEncoding { fn encode(t: &Properties) -> Value { Value { payload: ZBuf::from(t.to_string().into_bytes()), - encoding: DefaultEncoder::APP_PROPERTIES, + encoding: DefaultEncoding::APP_PROPERTIES, } } } -impl Encoder for DefaultEncoder { +impl Encoder for DefaultEncoding { fn encode(t: Properties) -> Value { Self::encode(&t) } } -impl Decoder for DefaultEncoder { +impl Decoder for DefaultEncoding { fn decode(v: &Value) -> ZResult { - if v.encoding == DefaultEncoder::APP_PROPERTIES { + if v.encoding == DefaultEncoding::APP_PROPERTIES { let ps = Properties::from( std::str::from_utf8(&v.payload.contiguous()).map_err(|e| zerror!("{}", e))?, ); @@ -396,17 +397,17 @@ impl Decoder for DefaultEncoder { // Shared memory conversion #[cfg(feature = "shared-memory")] -impl Encoder> for DefaultEncoder { +impl Encoder> for DefaultEncoding { fn encode(t: Arc) -> Value { Value { payload: t.into(), - encoding: DefaultEncoder::APP_OCTET_STREAM, + encoding: DefaultEncoding::APP_OCTET_STREAM, } } } #[cfg(feature = "shared-memory")] -impl Encoder> for DefaultEncoder { +impl Encoder> for DefaultEncoding { fn encode(t: Box) -> Value { let smb: Arc = t.into(); Self::encode(smb) @@ -414,11 +415,11 @@ impl Encoder> for DefaultEncoder { } #[cfg(feature = "shared-memory")] -impl Encoder for DefaultEncoder { +impl Encoder for DefaultEncoding { fn encode(t: SharedMemoryBuf) -> Value { Value { payload: t.into(), - encoding: DefaultEncoder::APP_OCTET_STREAM, + encoding: DefaultEncoding::APP_OCTET_STREAM, } } } diff --git a/zenoh/src/net/runtime/adminspace.rs b/zenoh/src/net/runtime/adminspace.rs index 704c5354c4..c4d6aa899f 100644 --- a/zenoh/src/net/runtime/adminspace.rs +++ b/zenoh/src/net/runtime/adminspace.rs @@ -22,7 +22,7 @@ use crate::prelude::{ use crate::queryable::Query; use crate::queryable::QueryInner; use crate::value::Value; -use crate::DefaultEncoder; +use crate::DefaultEncoding; use async_std::task; use log::{error, trace}; use serde_json::json; @@ -734,7 +734,7 @@ fn plugins_status(context: &AdminContext, query: Query) { if let Ok(key_expr) = KeyExpr::try_from(response.key) { if let Err(e) = query.reply(Ok(Sample::new( key_expr, - Value::from(response.value).encoding(DefaultEncoder::TEXT_PLAIN), + Value::from(response.value).encoding(DefaultEncoding::TEXT_PLAIN), ))) .res() { diff --git a/zenoh/src/prelude.rs b/zenoh/src/prelude.rs index 26857e0d9b..52889ed5a4 100644 --- a/zenoh/src/prelude.rs +++ b/zenoh/src/prelude.rs @@ -41,7 +41,7 @@ pub(crate) mod common { pub use crate::query::{QueryConsolidation, QueryTarget}; - pub use crate::encoding::DefaultEncoder; + pub use crate::encoding::DefaultEncoding; pub use crate::value::Value; /// The encoding of a zenoh `Value`. pub use zenoh_protocol::core::{Encoding, EncodingPrefix}; diff --git a/zenoh/src/session.rs b/zenoh/src/session.rs index d5740904b6..9e2a869bed 100644 --- a/zenoh/src/session.rs +++ b/zenoh/src/session.rs @@ -14,7 +14,7 @@ use crate::admin; use crate::config::Config; use crate::config::Notifier; -use crate::encoding::DefaultEncoder; +use crate::encoding::DefaultEncoding; use crate::handlers::{Callback, DefaultHandler}; use crate::info::*; use crate::key_expr::KeyExprInner; @@ -2270,7 +2270,7 @@ impl Primitives for Session { }, None => Value { payload: ZBuf::empty(), - encoding: DefaultEncoder::EMPTY, + encoding: DefaultEncoding::EMPTY, }, }; let replier_id = match e.ext_sinfo { diff --git a/zenoh/src/value.rs b/zenoh/src/value.rs index 8a49b16cab..670497312f 100644 --- a/zenoh/src/value.rs +++ b/zenoh/src/value.rs @@ -17,7 +17,7 @@ use base64::{engine::general_purpose::STANDARD as b64_std_engine, Engine}; use zenoh_result::ZResult; use crate::buffers::ZBuf; -use crate::encoding::{Decoder, DefaultEncoder, Encoder}; +use crate::encoding::{Decoder, DefaultEncoding, Encoder}; use crate::prelude::{Encoding, SplitBuffer}; /// A zenoh Value. @@ -62,9 +62,9 @@ impl Value { } } -// Provide some facilities in the Rust API to encode/decode [`Value`] with an `Encoder`. +/// Provide some facilities specific to the Rust API to encode/decode a [`Value`] with an `Encoder`. impl Value { - /// Encode an object of type `T` as a [`Value`] using the [`DefaultEncoder`]. + /// Encode an object of type `T` as a [`Value`] using the [`DefaultEncoding`]. /// /// ```rust /// use zenoh::value::Value; @@ -76,9 +76,9 @@ impl Value { /// ``` pub fn encode(t: T) -> Self where - DefaultEncoder: Encoder, + DefaultEncoding: Encoder, { - DefaultEncoder::encode(t) + DefaultEncoding::encode(t) } /// Encode an object of type `T` as a [`Value`] using a provided [`Encoder`]. @@ -122,7 +122,7 @@ impl Value { M::encode(t) } - /// Decode an object of type `T` from a [`Value`] using the [`DefaultEncoder`]. + /// Decode an object of type `T` from a [`Value`] using the [`DefaultEncoding`]. /// /// ```rust /// use zenoh::value::Value; @@ -134,9 +134,9 @@ impl Value { /// ``` pub fn decode(&self) -> ZResult where - DefaultEncoder: Decoder, + DefaultEncoding: Decoder, { - DefaultEncoder::decode(self) + DefaultEncoding::decode(self) } /// Decode an object of type `T` from a [`Value`] using a provided [`Encoder`]. @@ -181,10 +181,10 @@ impl Value { } } -/// Build a [`Value`] from any type `T` supported by the [`DefaultEncoder`]. +/// Build a [`Value`] from any type `T` supported by the [`DefaultEncoding`]. impl From for Value where - DefaultEncoder: Encoder, + DefaultEncoding: Encoder, { fn from(t: T) -> Self { Value::encode(t)