// @generated impl serde::Serialize for LocalRateLimitDescriptor { #[allow(deprecated)] fn serialize(&self, serializer: S) -> std::result::Result where S: serde::Serializer, { use serde::ser::SerializeStruct; let mut len = 0; if !self.entries.is_empty() { len += 1; } if self.token_bucket.is_some() { len += 1; } let mut struct_ser = serializer.serialize_struct("envoy.extensions.common.ratelimit.v3.LocalRateLimitDescriptor", len)?; if !self.entries.is_empty() { struct_ser.serialize_field("entries", &self.entries)?; } if let Some(v) = self.token_bucket.as_ref() { struct_ser.serialize_field("tokenBucket", v)?; } struct_ser.end() } } impl<'de> serde::Deserialize<'de> for LocalRateLimitDescriptor { #[allow(deprecated)] fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { const FIELDS: &[&str] = &[ "entries", "token_bucket", "tokenBucket", ]; #[allow(clippy::enum_variant_names)] enum GeneratedField { Entries, TokenBucket, } impl<'de> serde::Deserialize<'de> for GeneratedField { fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = GeneratedField; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(formatter, "expected one of: {:?}", &FIELDS) } #[allow(unused_variables)] fn visit_str(self, value: &str) -> std::result::Result where E: serde::de::Error, { match value { "entries" => Ok(GeneratedField::Entries), "tokenBucket" | "token_bucket" => Ok(GeneratedField::TokenBucket), _ => Err(serde::de::Error::unknown_field(value, FIELDS)), } } } deserializer.deserialize_identifier(GeneratedVisitor) } } struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = LocalRateLimitDescriptor; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("struct envoy.extensions.common.ratelimit.v3.LocalRateLimitDescriptor") } fn visit_map(self, mut map: V) -> std::result::Result where V: serde::de::MapAccess<'de>, { let mut entries__ = None; let mut token_bucket__ = None; while let Some(k) = map.next_key()? { match k { GeneratedField::Entries => { if entries__.is_some() { return Err(serde::de::Error::duplicate_field("entries")); } entries__ = Some(map.next_value()?); } GeneratedField::TokenBucket => { if token_bucket__.is_some() { return Err(serde::de::Error::duplicate_field("tokenBucket")); } token_bucket__ = map.next_value()?; } } } Ok(LocalRateLimitDescriptor { entries: entries__.unwrap_or_default(), token_bucket: token_bucket__, }) } } deserializer.deserialize_struct("envoy.extensions.common.ratelimit.v3.LocalRateLimitDescriptor", FIELDS, GeneratedVisitor) } } impl serde::Serialize for RateLimitDescriptor { #[allow(deprecated)] fn serialize(&self, serializer: S) -> std::result::Result where S: serde::Serializer, { use serde::ser::SerializeStruct; let mut len = 0; if !self.entries.is_empty() { len += 1; } if self.limit.is_some() { len += 1; } let mut struct_ser = serializer.serialize_struct("envoy.extensions.common.ratelimit.v3.RateLimitDescriptor", len)?; if !self.entries.is_empty() { struct_ser.serialize_field("entries", &self.entries)?; } if let Some(v) = self.limit.as_ref() { struct_ser.serialize_field("limit", v)?; } struct_ser.end() } } impl<'de> serde::Deserialize<'de> for RateLimitDescriptor { #[allow(deprecated)] fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { const FIELDS: &[&str] = &[ "entries", "limit", ]; #[allow(clippy::enum_variant_names)] enum GeneratedField { Entries, Limit, } impl<'de> serde::Deserialize<'de> for GeneratedField { fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = GeneratedField; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(formatter, "expected one of: {:?}", &FIELDS) } #[allow(unused_variables)] fn visit_str(self, value: &str) -> std::result::Result where E: serde::de::Error, { match value { "entries" => Ok(GeneratedField::Entries), "limit" => Ok(GeneratedField::Limit), _ => Err(serde::de::Error::unknown_field(value, FIELDS)), } } } deserializer.deserialize_identifier(GeneratedVisitor) } } struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = RateLimitDescriptor; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("struct envoy.extensions.common.ratelimit.v3.RateLimitDescriptor") } fn visit_map(self, mut map: V) -> std::result::Result where V: serde::de::MapAccess<'de>, { let mut entries__ = None; let mut limit__ = None; while let Some(k) = map.next_key()? { match k { GeneratedField::Entries => { if entries__.is_some() { return Err(serde::de::Error::duplicate_field("entries")); } entries__ = Some(map.next_value()?); } GeneratedField::Limit => { if limit__.is_some() { return Err(serde::de::Error::duplicate_field("limit")); } limit__ = map.next_value()?; } } } Ok(RateLimitDescriptor { entries: entries__.unwrap_or_default(), limit: limit__, }) } } deserializer.deserialize_struct("envoy.extensions.common.ratelimit.v3.RateLimitDescriptor", FIELDS, GeneratedVisitor) } } impl serde::Serialize for rate_limit_descriptor::Entry { #[allow(deprecated)] fn serialize(&self, serializer: S) -> std::result::Result where S: serde::Serializer, { use serde::ser::SerializeStruct; let mut len = 0; if !self.key.is_empty() { len += 1; } if !self.value.is_empty() { len += 1; } let mut struct_ser = serializer.serialize_struct("envoy.extensions.common.ratelimit.v3.RateLimitDescriptor.Entry", len)?; if !self.key.is_empty() { struct_ser.serialize_field("key", &self.key)?; } if !self.value.is_empty() { struct_ser.serialize_field("value", &self.value)?; } struct_ser.end() } } impl<'de> serde::Deserialize<'de> for rate_limit_descriptor::Entry { #[allow(deprecated)] fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { const FIELDS: &[&str] = &[ "key", "value", ]; #[allow(clippy::enum_variant_names)] enum GeneratedField { Key, Value, } impl<'de> serde::Deserialize<'de> for GeneratedField { fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = GeneratedField; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(formatter, "expected one of: {:?}", &FIELDS) } #[allow(unused_variables)] fn visit_str(self, value: &str) -> std::result::Result where E: serde::de::Error, { match value { "key" => Ok(GeneratedField::Key), "value" => Ok(GeneratedField::Value), _ => Err(serde::de::Error::unknown_field(value, FIELDS)), } } } deserializer.deserialize_identifier(GeneratedVisitor) } } struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = rate_limit_descriptor::Entry; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("struct envoy.extensions.common.ratelimit.v3.RateLimitDescriptor.Entry") } fn visit_map(self, mut map: V) -> std::result::Result where V: serde::de::MapAccess<'de>, { let mut key__ = None; let mut value__ = None; while let Some(k) = map.next_key()? { match k { GeneratedField::Key => { if key__.is_some() { return Err(serde::de::Error::duplicate_field("key")); } key__ = Some(map.next_value()?); } GeneratedField::Value => { if value__.is_some() { return Err(serde::de::Error::duplicate_field("value")); } value__ = Some(map.next_value()?); } } } Ok(rate_limit_descriptor::Entry { key: key__.unwrap_or_default(), value: value__.unwrap_or_default(), }) } } deserializer.deserialize_struct("envoy.extensions.common.ratelimit.v3.RateLimitDescriptor.Entry", FIELDS, GeneratedVisitor) } } impl serde::Serialize for rate_limit_descriptor::RateLimitOverride { #[allow(deprecated)] fn serialize(&self, serializer: S) -> std::result::Result where S: serde::Serializer, { use serde::ser::SerializeStruct; let mut len = 0; if self.requests_per_unit != 0 { len += 1; } if self.unit != 0 { len += 1; } let mut struct_ser = serializer.serialize_struct("envoy.extensions.common.ratelimit.v3.RateLimitDescriptor.RateLimitOverride", len)?; if self.requests_per_unit != 0 { struct_ser.serialize_field("requestsPerUnit", &self.requests_per_unit)?; } if self.unit != 0 { let v = super::super::super::super::r#type::v3::RateLimitUnit::from_i32(self.unit) .ok_or_else(|| serde::ser::Error::custom(format!("Invalid variant {}", self.unit)))?; struct_ser.serialize_field("unit", &v)?; } struct_ser.end() } } impl<'de> serde::Deserialize<'de> for rate_limit_descriptor::RateLimitOverride { #[allow(deprecated)] fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { const FIELDS: &[&str] = &[ "requests_per_unit", "requestsPerUnit", "unit", ]; #[allow(clippy::enum_variant_names)] enum GeneratedField { RequestsPerUnit, Unit, } impl<'de> serde::Deserialize<'de> for GeneratedField { fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = GeneratedField; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(formatter, "expected one of: {:?}", &FIELDS) } #[allow(unused_variables)] fn visit_str(self, value: &str) -> std::result::Result where E: serde::de::Error, { match value { "requestsPerUnit" | "requests_per_unit" => Ok(GeneratedField::RequestsPerUnit), "unit" => Ok(GeneratedField::Unit), _ => Err(serde::de::Error::unknown_field(value, FIELDS)), } } } deserializer.deserialize_identifier(GeneratedVisitor) } } struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = rate_limit_descriptor::RateLimitOverride; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("struct envoy.extensions.common.ratelimit.v3.RateLimitDescriptor.RateLimitOverride") } fn visit_map(self, mut map: V) -> std::result::Result where V: serde::de::MapAccess<'de>, { let mut requests_per_unit__ = None; let mut unit__ = None; while let Some(k) = map.next_key()? { match k { GeneratedField::RequestsPerUnit => { if requests_per_unit__.is_some() { return Err(serde::de::Error::duplicate_field("requestsPerUnit")); } requests_per_unit__ = Some(map.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0) ; } GeneratedField::Unit => { if unit__.is_some() { return Err(serde::de::Error::duplicate_field("unit")); } unit__ = Some(map.next_value::()? as i32); } } } Ok(rate_limit_descriptor::RateLimitOverride { requests_per_unit: requests_per_unit__.unwrap_or_default(), unit: unit__.unwrap_or_default(), }) } } deserializer.deserialize_struct("envoy.extensions.common.ratelimit.v3.RateLimitDescriptor.RateLimitOverride", FIELDS, GeneratedVisitor) } } impl serde::Serialize for VhRateLimitsOptions { #[allow(deprecated)] fn serialize(&self, serializer: S) -> std::result::Result where S: serde::Serializer, { let variant = match self { Self::Override => "OVERRIDE", Self::Include => "INCLUDE", Self::Ignore => "IGNORE", }; serializer.serialize_str(variant) } } impl<'de> serde::Deserialize<'de> for VhRateLimitsOptions { #[allow(deprecated)] fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { const FIELDS: &[&str] = &[ "OVERRIDE", "INCLUDE", "IGNORE", ]; struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = VhRateLimitsOptions; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(formatter, "expected one of: {:?}", &FIELDS) } fn visit_i64(self, v: i64) -> std::result::Result where E: serde::de::Error, { use std::convert::TryFrom; i32::try_from(v) .ok() .and_then(VhRateLimitsOptions::from_i32) .ok_or_else(|| { serde::de::Error::invalid_value(serde::de::Unexpected::Signed(v), &self) }) } fn visit_u64(self, v: u64) -> std::result::Result where E: serde::de::Error, { use std::convert::TryFrom; i32::try_from(v) .ok() .and_then(VhRateLimitsOptions::from_i32) .ok_or_else(|| { serde::de::Error::invalid_value(serde::de::Unexpected::Unsigned(v), &self) }) } fn visit_str(self, value: &str) -> std::result::Result where E: serde::de::Error, { match value { "OVERRIDE" => Ok(VhRateLimitsOptions::Override), "INCLUDE" => Ok(VhRateLimitsOptions::Include), "IGNORE" => Ok(VhRateLimitsOptions::Ignore), _ => Err(serde::de::Error::unknown_variant(value, FIELDS)), } } } deserializer.deserialize_any(GeneratedVisitor) } } impl serde::Serialize for XRateLimitHeadersRfcVersion { #[allow(deprecated)] fn serialize(&self, serializer: S) -> std::result::Result where S: serde::Serializer, { let variant = match self { Self::Off => "OFF", Self::DraftVersion03 => "DRAFT_VERSION_03", }; serializer.serialize_str(variant) } } impl<'de> serde::Deserialize<'de> for XRateLimitHeadersRfcVersion { #[allow(deprecated)] fn deserialize(deserializer: D) -> std::result::Result where D: serde::Deserializer<'de>, { const FIELDS: &[&str] = &[ "OFF", "DRAFT_VERSION_03", ]; struct GeneratedVisitor; impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { type Value = XRateLimitHeadersRfcVersion; fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(formatter, "expected one of: {:?}", &FIELDS) } fn visit_i64(self, v: i64) -> std::result::Result where E: serde::de::Error, { use std::convert::TryFrom; i32::try_from(v) .ok() .and_then(XRateLimitHeadersRfcVersion::from_i32) .ok_or_else(|| { serde::de::Error::invalid_value(serde::de::Unexpected::Signed(v), &self) }) } fn visit_u64(self, v: u64) -> std::result::Result where E: serde::de::Error, { use std::convert::TryFrom; i32::try_from(v) .ok() .and_then(XRateLimitHeadersRfcVersion::from_i32) .ok_or_else(|| { serde::de::Error::invalid_value(serde::de::Unexpected::Unsigned(v), &self) }) } fn visit_str(self, value: &str) -> std::result::Result where E: serde::de::Error, { match value { "OFF" => Ok(XRateLimitHeadersRfcVersion::Off), "DRAFT_VERSION_03" => Ok(XRateLimitHeadersRfcVersion::DraftVersion03), _ => Err(serde::de::Error::unknown_variant(value, FIELDS)), } } } deserializer.deserialize_any(GeneratedVisitor) } }