diff --git a/Cargo.lock b/Cargo.lock index 4328de40d7..7ceb5dbc39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4629,6 +4629,7 @@ dependencies = [ "ordered-float", "paste", "petgraph", + "phf", "rand 0.8.5", "regex", "rustc_version 0.4.0", @@ -5110,7 +5111,6 @@ dependencies = [ "const_format", "hex", "lazy_static", - "phf", "rand 0.8.5", "serde", "uhlc", diff --git a/commons/zenoh-codec/src/core/encoding.rs b/commons/zenoh-codec/src/core/encoding.rs index 0895396198..8e8627d05a 100644 --- a/commons/zenoh-codec/src/core/encoding.rs +++ b/commons/zenoh-codec/src/core/encoding.rs @@ -49,7 +49,12 @@ where let zodec = Zenoh080Bounded::::new(); let prefix: EncodingPrefix = zodec.read(&mut *reader)?; let suffix: String = zodec.read(&mut *reader)?; - let encoding = Encoding::new(prefix, suffix).map_err(|_| DidntRead)?; + + let mut encoding: Encoding = Encoding::new(prefix); + if !suffix.is_empty() { + encoding = encoding.with_suffix(suffix).map_err(|_| DidntRead)?; + } + Ok(encoding) } } diff --git a/commons/zenoh-protocol/Cargo.toml b/commons/zenoh-protocol/Cargo.toml index 7c1a49c5fd..07c11cb2fc 100644 --- a/commons/zenoh-protocol/Cargo.toml +++ b/commons/zenoh-protocol/Cargo.toml @@ -44,7 +44,6 @@ complete_n = [] const_format = { workspace = true } hex = { workspace = true, features = ["alloc"] } rand = { workspace = true, features = ["alloc", "getrandom"], optional = true } -phf = { workspace = true } serde = { workspace = true, features = ["alloc"] } uhlc = { workspace = true, default-features = false } uuid = { workspace = true } # Needs a getrandom::getrandom() custom implementation on embedded (in root crate) diff --git a/commons/zenoh-protocol/src/core/encoding.rs b/commons/zenoh-protocol/src/core/encoding.rs index f9111fb89f..31aa3e80b0 100644 --- a/commons/zenoh-protocol/src/core/encoding.rs +++ b/commons/zenoh-protocol/src/core/encoding.rs @@ -13,13 +13,10 @@ // use crate::core::CowStr; use alloc::{borrow::Cow, string::String}; -use core::{ - fmt::{self, Debug}, - write, -}; +use core::fmt::{self, Debug}; use zenoh_result::{bail, ZResult}; -pub type EncodingPrefix = u8; +pub type EncodingPrefix = u64; /// The encoding of a zenoh `zenoh::Value`. /// @@ -31,101 +28,15 @@ pub struct Encoding { suffix: CowStr<'static>, } -pub mod prefix { - use crate::core::encoding::EncodingPrefix; - use phf::phf_ordered_map; - - /// Prefixes from 0 to 63 are reserved by Zenoh - /// Users are free to use any prefix from 64 to 255 - pub const EMPTY: EncodingPrefix = 0; - pub const APP_OCTET_STREAM: EncodingPrefix = 1; - pub const APP_CUSTOM: EncodingPrefix = 2; - pub const TEXT_PLAIN: EncodingPrefix = 3; - pub const APP_PROPERTIES: EncodingPrefix = 4; - pub const APP_JSON: EncodingPrefix = 5; - pub const APP_SQL: EncodingPrefix = 6; - pub const APP_INTEGER: EncodingPrefix = 7; - pub const APP_FLOAT: EncodingPrefix = 8; - pub const APP_XML: EncodingPrefix = 9; - pub const APP_XHTML_XML: EncodingPrefix = 10; - pub const APP_XWWW_FORM_URLENCODED: EncodingPrefix = 11; - pub const TEXT_JSON: EncodingPrefix = 12; - pub const TEXT_HTML: EncodingPrefix = 13; - pub const TEXT_XML: EncodingPrefix = 14; - pub const TEXT_CSS: EncodingPrefix = 15; - pub const TEXT_CSV: EncodingPrefix = 16; - pub const TEXT_JAVASCRIPT: EncodingPrefix = 17; - pub const IMAGE_JPEG: EncodingPrefix = 18; - pub const IMAGE_PNG: EncodingPrefix = 19; - pub const IMAGE_GIF: EncodingPrefix = 20; - - // A perfect hashmap for fast lookup of prefixes - pub(super) const KNOWN: phf::OrderedMap = phf_ordered_map! { - 0u8 => "", - 1u8 => "application/octet-stream", - 2u8 => "application/custom", // non iana standard - 3u8 => "text/plain", - 4u8 => "application/properties", // non iana standard - 5u8 => "application/json", // if not readable from casual users - 6u8 => "application/sql", - 7u8 => "application/integer", // non iana standard - 8u8 => "application/float", // non iana standard - 9u8 => "application/xml", // if not readable from casual users (RFC 3023, sec 3) - 10u8 => "application/xhtml+xml", - 11u8 => "application/x-www-form-urlencoded", - 12u8 => "text/json", // non iana standard - if readable from casual users - 13u8 => "text/html", - 14u8 => "text/xml", // if readable from casual users (RFC 3023, section 3) - 15u8 => "text/css", - 16u8 => "text/csv", - 17u8 => "text/javascript", - 18u8 => "image/jpeg", - 19u8 => "image/png", - 20u8 => "image/gif", - }; -} - impl Encoding { - /// The encoding is empty. It is equivalent to not being defined. - pub const EMPTY: Encoding = Encoding::exact(prefix::EMPTY); - pub const APP_OCTET_STREAM: Encoding = Encoding::exact(prefix::APP_OCTET_STREAM); - pub const APP_CUSTOM: Encoding = Encoding::exact(prefix::APP_CUSTOM); - pub const TEXT_PLAIN: Encoding = Encoding::exact(prefix::TEXT_PLAIN); - pub const APP_PROPERTIES: Encoding = Encoding::exact(prefix::APP_PROPERTIES); - pub const APP_JSON: Encoding = Encoding::exact(prefix::APP_JSON); - pub const APP_SQL: Encoding = Encoding::exact(prefix::APP_SQL); - pub const APP_INTEGER: Encoding = Encoding::exact(prefix::APP_INTEGER); - pub const APP_FLOAT: Encoding = Encoding::exact(prefix::APP_FLOAT); - pub const APP_XML: Encoding = Encoding::exact(prefix::APP_XML); - pub const APP_XHTML_XML: Encoding = Encoding::exact(prefix::APP_XHTML_XML); - pub const APP_XWWW_FORM_URLENCODED: Encoding = - Encoding::exact(prefix::APP_XWWW_FORM_URLENCODED); - pub const TEXT_JSON: Encoding = Encoding::exact(prefix::TEXT_JSON); - pub const TEXT_HTML: Encoding = Encoding::exact(prefix::TEXT_HTML); - pub const TEXT_XML: Encoding = Encoding::exact(prefix::TEXT_XML); - pub const TEXT_CSS: Encoding = Encoding::exact(prefix::TEXT_CSS); - pub const TEXT_CSV: Encoding = Encoding::exact(prefix::TEXT_CSV); - pub const TEXT_JAVASCRIPT: Encoding = Encoding::exact(prefix::TEXT_JAVASCRIPT); - pub const IMAGE_JPEG: Encoding = Encoding::exact(prefix::IMAGE_JPEG); - pub const IMAGE_PNG: Encoding = Encoding::exact(prefix::IMAGE_PNG); - pub const IMAGE_GIF: Encoding = Encoding::exact(prefix::IMAGE_GIF); - - pub const fn exact(prefix: EncodingPrefix) -> Self { + /// Returns a new [`WireEncoding`] object provided the prefix ID. + pub const fn new(prefix: EncodingPrefix) -> Self { Self { prefix, suffix: CowStr::borrowed(""), } } - /// Returns a new [`Encoding`] object. - /// This method will return an error when the suffix is longer than 255 characters. - pub fn new(prefix: EncodingPrefix, suffix: IntoCowStr) -> ZResult - where - IntoCowStr: Into> + AsRef, - { - Self::exact(prefix).with_suffix(suffix) - } - /// Sets the suffix of this encoding. /// This method will return an error when the suffix is longer than 255 characters. pub fn with_suffix(mut self, suffix: IntoCowStr) -> ZResult @@ -140,106 +51,41 @@ impl Encoding { Ok(self) } - pub fn as_ref<'a, T>(&'a self) -> T - where - &'a Self: Into, - { - self.into() - } - - /// Returns `true` if the string representation of this encoding starts with - /// the string representation of ther given encoding. - pub fn starts_with(&self, with: T) -> bool - where - T: Into, - { - let with: Encoding = with.into(); - self.prefix() == with.prefix() && self.suffix().starts_with(with.suffix()) + /// Returns a new [`WireEncoding`] object with default empty prefix ID. + pub const fn empty() -> Self { + Self::new(0) } + // Returns the numerical prefix ID pub const fn prefix(&self) -> EncodingPrefix { self.prefix } + // Returns the suffix string pub fn suffix(&self) -> &str { self.suffix.as_str() } -} - -impl From<&EncodingPrefix> for Encoding { - fn from(e: &EncodingPrefix) -> Encoding { - Encoding::exact(*e) - } -} -impl From for Encoding { - fn from(e: EncodingPrefix) -> Encoding { - Encoding::exact(e) + /// Returns `true` if the string representation of this encoding starts with + /// the string representation of ther given encoding. + pub fn starts_with(&self, with: T) -> bool + where + T: Into, + { + let with: Encoding = with.into(); + self.prefix() == with.prefix() && self.suffix().starts_with(with.suffix()) } } impl fmt::Display for Encoding { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match prefix::KNOWN.get(&self.prefix) { - Some(s) => write!(f, "{}", s)?, - None => write!(f, "Unknown({})", self.prefix)?, - } - write!(f, "{}", self.suffix.as_str()) - } -} - -impl TryFrom<&'static str> for Encoding { - type Error = zenoh_result::Error; - - fn try_from(s: &'static str) -> Result { - for (k, v) in prefix::KNOWN.entries().skip(1) { - if let Some(suffix) = s.strip_prefix(v) { - let e = Encoding::exact(*k); - if suffix.is_empty() { - return Ok(e); - } else { - return e.with_suffix(suffix); - } - } - } - - let e = Encoding::EMPTY; - if s.is_empty() { - Ok(e) - } else { - e.with_suffix(s) - } - } -} - -impl TryFrom for Encoding { - type Error = zenoh_result::Error; - - fn try_from(mut s: String) -> Result { - for (k, v) in prefix::KNOWN.entries().skip(1) { - if s.starts_with(v) { - s.replace_range(..v.len(), ""); - let e = Encoding::exact(*k); - if s.is_empty() { - return Ok(e); - } else { - return e.with_suffix(s); - } - } - } - - let e = Encoding::EMPTY; - if s.is_empty() { - Ok(e) - } else { - e.with_suffix(s) - } + f.write_fmt(format_args!("{}:{}", self.prefix, self.suffix.as_str())) } } impl Default for Encoding { fn default() -> Self { - Encoding::EMPTY + Self::empty() } } @@ -263,6 +109,6 @@ impl Encoding { } else { String::new() }; - Encoding::new(prefix, suffix).unwrap() + Encoding::new(prefix).with_suffix(suffix).unwrap() } } diff --git a/commons/zenoh-protocol/src/core/mod.rs b/commons/zenoh-protocol/src/core/mod.rs index 48868b2034..55e57d5d81 100644 --- a/commons/zenoh-protocol/src/core/mod.rs +++ b/commons/zenoh-protocol/src/core/mod.rs @@ -43,7 +43,7 @@ pub use wire_expr::*; mod cowstr; pub use cowstr::CowStr; mod encoding; -pub use encoding::{prefix, Encoding, EncodingPrefix}; +pub use encoding::{Encoding, EncodingPrefix}; pub mod locator; pub use locator::*; diff --git a/zenoh/Cargo.toml b/zenoh/Cargo.toml index fb929e9893..3f649941e8 100644 --- a/zenoh/Cargo.toml +++ b/zenoh/Cargo.toml @@ -80,6 +80,7 @@ log = { workspace = true } ordered-float = { workspace = true } paste = { workspace = true } petgraph = { workspace = true } +phf = { workspace = true } rand = { workspace = true, features = ["default"] } regex = { workspace = true } serde = { workspace = true, features = ["default"] } diff --git a/zenoh/src/admin.rs b/zenoh/src/admin.rs index 9ff1bb3878..9ca0873555 100644 --- a/zenoh/src/admin.rs +++ b/zenoh/src/admin.rs @@ -11,6 +11,7 @@ // Contributors: // ZettaScale Zenoh Team, // +use crate::prelude::Encoding; use crate::{ keyexpr, prelude::sync::{KeyExpr, Locality, SampleKind}, @@ -25,10 +26,7 @@ use std::{ sync::Arc, }; use zenoh_core::SyncResolve; -use zenoh_protocol::{ - core::{Encoding, WireExpr}, - network::NetworkMessage, -}; +use zenoh_protocol::{core::WireExpr, network::NetworkMessage}; use zenoh_transport::{ TransportEventHandler, TransportMulticastEventHandler, TransportPeer, TransportPeerEventHandler, }; diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index 5c3b938e5b..d26da120a3 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -124,6 +124,7 @@ pub const FEATURES: &str = concat_enabled_features!( mod admin; #[macro_use] mod session; +pub mod encoding; pub use session::*; pub mod key_expr; diff --git a/zenoh/src/net/runtime/adminspace.rs b/zenoh/src/net/runtime/adminspace.rs index 15880a6510..db17694092 100644 --- a/zenoh/src/net/runtime/adminspace.rs +++ b/zenoh/src/net/runtime/adminspace.rs @@ -15,7 +15,10 @@ use super::Runtime; use crate::key_expr::KeyExpr; use crate::net::primitives::Primitives; use crate::plugins::sealed::{self as plugins}; -use crate::prelude::sync::{Sample, SyncResolve}; +use crate::prelude::{ + sync::{Sample, SyncResolve}, + Encoding, +}; use crate::queryable::Query; use crate::queryable::QueryInner; use crate::value::Value; @@ -33,7 +36,7 @@ use zenoh_plugin_trait::{PluginControl, PluginStatus}; use zenoh_protocol::{ core::{ key_expr::{keyexpr, OwnedKeyExpr}, - Encoding, ExprId, WireExpr, ZenohId, EMPTY_EXPR_ID, + ExprId, WireExpr, ZenohId, EMPTY_EXPR_ID, }, network::{ declare::{queryable::ext::QueryableInfo, subscriber::ext::SubscriberInfo}, @@ -422,7 +425,7 @@ impl Primitives for AdminSpace { parameters, value: query .ext_body - .map(|b| Value::from(b.payload).encoding(b.encoding)), + .map(|b| Value::from(b.payload).encoding(b.encoding.into())), qid: msg.id, zid, primitives, diff --git a/zenoh/src/prelude.rs b/zenoh/src/prelude.rs index 1a408ed014..7bc54b7ec4 100644 --- a/zenoh/src/prelude.rs +++ b/zenoh/src/prelude.rs @@ -41,9 +41,9 @@ pub(crate) mod common { pub use crate::query::{QueryConsolidation, QueryTarget}; - pub use crate::value::Value; /// The encoding of a zenoh `Value`. - pub use zenoh_protocol::core::{prefix as EncodingPrefix, Encoding}; + pub use crate::encoding::Encoding; + pub use crate::value::Value; pub use crate::query::ConsolidationMode; #[zenoh_macros::unstable] diff --git a/zenoh/src/publication.rs b/zenoh/src/publication.rs index 843190ad45..87e3f9261f 100644 --- a/zenoh/src/publication.rs +++ b/zenoh/src/publication.rs @@ -824,7 +824,7 @@ fn resolve_put( } PushBody::Put(Put { timestamp, - encoding: value.encoding.clone(), + encoding: value.encoding.clone().into(), ext_sinfo: None, #[cfg(feature = "shared-memory")] ext_shm: None, @@ -855,7 +855,7 @@ fn resolve_put( if publisher.destination != Locality::Remote { let data_info = DataInfo { kind, - encoding: Some(value.encoding), + encoding: Some(value.encoding.clone()), timestamp, ..Default::default() }; diff --git a/zenoh/src/queryable.rs b/zenoh/src/queryable.rs index 9ee73d1641..297f33e973 100644 --- a/zenoh/src/queryable.rs +++ b/zenoh/src/queryable.rs @@ -225,7 +225,7 @@ impl SyncResolve for ReplyBuilder<'_> { }, payload: ResponseBody::Reply(zenoh::Reply { timestamp: data_info.timestamp, - encoding: data_info.encoding.unwrap_or_default(), + encoding: data_info.encoding.unwrap_or_default().into(), ext_sinfo: if data_info.source_id.is_some() || data_info.source_sn.is_some() { Some(zenoh::reply::ext::SourceInfoType { @@ -269,7 +269,7 @@ impl SyncResolve for ReplyBuilder<'_> { #[cfg(feature = "shared-memory")] ext_shm: None, payload: payload.payload, - encoding: payload.encoding, + encoding: payload.encoding.into(), }), code: 0, // TODO }), diff --git a/zenoh/src/sample.rs b/zenoh/src/sample.rs index 5d707e5936..7bdae78a58 100644 --- a/zenoh/src/sample.rs +++ b/zenoh/src/sample.rs @@ -14,14 +14,12 @@ //! Sample primitives use crate::buffers::ZBuf; -use crate::prelude::ZenohId; -use crate::prelude::{KeyExpr, SampleKind, Value}; +use crate::prelude::{Encoding, KeyExpr, SampleKind, Value, ZenohId}; use crate::query::Reply; use crate::time::{new_reception_timestamp, Timestamp}; #[zenoh_macros::unstable] use serde::Serialize; use std::convert::{TryFrom, TryInto}; -use zenoh_protocol::core::Encoding; pub type SourceSn = u64; @@ -395,12 +393,12 @@ impl Sample { pub(crate) fn with_info( key_expr: KeyExpr<'static>, payload: ZBuf, - data_info: Option, + mut data_info: Option, ) -> Self { let mut value: Value = payload.into(); - if let Some(data_info) = data_info { - if let Some(encoding) = &data_info.encoding { - value.encoding = encoding.clone(); + if let Some(mut data_info) = data_info.take() { + if let Some(encoding) = data_info.encoding.take() { + value.encoding = encoding; } Sample { key_expr, diff --git a/zenoh/src/session.rs b/zenoh/src/session.rs index d52c446d3d..3aba44a5c0 100644 --- a/zenoh/src/session.rs +++ b/zenoh/src/session.rs @@ -33,6 +33,7 @@ use crate::sample::Attachment; use crate::sample::DataInfo; use crate::selector::TIME_RANGE_KEY; use crate::subscriber::*; +use crate::Encoding; use crate::Id; use crate::Priority; use crate::Sample; @@ -1814,7 +1815,7 @@ impl Session { ext_body: value.as_ref().map(|v| query::ext::QueryBodyType { #[cfg(feature = "shared-memory")] ext_shm: None, - encoding: v.encoding.clone(), + encoding: v.encoding.clone().into(), payload: v.payload.clone(), }), ext_attachment, @@ -1833,7 +1834,7 @@ impl Session { value.as_ref().map(|v| query::ext::QueryBodyType { #[cfg(feature = "shared-memory")] ext_shm: None, - encoding: v.encoding.clone(), + encoding: v.encoding.clone().into(), payload: v.payload.clone(), }), #[cfg(feature = "unstable")] @@ -1905,7 +1906,7 @@ impl Session { parameters, value: body.map(|b| Value { payload: b.payload, - encoding: b.encoding, + encoding: b.encoding.into(), }), qid, zid, @@ -2190,7 +2191,7 @@ impl Primitives for Session { PushBody::Put(m) => { let info = DataInfo { kind: SampleKind::Put, - encoding: Some(m.encoding), + encoding: Some(m.encoding.into()), timestamp: m.timestamp, source_id: m.ext_sinfo.as_ref().map(|i| i.zid), source_sn: m.ext_sinfo.as_ref().map(|i| i.sn as u64), @@ -2266,11 +2267,11 @@ impl Primitives for Session { let value = match e.ext_body { Some(body) => Value { payload: body.payload, - encoding: body.encoding, + encoding: body.encoding.into(), }, None => Value { payload: ZBuf::empty(), - encoding: zenoh_protocol::core::Encoding::EMPTY, + encoding: Encoding::EMPTY, }, }; let replier_id = match e.ext_sinfo { @@ -2343,7 +2344,7 @@ impl Primitives for Session { }; let info = DataInfo { kind: SampleKind::Put, - encoding: Some(m.encoding), + encoding: Some(m.encoding.into()), timestamp: m.timestamp, source_id: m.ext_sinfo.as_ref().map(|i| i.zid), source_sn: m.ext_sinfo.as_ref().map(|i| i.sn as u64), diff --git a/zenoh/src/value.rs b/zenoh/src/value.rs index 94e28f9aaf..9c0afa28c7 100644 --- a/zenoh/src/value.rs +++ b/zenoh/src/value.rs @@ -13,7 +13,6 @@ // //! Value primitives. - use base64::{engine::general_purpose::STANDARD as b64_std_engine, Engine}; use std::borrow::Cow; use std::convert::TryFrom; @@ -24,7 +23,8 @@ use zenoh_collections::Properties; use zenoh_result::ZError; use crate::buffers::ZBuf; -use crate::prelude::{Encoding, EncodingPrefix, Sample, SplitBuffer}; +use crate::encoding::DefaultEncodingMapping; +use crate::prelude::{Encoding, Sample, SplitBuffer}; #[cfg(feature = "shared-memory")] use zenoh_shm::SharedMemoryBuf; @@ -131,7 +131,7 @@ impl TryFrom<&Value> for ZBuf { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_OCTET_STREAM => Ok(v.payload.clone()), + DefaultEncodingMapping::APP_OCTET_STREAM => Ok(v.payload.clone()), unexpected => Err(zerror!( "{:?} can not be converted into Cow<'a, [u8]>", unexpected @@ -159,7 +159,7 @@ impl<'a> TryFrom<&'a Value> for Cow<'a, [u8]> { fn try_from(v: &'a Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_OCTET_STREAM => Ok(v.payload.contiguous()), + DefaultEncodingMapping::APP_OCTET_STREAM => Ok(v.payload.contiguous()), unexpected => Err(zerror!( "{:?} can not be converted into Cow<'a, [u8]>", unexpected @@ -179,7 +179,7 @@ impl TryFrom<&Value> for Vec { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_OCTET_STREAM => Ok(v.payload.contiguous().to_vec()), + DefaultEncodingMapping::APP_OCTET_STREAM => Ok(v.payload.contiguous().to_vec()), unexpected => Err(zerror!( "{:?} can not be converted into Vec", unexpected @@ -220,7 +220,7 @@ impl TryFrom<&Value> for String { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::TEXT_PLAIN => { + DefaultEncodingMapping::TEXT_PLAIN => { String::from_utf8(v.payload.contiguous().to_vec()).map_err(|e| zerror!("{}", e)) } unexpected => Err(zerror!("{:?} can not be converted into String", unexpected)), @@ -258,7 +258,7 @@ impl TryFrom<&Value> for i64 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -290,7 +290,7 @@ impl TryFrom<&Value> for i32 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -322,7 +322,7 @@ impl TryFrom<&Value> for i16 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -354,7 +354,7 @@ impl TryFrom<&Value> for i8 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -386,7 +386,7 @@ impl TryFrom<&Value> for isize { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -418,7 +418,7 @@ impl TryFrom<&Value> for u64 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -450,7 +450,7 @@ impl TryFrom<&Value> for u32 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -482,7 +482,7 @@ impl TryFrom<&Value> for u16 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -514,7 +514,7 @@ impl TryFrom<&Value> for u8 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -546,7 +546,7 @@ impl TryFrom<&Value> for usize { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_INTEGER => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -578,7 +578,7 @@ impl TryFrom<&Value> for f64 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_FLOAT => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_FLOAT => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -610,7 +610,7 @@ impl TryFrom<&Value> for f32 { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_FLOAT => std::str::from_utf8(&v.payload.contiguous()) + DefaultEncodingMapping::APP_FLOAT => std::str::from_utf8(&v.payload.contiguous()) .map_err(|e| zerror!("{}", e))? .parse() .map_err(|e| zerror!("{}", e)), @@ -648,7 +648,7 @@ impl TryFrom<&Value> for serde_json::Value { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_JSON | EncodingPrefix::TEXT_JSON => { + DefaultEncodingMapping::APP_JSON | DefaultEncodingMapping::TEXT_JSON => { let r = serde::Deserialize::deserialize(&mut serde_json::Deserializer::from_slice( &v.payload.contiguous(), )); @@ -685,7 +685,7 @@ impl TryFrom<&Value> for Properties { fn try_from(v: &Value) -> Result { match v.encoding.prefix() { - EncodingPrefix::APP_PROPERTIES => Ok(Properties::from( + DefaultEncodingMapping::APP_PROPERTIES => Ok(Properties::from( std::str::from_utf8(&v.payload.contiguous()).map_err(|e| zerror!("{}", e))?, )), unexpected => Err(zerror!(