mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 09:09:17 +00:00
feat: string deserialization for prost enums (#2316)
Use pbjson to support string deserialization for enum fields
This allows TOML configs like:
chainType = "Inbound"
instead of:
chainType = 1
- Maintain backward compatibility with integer values
- Default serialization format is now string
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/acl.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/acl.serde.rs"));
|
||||
|
||||
impl Acl {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
pub mod config {
|
||||
include!(concat!(env!("OUT_DIR"), "/api.config.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/api.config.serde.rs"));
|
||||
|
||||
pub struct Patchable<T> {
|
||||
pub action: Option<ConfigPatchAction>,
|
||||
pub value: Option<T>,
|
||||
@@ -77,6 +79,7 @@ pub mod config {
|
||||
|
||||
pub mod instance {
|
||||
include!(concat!(env!("OUT_DIR"), "/api.instance.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/api.instance.serde.rs"));
|
||||
|
||||
impl PeerRoutePair {
|
||||
pub fn get_latency_ms(&self) -> Option<f64> {
|
||||
@@ -229,10 +232,12 @@ pub mod instance {
|
||||
|
||||
pub mod logger {
|
||||
include!(concat!(env!("OUT_DIR"), "/api.logger.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/api.logger.serde.rs"));
|
||||
}
|
||||
|
||||
pub mod manage {
|
||||
include!(concat!(env!("OUT_DIR"), "/api.manage.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/api.manage.serde.rs"));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
use anyhow::Context;
|
||||
use base64::{Engine as _, prelude::BASE64_STANDARD};
|
||||
use std::time::SystemTime;
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use base64::{Engine as _, prelude::BASE64_STANDARD};
|
||||
use strum::VariantArray;
|
||||
|
||||
use crate::tunnel::{IpScheme, packet_def::CompressorAlgo};
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/common.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/common.serde.rs"));
|
||||
|
||||
pub trait TimestampExt {
|
||||
fn now() -> Self;
|
||||
}
|
||||
|
||||
impl TimestampExt for prost_wkt_types::Timestamp {
|
||||
fn now() -> Self {
|
||||
SystemTime::now().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<uuid::Uuid> for Uuid {
|
||||
fn from(uuid: uuid::Uuid) -> Self {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#![allow(clippy::module_inception)]
|
||||
|
||||
use prost::DecodeError;
|
||||
|
||||
use super::rpc_types;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/error.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/error.serde.rs"));
|
||||
|
||||
impl From<&rpc_types::error::Error> for Error {
|
||||
fn from(e: &rpc_types::error::Error) -> Self {
|
||||
@@ -15,10 +14,10 @@ impl From<&rpc_types::error::Error> for Error {
|
||||
error_message: format!("{:?}", e),
|
||||
})),
|
||||
},
|
||||
rpc_types::error::Error::DecodeError(_) => Self {
|
||||
rpc_types::error::Error::DecodeError => Self {
|
||||
error_kind: Some(ProtoError::ProstDecodeError(ProstDecodeError {})),
|
||||
},
|
||||
rpc_types::error::Error::EncodeError(_) => Self {
|
||||
rpc_types::error::Error::EncodeError => Self {
|
||||
error_kind: Some(ProtoError::ProstEncodeError(ProstEncodeError {})),
|
||||
},
|
||||
rpc_types::error::Error::InvalidMethodIndex(m, s) => Self {
|
||||
@@ -59,12 +58,8 @@ impl From<&Error> for rpc_types::error::Error {
|
||||
Some(ProtoError::ExecuteError(e)) => {
|
||||
Self::ExecutionError(anyhow::anyhow!(e.error_message.clone()))
|
||||
}
|
||||
Some(ProtoError::ProstDecodeError(_)) => {
|
||||
Self::DecodeError(DecodeError::new("decode error"))
|
||||
}
|
||||
Some(ProtoError::ProstEncodeError(_)) => {
|
||||
Self::DecodeError(DecodeError::new("encode error"))
|
||||
}
|
||||
Some(ProtoError::ProstDecodeError(_)) => Self::DecodeError,
|
||||
Some(ProtoError::ProstEncodeError(_)) => Self::EncodeError,
|
||||
Some(ProtoError::InvalidMethodIndex(e)) => {
|
||||
Self::InvalidMethodIndex(e.method_index as u8, e.service_name.clone())
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
include!(concat!(env!("OUT_DIR"), "/magic_dns.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/magic_dns.serde.rs"));
|
||||
|
||||
@@ -5,6 +5,7 @@ use sha2::Sha256;
|
||||
use crate::common::PeerId;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/peer_rpc.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/peer_rpc.serde.rs"));
|
||||
|
||||
impl PeerGroupInfo {
|
||||
pub fn generate_with_proof(group_name: String, group_secret: String, peer_id: PeerId) -> Self {
|
||||
|
||||
@@ -9,11 +9,11 @@ pub enum Error {
|
||||
#[error("Rust error: {0}")]
|
||||
ExecutionError(#[from] anyhow::Error),
|
||||
|
||||
#[error("Decode error: {0}")]
|
||||
DecodeError(#[from] prost::DecodeError),
|
||||
#[error("Decode error")]
|
||||
DecodeError,
|
||||
|
||||
#[error("Encode error: {0}")]
|
||||
EncodeError(#[from] prost::EncodeError),
|
||||
#[error("Encode error")]
|
||||
EncodeError,
|
||||
|
||||
#[error("Invalid method index: {0}, service: {1}")]
|
||||
InvalidMethodIndex(u8, String),
|
||||
@@ -34,4 +34,16 @@ pub enum Error {
|
||||
Shutdown,
|
||||
}
|
||||
|
||||
impl From<prost::DecodeError> for Error {
|
||||
fn from(_: prost::DecodeError) -> Self {
|
||||
Error::DecodeError
|
||||
}
|
||||
}
|
||||
|
||||
impl From<prost::EncodeError> for Error {
|
||||
fn from(_: prost::EncodeError) -> Self {
|
||||
Error::EncodeError
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
include!(concat!(env!("OUT_DIR"), "/tests.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/tests.serde.rs"));
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
include!(concat!(env!("OUT_DIR"), "/web.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/web.serde.rs"));
|
||||
|
||||
Reference in New Issue
Block a user