From bdb01fb0ea39ba7849ebf4cb87495f81368bcc94 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Wed, 9 Oct 2024 17:22:48 +0200 Subject: [PATCH] Encoding and timestamp serialization remove from zenoh-ext (#1520) * 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 --- Cargo.lock | 40 +-- Cargo.toml | 2 - zenoh-ext/src/serialization.rs | 79 +---- zenoh/Cargo.toml | 3 - zenoh/src/api/encoding.rs | 626 +++++++++------------------------ 5 files changed, 171 insertions(+), 579 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2387bd28d3..94542bf638 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -787,7 +787,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" dependencies = [ "ciborium-io", - "half 2.4.1", + "half", ] [[package]] @@ -1601,12 +1601,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "half" -version = "1.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" - [[package]] name = "half" version = "2.4.1" @@ -1957,12 +1951,6 @@ dependencies = [ "nom", ] -[[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" @@ -3704,29 +3692,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 1.8.3", - "serde", -] - [[package]] name = "serde_derive" version = "1.0.210" @@ -5488,10 +5453,7 @@ dependencies = [ "rand 0.8.5", "rustc_version 0.4.1", "serde", - "serde-pickle", - "serde_cbor", "serde_json", - "serde_yaml", "socket2 0.5.7", "tokio", "tokio-util", diff --git a/Cargo.toml b/Cargo.toml index 23b384e485..eef6f1ef44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/zenoh-ext/src/serialization.rs b/zenoh-ext/src/serialization.rs index 0a79b7fc7e..2ed4e967df 100644 --- a/zenoh-ext/src/serialization.rs +++ b/zenoh-ext/src/serialization.rs @@ -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; @@ -461,66 +457,6 @@ impl Deserialize for VarInt { } } -// -// 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 { - 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 { - let id = Vec::::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 { - 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 { - let encoding = String::deserialize(deserializer)?; - Encoding::from_str(&encoding).map_err(|_| ZDeserializeError) - } -} - #[cfg(test)] mod tests { use std::ops::Range; @@ -603,17 +539,4 @@ mod tests { map.insert("hello".to_string(), "world".to_string()); serialize_deserialize!(HashMap, 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()); - } } diff --git a/zenoh/Cargo.toml b/zenoh/Cargo.toml index b1bc3e5fb8..94f6d6eb48 100644 --- a/zenoh/Cargo.toml +++ b/zenoh/Cargo.toml @@ -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 } diff --git a/zenoh/src/api/encoding.rs b/zenoh/src/api/encoding.rs index bc335a5fc2..6f84db5c4e 100644 --- a/zenoh/src/api/encoding.rs +++ b/zenoh/src/api/encoding.rs @@ -14,12 +14,8 @@ use std::{borrow::Cow, convert::Infallible, fmt, str::FromStr}; use phf::phf_map; -use zenoh_buffers::{ZBuf, ZSlice}; +use zenoh_buffers::ZSlice; use zenoh_protocol::core::EncodingId; -#[cfg(feature = "shared-memory")] -use zenoh_shm::api::buffer::{zshm::ZShm, zshmmut::ZShmMut}; - -use super::bytes::ZBytes; /// Default encoding values used by Zenoh. /// @@ -61,7 +57,7 @@ use super::bytes::ZBytes; /// ### Schema /// /// Additionally, a schema can be associated to the encoding. -/// The conventions is to use the `;` separator if an encoding is created from a string. +/// The convention is to use the `;` separator if an encoding is created from a string. /// Alternatively, [`with_schema()`](Encoding::with_schema) can be used to add a scheme to one of the associated constants. /// ``` /// use zenoh::bytes::Encoding; @@ -86,209 +82,96 @@ impl Encoding { /// /// Constant alias for string: `"zenoh/bytes"`. /// - /// Usually used for types: `Vec`, `&[u8]`, `[u8; N]`, `Cow<[u8]>`. + /// This encoding supposes that the payload was created with [`ZBytes::from::>`](crate::bytes::ZBytes::from) or similar + /// (`[u8]`, `[u8;N]`, `Cow<_,[u8]>`) and its data can be accessed with [`ZBytes::to_bytes()`](crate::bytes::ZBytes::to_bytes), + /// no additional assumptions about data format are made pub const ZENOH_BYTES: Encoding = Self(zenoh_protocol::core::Encoding { id: 0, schema: None, }); - /// A VLE-encoded signed little-endian 8bit integer. Binary representation uses two's complement. - /// - /// Constant alias for string: `"zenoh/int8"`. - /// - /// Usually used for types: `i8`. - pub const ZENOH_INT8: Encoding = Self(zenoh_protocol::core::Encoding { - id: 1, - schema: None, - }); - /// A VLE-encoded signed little-endian 16bit integer. Binary representation uses two's complement. - /// - /// Constant alias for string: `"zenoh/int16"`. - /// - /// Usually used for types: `i16`. - pub const ZENOH_INT16: Encoding = Self(zenoh_protocol::core::Encoding { - id: 2, - schema: None, - }); - /// A VLE-encoded signed little-endian 32bit integer. Binary representation uses two's complement. - /// - /// Constant alias for string: `"zenoh/int32"`. - /// - /// Usually used for types: `i32`. - pub const ZENOH_INT32: Encoding = Self(zenoh_protocol::core::Encoding { - id: 3, - schema: None, - }); - /// A VLE-encoded signed little-endian 64bit integer. Binary representation uses two's complement. - /// - /// Constant alias for string: `"zenoh/int64"`. - /// - /// Usually used for types: `i64`. - pub const ZENOH_INT64: Encoding = Self(zenoh_protocol::core::Encoding { - id: 4, - schema: None, - }); - /// A VLE-encoded signed little-endian 128bit integer. Binary representation uses two's complement. - /// - /// Constant alias for string: `"zenoh/int128"`. - /// - /// Usually used for types: `i128`. - pub const ZENOH_INT128: Encoding = Self(zenoh_protocol::core::Encoding { - id: 5, - schema: None, - }); - /// A VLE-encoded unsigned little-endian 8bit integer. - /// - /// Constant alias for string: `"zenoh/uint8"`. - /// - /// Usually used for types: `u8`. - pub const ZENOH_UINT8: Encoding = Self(zenoh_protocol::core::Encoding { - id: 6, - schema: None, - }); - /// A VLE-encoded unsigned little-endian 16bit integer. - /// - /// Constant alias for string: `"zenoh/uint16"`. - /// - /// Usually used for types: `u16`. - pub const ZENOH_UINT16: Encoding = Self(zenoh_protocol::core::Encoding { - id: 7, - schema: None, - }); - /// A VLE-encoded unsigned little-endian 32bit integer. - /// - /// Constant alias for string: `"zenoh/uint32"`. - /// - /// Usually used for types: `u32`. - pub const ZENOH_UINT32: Encoding = Self(zenoh_protocol::core::Encoding { - id: 8, - schema: None, - }); - /// A VLE-encoded unsigned little-endian 64bit integer. - /// - /// Constant alias for string: `"zenoh/uint64"`. - /// - /// Usually used for types: `u64`. - pub const ZENOH_UINT64: Encoding = Self(zenoh_protocol::core::Encoding { - id: 9, - schema: None, - }); - /// A VLE-encoded unsigned little-endian 128bit integer. - /// - /// Constant alias for string: `"zenoh/uint128"`. - /// - /// Usually used for types: `u128`. - pub const ZENOH_UINT128: Encoding = Self(zenoh_protocol::core::Encoding { - id: 10, - schema: None, - }); - /// A VLE-encoded 32bit float. Binary representation uses *IEEE 754-2008* *binary32* . - /// - /// Constant alias for string: `"zenoh/float32"`. - /// - /// Usually used for types: `f32`. - pub const ZENOH_FLOAT32: Encoding = Self(zenoh_protocol::core::Encoding { - id: 11, - schema: None, - }); - /// A VLE-encoded 64bit float. Binary representation uses *IEEE 754-2008* *binary64*. - /// - /// Constant alias for string: `"zenoh/float64"`. - /// - /// Usually used for types: `f64`. - pub const ZENOH_FLOAT64: Encoding = Self(zenoh_protocol::core::Encoding { - id: 12, - schema: None, - }); - /// A boolean. `0` is `false`, `1` is `true`. Other values are invalid. - /// - /// Constant alias for string: `"zenoh/bool"`. - /// - /// Usually used for types: `bool`. - pub const ZENOH_BOOL: Encoding = Self(zenoh_protocol::core::Encoding { - id: 13, - schema: None, - }); /// A UTF-8 string. /// /// Constant alias for string: `"zenoh/string"`. /// - /// Usually used for types: `String`, `&str`, `Cow`, `char`. + /// This encoding supposes that the payload was created with [`ZBytes::from::`](crate::bytes::ZBytes::from) or similar + /// (`&str`, `Cow`) and its data can be accessed with [`ZBytes::try_to_string()`](crate::bytes::ZBytes::try_to_string) without an error. pub const ZENOH_STRING: Encoding = Self(zenoh_protocol::core::Encoding { - id: 14, + id: 1, schema: None, }); - /// A zenoh error. + + /// Zenoh serialized data. /// - /// Constant alias for string: `"zenoh/error"`. + /// Constant alias for string: `"zenoh/serialization"`. /// - /// Usually used for types: `ReplyError`. - pub const ZENOH_ERROR: Encoding = Self(zenoh_protocol::core::Encoding { - id: 15, + /// This encoding supposes that the payload created with serialization functions provided by `zenoh-ext` crate. + /// The `schema` field may contain the details of the serialization format. + pub const ZENOH_SERIALIZED: Encoding = Self(zenoh_protocol::core::Encoding { + id: 2, schema: None, }); - // - Advanced types may be supported in some of the Zenoh bindings. /// An application-specific stream of bytes. /// /// Constant alias for string: `"application/octet-stream"`. pub const APPLICATION_OCTET_STREAM: Encoding = Self(zenoh_protocol::core::Encoding { - id: 16, + id: 3, schema: None, }); /// A textual file. /// /// Constant alias for string: `"text/plain"`. pub const TEXT_PLAIN: Encoding = Self(zenoh_protocol::core::Encoding { - id: 17, + id: 4, schema: None, }); /// JSON data intended to be consumed by an application. /// /// Constant alias for string: `"application/json"`. pub const APPLICATION_JSON: Encoding = Self(zenoh_protocol::core::Encoding { - id: 18, + id: 5, schema: None, }); /// JSON data intended to be human readable. /// /// Constant alias for string: `"text/json"`. pub const TEXT_JSON: Encoding = Self(zenoh_protocol::core::Encoding { - id: 19, + id: 6, schema: None, }); /// A Common Data Representation (CDR)-encoded data. /// /// Constant alias for string: `"application/cdr"`. pub const APPLICATION_CDR: Encoding = Self(zenoh_protocol::core::Encoding { - id: 20, + id: 7, schema: None, }); /// A Concise Binary Object Representation (CBOR)-encoded data. /// /// Constant alias for string: `"application/cbor"`. pub const APPLICATION_CBOR: Encoding = Self(zenoh_protocol::core::Encoding { - id: 21, + id: 8, schema: None, }); /// YAML data intended to be consumed by an application. /// /// Constant alias for string: `"application/yaml"`. pub const APPLICATION_YAML: Encoding = Self(zenoh_protocol::core::Encoding { - id: 22, + id: 9, schema: None, }); /// YAML data intended to be human readable. /// /// Constant alias for string: `"text/yaml"`. pub const TEXT_YAML: Encoding = Self(zenoh_protocol::core::Encoding { - id: 23, + id: 10, schema: None, }); /// JSON5 encoded data that are human readable. /// /// Constant alias for string: `"text/json5"`. pub const TEXT_JSON5: Encoding = Self(zenoh_protocol::core::Encoding { - id: 24, + id: 11, schema: None, }); /// A Python object serialized using [pickle](https://docs.python.org/3/library/pickle.html). @@ -296,426 +179,400 @@ impl Encoding { /// Constant alias for string: `"application/python-serialized-object"`. pub const APPLICATION_PYTHON_SERIALIZED_OBJECT: Encoding = Self(zenoh_protocol::core::Encoding { - id: 25, + id: 12, schema: None, }); /// An application-specific protobuf-encoded data. /// /// Constant alias for string: `"application/protobuf"`. pub const APPLICATION_PROTOBUF: Encoding = Self(zenoh_protocol::core::Encoding { - id: 26, + id: 13, schema: None, }); /// A Java serialized object. /// /// Constant alias for string: `"application/java-serialized-object"`. pub const APPLICATION_JAVA_SERIALIZED_OBJECT: Encoding = Self(zenoh_protocol::core::Encoding { - id: 27, + id: 14, schema: None, }); /// An [openmetrics](https://github.com/OpenObservability/OpenMetrics) data, common used by [Prometheus](https://prometheus.io/). /// /// Constant alias for string: `"application/openmetrics-text"`. pub const APPLICATION_OPENMETRICS_TEXT: Encoding = Self(zenoh_protocol::core::Encoding { - id: 28, + id: 15, schema: None, }); /// A Portable Network Graphics (PNG) image. /// /// Constant alias for string: `"image/png"`. pub const IMAGE_PNG: Encoding = Self(zenoh_protocol::core::Encoding { - id: 29, + id: 16, schema: None, }); /// A Joint Photographic Experts Group (JPEG) image. /// /// Constant alias for string: `"image/jpeg"`. pub const IMAGE_JPEG: Encoding = Self(zenoh_protocol::core::Encoding { - id: 30, + id: 17, schema: None, }); /// A Graphics Interchange Format (GIF) image. /// /// Constant alias for string: `"image/gif"`. pub const IMAGE_GIF: Encoding = Self(zenoh_protocol::core::Encoding { - id: 31, + id: 18, schema: None, }); /// A BitMap (BMP) image. /// /// Constant alias for string: `"image/bmp"`. pub const IMAGE_BMP: Encoding = Self(zenoh_protocol::core::Encoding { - id: 32, + id: 19, schema: None, }); /// A Web Portable (WebP) image. /// /// Constant alias for string: `"image/webp"`. pub const IMAGE_WEBP: Encoding = Self(zenoh_protocol::core::Encoding { - id: 33, + id: 20, schema: None, }); /// An XML file intended to be consumed by an application.. /// /// Constant alias for string: `"application/xml"`. pub const APPLICATION_XML: Encoding = Self(zenoh_protocol::core::Encoding { - id: 34, + id: 21, schema: None, }); /// An encoded a list of tuples, each consisting of a name and a value. /// /// Constant alias for string: `"application/x-www-form-urlencoded"`. pub const APPLICATION_X_WWW_FORM_URLENCODED: Encoding = Self(zenoh_protocol::core::Encoding { - id: 35, + id: 22, schema: None, }); /// An HTML file. /// /// Constant alias for string: `"text/html"`. pub const TEXT_HTML: Encoding = Self(zenoh_protocol::core::Encoding { - id: 36, + id: 23, schema: None, }); /// An XML file that is human readable. /// /// Constant alias for string: `"text/xml"`. pub const TEXT_XML: Encoding = Self(zenoh_protocol::core::Encoding { - id: 37, + id: 24, schema: None, }); /// A CSS file. /// /// Constant alias for string: `"text/css"`. pub const TEXT_CSS: Encoding = Self(zenoh_protocol::core::Encoding { - id: 38, + id: 25, schema: None, }); /// A JavaScript file. /// /// Constant alias for string: `"text/javascript"`. pub const TEXT_JAVASCRIPT: Encoding = Self(zenoh_protocol::core::Encoding { - id: 39, + id: 26, schema: None, }); /// A MarkDown file. /// /// Constant alias for string: `"text/markdown"`. pub const TEXT_MARKDOWN: Encoding = Self(zenoh_protocol::core::Encoding { - id: 40, + id: 27, schema: None, }); /// A CSV file. /// /// Constant alias for string: `"text/csv"`. pub const TEXT_CSV: Encoding = Self(zenoh_protocol::core::Encoding { - id: 41, + id: 28, schema: None, }); /// An application-specific SQL query. /// /// Constant alias for string: `"application/sql"`. pub const APPLICATION_SQL: Encoding = Self(zenoh_protocol::core::Encoding { - id: 42, + id: 29, schema: None, }); /// Constrained Application Protocol (CoAP) data intended for CoAP-to-HTTP and HTTP-to-CoAP proxies. /// /// Constant alias for string: `"application/coap-payload"`. pub const APPLICATION_COAP_PAYLOAD: Encoding = Self(zenoh_protocol::core::Encoding { - id: 43, + id: 30, schema: None, }); /// Defines a JSON document structure for expressing a sequence of operations to apply to a JSON document. /// /// Constant alias for string: `"application/json-patch+json"`. pub const APPLICATION_JSON_PATCH_JSON: Encoding = Self(zenoh_protocol::core::Encoding { - id: 44, + id: 31, schema: None, }); /// A JSON text sequence consists of any number of JSON texts, all encoded in UTF-8. /// /// Constant alias for string: `"application/json-seq"`. pub const APPLICATION_JSON_SEQ: Encoding = Self(zenoh_protocol::core::Encoding { - id: 45, + id: 32, schema: None, }); /// A JSONPath defines a string syntax for selecting and extracting JSON values from within a given JSON value. /// /// Constant alias for string: `"application/jsonpath"`. pub const APPLICATION_JSONPATH: Encoding = Self(zenoh_protocol::core::Encoding { - id: 46, + id: 33, schema: None, }); /// A JSON Web Token (JWT). /// /// Constant alias for string: `"application/jwt"`. pub const APPLICATION_JWT: Encoding = Self(zenoh_protocol::core::Encoding { - id: 47, + id: 34, schema: None, }); /// An application-specific MPEG-4 encoded data, either audio or video. /// /// Constant alias for string: `"application/mp4"`. pub const APPLICATION_MP4: Encoding = Self(zenoh_protocol::core::Encoding { - id: 48, + id: 35, schema: None, }); /// A SOAP 1.2 message serialized as XML 1.0. /// /// Constant alias for string: `"application/soap+xml"`. pub const APPLICATION_SOAP_XML: Encoding = Self(zenoh_protocol::core::Encoding { - id: 49, + id: 36, schema: None, }); /// A YANG-encoded data commonly used by the Network Configuration Protocol (NETCONF). /// /// Constant alias for string: `"application/yang"`. pub const APPLICATION_YANG: Encoding = Self(zenoh_protocol::core::Encoding { - id: 50, + id: 37, schema: None, }); /// A MPEG-4 Advanced Audio Coding (AAC) media. /// /// Constant alias for string: `"audio/aac"`. pub const AUDIO_AAC: Encoding = Self(zenoh_protocol::core::Encoding { - id: 51, + id: 38, schema: None, }); /// A Free Lossless Audio Codec (FLAC) media. /// /// Constant alias for string: `"audio/flac"`. pub const AUDIO_FLAC: Encoding = Self(zenoh_protocol::core::Encoding { - id: 52, + id: 39, schema: None, }); /// An audio codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. /// /// Constant alias for string: `"audio/mp4"`. pub const AUDIO_MP4: Encoding = Self(zenoh_protocol::core::Encoding { - id: 53, + id: 40, schema: None, }); /// An Ogg-encapsulated audio stream. /// /// Constant alias for string: `"audio/ogg"`. pub const AUDIO_OGG: Encoding = Self(zenoh_protocol::core::Encoding { - id: 54, + id: 41, schema: None, }); /// A Vorbis-encoded audio stream. /// /// Constant alias for string: `"audio/vorbis"`. pub const AUDIO_VORBIS: Encoding = Self(zenoh_protocol::core::Encoding { - id: 55, + id: 42, schema: None, }); /// A h261-encoded video stream. /// /// Constant alias for string: `"video/h261"`. pub const VIDEO_H261: Encoding = Self(zenoh_protocol::core::Encoding { - id: 56, + id: 43, schema: None, }); /// A h263-encoded video stream. /// /// Constant alias for string: `"video/h263"`. pub const VIDEO_H263: Encoding = Self(zenoh_protocol::core::Encoding { - id: 57, + id: 44, schema: None, }); /// A h264-encoded video stream. /// /// Constant alias for string: `"video/h264"`. pub const VIDEO_H264: Encoding = Self(zenoh_protocol::core::Encoding { - id: 58, + id: 45, schema: None, }); /// A h265-encoded video stream. /// /// Constant alias for string: `"video/h265"`. pub const VIDEO_H265: Encoding = Self(zenoh_protocol::core::Encoding { - id: 59, + id: 46, schema: None, }); /// A h266-encoded video stream. /// /// Constant alias for string: `"video/h266"`. pub const VIDEO_H266: Encoding = Self(zenoh_protocol::core::Encoding { - id: 60, + id: 47, schema: None, }); /// A video codec defined in MPEG-1, MPEG-2, MPEG-4, or registered at the MP4 registration authority. /// /// Constant alias for string: `"video/mp4"`. pub const VIDEO_MP4: Encoding = Self(zenoh_protocol::core::Encoding { - id: 61, + id: 48, schema: None, }); /// An Ogg-encapsulated video stream. /// /// Constant alias for string: `"video/ogg"`. pub const VIDEO_OGG: Encoding = Self(zenoh_protocol::core::Encoding { - id: 62, + id: 49, schema: None, }); /// An uncompressed, studio-quality video stream. /// /// Constant alias for string: `"video/raw"`. pub const VIDEO_RAW: Encoding = Self(zenoh_protocol::core::Encoding { - id: 63, + id: 50, schema: None, }); /// A VP8-encoded video stream. /// /// Constant alias for string: `"video/vp8"`. pub const VIDEO_VP8: Encoding = Self(zenoh_protocol::core::Encoding { - id: 64, + id: 51, schema: None, }); /// A VP9-encoded video stream. /// /// Constant alias for string: `"video/vp9"`. pub const VIDEO_VP9: Encoding = Self(zenoh_protocol::core::Encoding { - id: 65, + id: 52, schema: None, }); const ID_TO_STR: phf::Map = phf_map! { 0u16 => "zenoh/bytes", - 1u16 => "zenoh/int8", - 2u16 => "zenoh/int16", - 3u16 => "zenoh/int32", - 4u16 => "zenoh/int64", - 5u16 => "zenoh/int128", - 6u16 => "zenoh/uint8", - 7u16 => "zenoh/uint16", - 8u16 => "zenoh/uint32", - 9u16 => "zenoh/uint64", - 10u16 => "zenoh/uint128", - 11u16 => "zenoh/float32", - 12u16 => "zenoh/float64", - 13u16 => "zenoh/bool", - 14u16 => "zenoh/string", - 15u16 => "zenoh/error", - 16u16 => "application/octet-stream", - 17u16 => "text/plain", - 18u16 => "application/json", - 19u16 => "text/json", - 20u16 => "application/cdr", - 21u16 => "application/cbor", - 22u16 => "application/yaml", - 23u16 => "text/yaml", - 24u16 => "text/json5", - 25u16 => "application/python-serialized-object", - 26u16 => "application/protobuf", - 27u16 => "application/java-serialized-object", - 28u16 => "application/openmetrics-text", - 29u16 => "image/png", - 30u16 => "image/jpeg", - 31u16 => "image/gif", - 32u16 => "image/bmp", - 33u16 => "image/webp", - 34u16 => "application/xml", - 35u16 => "application/x-www-form-urlencoded", - 36u16 => "text/html", - 37u16 => "text/xml", - 38u16 => "text/css", - 39u16 => "text/javascript", - 40u16 => "text/markdown", - 41u16 => "text/csv", - 42u16 => "application/sql", - 43u16 => "application/coap-payload", - 44u16 => "application/json-patch+json", - 45u16 => "application/json-seq", - 46u16 => "application/jsonpath", - 47u16 => "application/jwt", - 48u16 => "application/mp4", - 49u16 => "application/soap+xml", - 50u16 => "application/yang", - 51u16 => "audio/aac", - 52u16 => "audio/flac", - 53u16 => "audio/mp4", - 54u16 => "audio/ogg", - 55u16 => "audio/vorbis", - 56u16 => "video/h261", - 57u16 => "video/h263", - 58u16 => "video/h264", - 59u16 => "video/h265", - 60u16 => "video/h266", - 61u16 => "video/mp4", - 62u16 => "video/ogg", - 63u16 => "video/raw", - 64u16 => "video/vp8", - 65u16 => "video/vp9", + 1u16 => "zenoh/string", + 2u16 => "zenoh/serialized", + 3u16 => "application/octet-stream", + 4u16 => "text/plain", + 5u16 => "application/json", + 6u16 => "text/json", + 7u16 => "application/cdr", + 8u16 => "application/cbor", + 9u16 => "application/yaml", + 10u16 => "text/yaml", + 11u16 => "text/json5", + 12u16 => "application/python-serialized-object", + 13u16 => "application/protobuf", + 14u16 => "application/java-serialized-object", + 15u16 => "application/openmetrics-text", + 16u16 => "image/png", + 17u16 => "image/jpeg", + 18u16 => "image/gif", + 19u16 => "image/bmp", + 20u16 => "image/webp", + 21u16 => "application/xml", + 22u16 => "application/x-www-form-urlencoded", + 23u16 => "text/html", + 24u16 => "text/xml", + 25u16 => "text/css", + 26u16 => "text/javascript", + 27u16 => "text/markdown", + 28u16 => "text/csv", + 29u16 => "application/sql", + 30u16 => "application/coap-payload", + 31u16 => "application/json-patch+json", + 32u16 => "application/json-seq", + 33u16 => "application/jsonpath", + 34u16 => "application/jwt", + 35u16 => "application/mp4", + 36u16 => "application/soap+xml", + 37u16 => "application/yang", + 38u16 => "audio/aac", + 39u16 => "audio/flac", + 40u16 => "audio/mp4", + 41u16 => "audio/ogg", + 42u16 => "audio/vorbis", + 43u16 => "video/h261", + 44u16 => "video/h263", + 45u16 => "video/h264", + 46u16 => "video/h265", + 47u16 => "video/h266", + 48u16 => "video/mp4", + 49u16 => "video/ogg", + 50u16 => "video/raw", + 51u16 => "video/vp8", + 52u16 => "video/vp9", }; const STR_TO_ID: phf::Map<&'static str, EncodingId> = phf_map! { "zenoh/bytes" => 0u16, - "zenoh/int8" => 1u16, - "zenoh/int16" => 2u16, - "zenoh/int32" => 3u16, - "zenoh/int64" => 4u16, - "zenoh/int128" => 5u16, - "zenoh/uint8" => 6u16, - "zenoh/uint16" => 7u16, - "zenoh/uint32" => 8u16, - "zenoh/uint64" => 9u16, - "zenoh/uint128" => 10u16, - "zenoh/float32" => 11u16, - "zenoh/float64" => 12u16, - "zenoh/bool" => 13u16, - "zenoh/string" => 14u16, - "zenoh/error" => 15u16, - "application/octet-stream" => 16u16, - "text/plain" => 17u16, - "application/json" => 18u16, - "text/json" => 19u16, - "application/cdr" => 20u16, - "application/cbor" => 21u16, - "application/yaml" => 22u16, - "text/yaml" => 23u16, - "text/json5" => 24u16, - "application/python-serialized-object" => 25u16, - "application/protobuf" => 26u16, - "application/java-serialized-object" => 27u16, - "application/openmetrics-text" => 28u16, - "image/png" => 29u16, - "image/jpeg" => 30u16, - "image/gif" => 31u16, - "image/bmp" => 32u16, - "image/webp" => 33u16, - "application/xml" => 34u16, - "application/x-www-form-urlencoded" => 35u16, - "text/html" => 36u16, - "text/xml" => 37u16, - "text/css" => 38u16, - "text/javascript" => 39u16, - "text/markdown" => 40u16, - "text/csv" => 41u16, - "application/sql" => 42u16, - "application/coap-payload" => 43u16, - "application/json-patch+json" => 44u16, - "application/json-seq" => 45u16, - "application/jsonpath" => 46u16, - "application/jwt" => 47u16, - "application/mp4" => 48u16, - "application/soap+xml" => 49u16, - "application/yang" => 50u16, - "audio/aac" => 51u16, - "audio/flac" => 52u16, - "audio/mp4" => 53u16, - "audio/ogg" => 54u16, - "audio/vorbis" => 55u16, - "video/h261" => 56u16, - "video/h263" => 57u16, - "video/h264" => 58u16, - "video/h265" => 59u16, - "video/h266" => 60u16, - "video/mp4" => 61u16, - "video/ogg" => 62u16, - "video/raw" => 63u16, - "video/vp8" => 64u16, - "video/vp9" => 65u16, + "zenoh/string" => 1u16, + "zenoh/serialized" => 2u16, + "application/octet-stream" => 3u16, + "text/plain" => 4u16, + "application/json" => 5u16, + "text/json" => 6u16, + "application/cdr" => 7u16, + "application/cbor" => 8u16, + "application/yaml" => 9u16, + "text/yaml" => 10u16, + "text/json5" => 11u16, + "application/python-serialized-object" => 12u16, + "application/protobuf" => 13u16, + "application/java-serialized-object" => 14u16, + "application/openmetrics-text" => 15u16, + "image/png" => 16u16, + "image/jpeg" => 17u16, + "image/gif" => 18u16, + "image/bmp" => 19u16, + "image/webp" => 20u16, + "application/xml" => 21u16, + "application/x-www-form-urlencoded" => 22u16, + "text/html" => 23u16, + "text/xml" => 24u16, + "text/css" => 25u16, + "text/javascript" => 26u16, + "text/markdown" => 27u16, + "text/csv" => 28u16, + "application/sql" => 29u16, + "application/coap-payload" => 30u16, + "application/json-patch+json" => 31u16, + "application/json-seq" => 32u16, + "application/jsonpath" => 33u16, + "application/jwt" => 34u16, + "application/mp4" => 35u16, + "application/soap+xml" => 36u16, + "application/yang" => 37u16, + "audio/aac" => 38u16, + "audio/flac" => 39u16, + "audio/mp4" => 40u16, + "audio/ogg" => 41u16, + "audio/vorbis" => 42u16, + "video/h261" => 43u16, + "video/h263" => 44u16, + "video/h264" => 45u16, + "video/h265" => 46u16, + "video/h266" => 47u16, + "video/mp4" => 48u16, + "video/ogg" => 49u16, + "video/raw" => 50u16, + "video/vp8" => 51u16, + "video/vp9" => 52u16, }; /// The default [`Encoding`] is [`ZENOH_BYTES`](Encoding::ZENOH_BYTES). @@ -839,141 +696,6 @@ impl fmt::Display for Encoding { } } -#[allow(dead_code)] -// - Encoding trait -pub trait EncodingMapping { - const ENCODING: Encoding; -} - -// Bytes -impl EncodingMapping for ZBytes { - const ENCODING: Encoding = Encoding::ZENOH_BYTES; -} - -impl EncodingMapping for ZBuf { - const ENCODING: Encoding = Encoding::ZENOH_BYTES; -} - -impl EncodingMapping for Vec { - const ENCODING: Encoding = Encoding::ZENOH_BYTES; -} - -impl EncodingMapping for &[u8] { - const ENCODING: Encoding = Encoding::ZENOH_BYTES; -} - -impl EncodingMapping for Cow<'_, [u8]> { - const ENCODING: Encoding = Encoding::ZENOH_BYTES; -} - -// String -impl EncodingMapping for String { - const ENCODING: Encoding = Encoding::ZENOH_STRING; -} - -impl EncodingMapping for &str { - const ENCODING: Encoding = Encoding::ZENOH_STRING; -} - -impl EncodingMapping for Cow<'_, str> { - const ENCODING: Encoding = Encoding::ZENOH_STRING; -} - -// Zenoh unsigned integers -impl EncodingMapping for u8 { - const ENCODING: Encoding = Encoding::ZENOH_UINT8; -} - -impl EncodingMapping for u16 { - const ENCODING: Encoding = Encoding::ZENOH_UINT16; -} - -impl EncodingMapping for u32 { - const ENCODING: Encoding = Encoding::ZENOH_UINT32; -} - -impl EncodingMapping for u64 { - const ENCODING: Encoding = Encoding::ZENOH_UINT64; -} - -impl EncodingMapping for u128 { - const ENCODING: Encoding = Encoding::ZENOH_UINT128; -} - -impl EncodingMapping for usize { - #[cfg(target_pointer_width = "16")] - const ENCODING: Encoding = Encoding::ZENOH_UINT16; - #[cfg(target_pointer_width = "32")] - const ENCODING: Encoding = Encoding::ZENOH_UINT32; - #[cfg(target_pointer_width = "64")] - const ENCODING: Encoding = Encoding::ZENOH_UINT64; -} - -// Zenoh signed integers -impl EncodingMapping for i8 { - const ENCODING: Encoding = Encoding::ZENOH_INT8; -} - -impl EncodingMapping for i16 { - const ENCODING: Encoding = Encoding::ZENOH_INT16; -} - -impl EncodingMapping for i32 { - const ENCODING: Encoding = Encoding::ZENOH_INT32; -} - -impl EncodingMapping for i64 { - const ENCODING: Encoding = Encoding::ZENOH_INT64; -} - -impl EncodingMapping for i128 { - const ENCODING: Encoding = Encoding::ZENOH_INT128; -} - -impl EncodingMapping for isize { - #[cfg(target_pointer_width = "8")] - const ENCODING: Encoding = Encoding::ZENOH_INT8; - #[cfg(target_pointer_width = "16")] - const ENCODING: Encoding = Encoding::ZENOH_INT16; - #[cfg(target_pointer_width = "32")] - const ENCODING: Encoding = Encoding::ZENOH_INT32; - #[cfg(target_pointer_width = "64")] - const ENCODING: Encoding = Encoding::ZENOH_INT64; - #[cfg(target_pointer_width = "128")] - const ENCODING: Encoding = Encoding::ZENOH_INT128; -} - -// Zenoh floats -impl EncodingMapping for f32 { - const ENCODING: Encoding = Encoding::ZENOH_FLOAT32; -} - -impl EncodingMapping for f64 { - const ENCODING: Encoding = Encoding::ZENOH_FLOAT64; -} - -// Zenoh bool -impl EncodingMapping for bool { - const ENCODING: Encoding = Encoding::ZENOH_BOOL; -} - -// - Zenoh advanced types encoders/decoders -impl EncodingMapping for serde_json::Value { - const ENCODING: Encoding = Encoding::APPLICATION_JSON; -} - -impl EncodingMapping for serde_yaml::Value { - const ENCODING: Encoding = Encoding::APPLICATION_YAML; -} - -impl EncodingMapping for serde_cbor::Value { - const ENCODING: Encoding = Encoding::APPLICATION_CBOR; -} - -impl EncodingMapping for serde_pickle::Value { - const ENCODING: Encoding = Encoding::APPLICATION_PYTHON_SERIALIZED_OBJECT; -} - impl Encoding { #[zenoh_macros::internal] pub fn id(&self) -> EncodingId { @@ -988,13 +710,3 @@ impl Encoding { Encoding(zenoh_protocol::core::Encoding { id, schema }) } } - -// - Zenoh SHM -#[cfg(feature = "shared-memory")] -impl EncodingMapping for ZShm { - const ENCODING: Encoding = Encoding::ZENOH_BYTES; -} -#[cfg(feature = "shared-memory")] -impl EncodingMapping for ZShmMut { - const ENCODING: Encoding = Encoding::ZENOH_BYTES; -}