Skip to content

Commit

Permalink
Derive Deserialize for enums used in remote-api-plugin (#1653)
Browse files Browse the repository at this point in the history
* Derive Deserialize for enums used in remote-api-plugin

* Fix clippy lints

* import Deserialize, Add back Copy for ConsolidationMode

* removed uneeded as_bytes()

* fix clippy concat_enabled_features, move Serialize to Unstable
  • Loading branch information
Charles-Schleich authored Jan 16, 2025
1 parent ea014f4 commit a78dac5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions commons/zenoh-protocol/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -454,7 +454,7 @@ impl TryFrom<u8> 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,
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion commons/zenoh-protocol/src/network/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion commons/zenoh-protocol/src/zenoh/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, Copy, Deserialize)]
pub enum ConsolidationMode {
/// Apply automatic consolidation based on queryable's preferences
#[default]
Expand Down
3 changes: 2 additions & 1 deletion zenoh/src/api/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::{
};

use futures::Sink;
use serde::Deserialize;
use tracing::error;
use zenoh_config::qos::PublisherPriorityConf;
use zenoh_core::{Resolvable, Resolve, Wait};
Expand Down Expand Up @@ -424,7 +425,7 @@ impl Sink<Sample> 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,
Expand Down
4 changes: 3 additions & 1 deletion zenoh/src/api/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

use std::{collections::HashMap, error::Error, fmt::Display};

#[cfg(feature = "unstable")]
use serde::Deserialize;
#[cfg(feature = "unstable")]
use zenoh_config::ZenohId;
use zenoh_keyexpr::OwnedKeyExpr;
Expand Down Expand Up @@ -172,7 +174,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,
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/api/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a78dac5

Please sign in to comment.