From e4c4110548de2fc21164e87bb8a368e8109675bb Mon Sep 17 00:00:00 2001 From: Charles Schleich Date: Tue, 10 Dec 2024 18:24:05 +0100 Subject: [PATCH] Derive Deserialize for enums used in remote-api-plugin --- commons/zenoh-protocol/src/core/mod.rs | 6 +++--- commons/zenoh-protocol/src/network/request.rs | 4 +++- commons/zenoh-protocol/src/zenoh/query.rs | 4 +++- zenoh/src/api/publisher.rs | 2 +- zenoh/src/api/query.rs | 2 +- zenoh/src/api/sample.rs | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/commons/zenoh-protocol/src/core/mod.rs b/commons/zenoh-protocol/src/core/mod.rs index c9cc605c91..d3eeb68fae 100644 --- a/commons/zenoh-protocol/src/core/mod.rs +++ b/commons/zenoh-protocol/src/core/mod.rs @@ -25,7 +25,7 @@ use core::{ str::FromStr, }; -use serde::Serialize; +use serde::{Deserialize, Serialize}; pub use uhlc::{Timestamp, NTP64}; use zenoh_keyexpr::OwnedKeyExpr; use zenoh_result::{bail, zerror}; @@ -454,7 +454,7 @@ impl TryFrom for Priority { } } -#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash, Serialize)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] #[repr(u8)] pub enum Reliability { BestEffort = 0, @@ -560,7 +560,7 @@ impl Channel { } /// Congestion control strategy. -#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize)] #[repr(u8)] pub enum CongestionControl { #[default] diff --git a/commons/zenoh-protocol/src/network/request.rs b/commons/zenoh-protocol/src/network/request.rs index 3fd9eb2217..7ebfbb5d22 100644 --- a/commons/zenoh-protocol/src/network/request.rs +++ b/commons/zenoh-protocol/src/network/request.rs @@ -67,6 +67,8 @@ pub struct Request { pub mod ext { use core::{num::NonZeroU32, time::Duration}; + use serde::Deserialize; + use crate::{ common::{ZExtZ64, ZExtZBuf}, zextz64, zextzbuf, @@ -91,7 +93,7 @@ pub mod ext { // ``` // The `zenoh::queryable::Queryable`s that should be target of a `zenoh::Session::get()`. #[repr(u8)] - #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] + #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize)] pub enum QueryTarget { /// Let Zenoh find the BestMatching queryable capabale of serving the query. #[default] diff --git a/commons/zenoh-protocol/src/zenoh/query.rs b/commons/zenoh-protocol/src/zenoh/query.rs index 49ac3e6d52..1db34c19bd 100644 --- a/commons/zenoh-protocol/src/zenoh/query.rs +++ b/commons/zenoh-protocol/src/zenoh/query.rs @@ -13,11 +13,13 @@ // use alloc::{string::String, vec::Vec}; +use serde::Deserialize; + use crate::common::ZExtUnknown; /// The kind of consolidation to apply to a query. #[repr(u8)] -#[derive(Debug, Default, Clone, PartialEq, Eq, Copy)] +#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize)] pub enum ConsolidationMode { /// Apply automatic consolidation based on queryable's preferences #[default] diff --git a/zenoh/src/api/publisher.rs b/zenoh/src/api/publisher.rs index 1217a12382..81c93e4884 100644 --- a/zenoh/src/api/publisher.rs +++ b/zenoh/src/api/publisher.rs @@ -419,7 +419,7 @@ impl Sink for Publisher<'_> { /// If QoS is enabled, Zenoh keeps one transmission queue per [`Priority`] P, where all messages in /// the queue have [`Priority`] P. These queues are serviced in the order of their assigned /// [`Priority`] (i.e. from [`Priority::RealTime`] to [`Priority::Background`]). -#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Deserialize)] #[repr(u8)] pub enum Priority { RealTime = 1, diff --git a/zenoh/src/api/query.rs b/zenoh/src/api/query.rs index 8eff89831a..3675bccb71 100644 --- a/zenoh/src/api/query.rs +++ b/zenoh/src/api/query.rs @@ -167,7 +167,7 @@ impl QueryState { } /// The kind of accepted query replies. #[zenoh_macros::unstable] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Deserialize)] pub enum ReplyKeyExpr { /// Accept replies whose key expressions may not match the query key expression. Any, diff --git a/zenoh/src/api/sample.rs b/zenoh/src/api/sample.rs index 27b43b1b89..0809b262f1 100644 --- a/zenoh/src/api/sample.rs +++ b/zenoh/src/api/sample.rs @@ -34,7 +34,7 @@ pub type SourceSn = u32; /// The locality of samples to be received by subscribers or targeted by publishers. #[zenoh_macros::unstable] -#[derive(Clone, Copy, Debug, Default, Serialize, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq)] pub enum Locality { SessionLocal, Remote,