pub type AgeassuranceDefsAccess = String;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsConfig {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub regions: Vec<AgeassuranceDefsConfigRegion>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsConfig {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("regions")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.regions.len() as u64)?;
for item in &self.regions {
item.encode_cbor(buf)?;
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.regions.len() as u64)?;
for item in &self.regions {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("regions", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_regions: Vec<AgeassuranceDefsConfigRegion> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"regions" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_regions
.push(AgeassuranceDefsConfigRegion::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsConfig {
regions: field_regions,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsConfigRegion {
pub country_code: String,
pub min_access_age: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub region_code: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub rules: Vec<AgeassuranceDefsConfigRegionRulesUnion>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
#[derive(Debug, Clone)]
pub enum AgeassuranceDefsConfigRegionRulesUnion {
AgeassuranceDefsConfigRegionRuleDefault(Box<AgeassuranceDefsConfigRegionRuleDefault>),
AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge(
Box<AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge>,
),
AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge(
Box<AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge>,
),
AgeassuranceDefsConfigRegionRuleIfAssuredOverAge(
Box<AgeassuranceDefsConfigRegionRuleIfAssuredOverAge>,
),
AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge(
Box<AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge>,
),
AgeassuranceDefsConfigRegionRuleIfAccountNewerThan(
Box<AgeassuranceDefsConfigRegionRuleIfAccountNewerThan>,
),
AgeassuranceDefsConfigRegionRuleIfAccountOlderThan(
Box<AgeassuranceDefsConfigRegionRuleIfAccountOlderThan>,
),
Unknown(crate::api::UnknownUnionVariant),
}
impl serde::Serialize for AgeassuranceDefsConfigRegionRulesUnion {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleDefault(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.ageassurance.defs#configRegionRuleDefault".to_string()));
}
map.serialize(serializer)
}
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.ageassurance.defs#configRegionRuleIfDeclaredOverAge".to_string()));
}
map.serialize(serializer)
}
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.ageassurance.defs#configRegionRuleIfDeclaredUnderAge".to_string()));
}
map.serialize(serializer)
}
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAssuredOverAge(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.ageassurance.defs#configRegionRuleIfAssuredOverAge".to_string()));
}
map.serialize(serializer)
}
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.ageassurance.defs#configRegionRuleIfAssuredUnderAge".to_string()));
}
map.serialize(serializer)
}
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAccountNewerThan(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.ageassurance.defs#configRegionRuleIfAccountNewerThan".to_string()));
}
map.serialize(serializer)
}
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAccountOlderThan(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.ageassurance.defs#configRegionRuleIfAccountOlderThan".to_string()));
}
map.serialize(serializer)
}
AgeassuranceDefsConfigRegionRulesUnion::Unknown(v) => {
if let Some(ref j) = v.json {
j.serialize(serializer)
} else {
Err(serde::ser::Error::custom("no JSON data for unknown union variant"))
}
}
}
}
}
impl<'de> serde::Deserialize<'de> for AgeassuranceDefsConfigRegionRulesUnion {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = serde_json::Value::deserialize(deserializer)?;
let type_str = value
.get("$type")
.and_then(|v| v.as_str())
.unwrap_or_default();
match type_str {
"app.bsky.ageassurance.defs#configRegionRuleDefault" => {
let inner: AgeassuranceDefsConfigRegionRuleDefault =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleDefault(
Box::new(inner),
),
)
}
"app.bsky.ageassurance.defs#configRegionRuleIfDeclaredOverAge" => {
let inner: AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfDeclaredUnderAge" => {
let inner: AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfAssuredOverAge" => {
let inner: AgeassuranceDefsConfigRegionRuleIfAssuredOverAge =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAssuredOverAge(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfAssuredUnderAge" => {
let inner: AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfAccountNewerThan" => {
let inner: AgeassuranceDefsConfigRegionRuleIfAccountNewerThan =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAccountNewerThan(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfAccountOlderThan" => {
let inner: AgeassuranceDefsConfigRegionRuleIfAccountOlderThan =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAccountOlderThan(Box::new(inner)))
}
_ => Ok(AgeassuranceDefsConfigRegionRulesUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: Some(value),
cbor: None,
},
)),
}
}
}
impl AgeassuranceDefsConfigRegionRulesUnion {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
match self {
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleDefault(inner) => inner.encode_cbor(buf),
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge(inner) => inner.encode_cbor(buf),
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge(inner) => inner.encode_cbor(buf),
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAssuredOverAge(inner) => inner.encode_cbor(buf),
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge(inner) => inner.encode_cbor(buf),
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAccountNewerThan(inner) => inner.encode_cbor(buf),
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAccountOlderThan(inner) => inner.encode_cbor(buf),
AgeassuranceDefsConfigRegionRulesUnion::Unknown(v) => {
if let Some(ref data) = v.cbor {
buf.extend_from_slice(data);
Ok(())
} else {
Err(crate::cbor::CborError::InvalidCbor("no CBOR data for unknown union variant".into()))
}
}
}
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let start = decoder.position();
let val = decoder.decode()?;
let end = decoder.position();
let raw = &decoder.raw_input()[start..end];
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected map for union".into(),
));
}
};
let type_str = entries
.iter()
.find(|(k, _)| *k == "$type")
.and_then(|(_, v)| match v {
crate::cbor::Value::Text(s) => Some(*s),
_ => None,
})
.unwrap_or_default();
match type_str {
"app.bsky.ageassurance.defs#configRegionRuleDefault" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = AgeassuranceDefsConfigRegionRuleDefault::decode_cbor(&mut dec)?;
Ok(
AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleDefault(
Box::new(inner),
),
)
}
"app.bsky.ageassurance.defs#configRegionRuleIfDeclaredOverAge" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner =
AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge::decode_cbor(&mut dec)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfDeclaredUnderAge" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner =
AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge::decode_cbor(&mut dec)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfAssuredOverAge" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner =
AgeassuranceDefsConfigRegionRuleIfAssuredOverAge::decode_cbor(&mut dec)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAssuredOverAge(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfAssuredUnderAge" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner =
AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge::decode_cbor(&mut dec)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfAccountNewerThan" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner =
AgeassuranceDefsConfigRegionRuleIfAccountNewerThan::decode_cbor(&mut dec)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAccountNewerThan(Box::new(inner)))
}
"app.bsky.ageassurance.defs#configRegionRuleIfAccountOlderThan" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner =
AgeassuranceDefsConfigRegionRuleIfAccountOlderThan::decode_cbor(&mut dec)?;
Ok(AgeassuranceDefsConfigRegionRulesUnion::AgeassuranceDefsConfigRegionRuleIfAccountOlderThan(Box::new(inner)))
}
_ => Ok(AgeassuranceDefsConfigRegionRulesUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: None,
cbor: Some(raw.to_vec()),
},
)),
}
}
}
impl AgeassuranceDefsConfigRegion {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 3u64;
if self.region_code.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rules")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.rules.len() as u64)?;
for item in &self.rules {
item.encode_cbor(buf)?;
}
if self.region_code.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("regionCode")?;
if let Some(ref val) = self.region_code {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("countryCode")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.country_code)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("minAccessAge")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.min_access_age)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_array_header(self.rules.len() as u64)?;
for item in &self.rules {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("rules", vbuf));
}
if self.region_code.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.region_code {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("regionCode", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.country_code)?;
pairs.push(("countryCode", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.min_access_age)?;
pairs.push(("minAccessAge", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_rules: Vec<AgeassuranceDefsConfigRegionRulesUnion> = Vec::new();
let mut field_region_code: Option<String> = None;
let mut field_country_code: Option<String> = None;
let mut field_min_access_age: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rules" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_rules.push(AgeassuranceDefsConfigRegionRulesUnion::decode_cbor(
&mut dec,
)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"regionCode" => {
if let crate::cbor::Value::Text(s) = value {
field_region_code = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"countryCode" => {
if let crate::cbor::Value::Text(s) = value {
field_country_code = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"minAccessAge" => match value {
crate::cbor::Value::Unsigned(n) => {
field_min_access_age = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_min_access_age = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsConfigRegion {
rules: field_rules,
region_code: field_region_code,
country_code: field_country_code.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'countryCode'".into())
})?,
min_access_age: field_min_access_age.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'minAccessAge'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsConfigRegionRuleDefault {
pub access: AgeassuranceDefsAccess,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsConfigRegionRuleDefault {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("access")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.access)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.access)?;
pairs.push(("access", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_access: Option<AgeassuranceDefsAccess> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"access" => {
if let crate::cbor::Value::Text(s) = value {
field_access = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsConfigRegionRuleDefault {
access: field_access.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'access'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsConfigRegionRuleIfAccountNewerThan {
pub access: AgeassuranceDefsAccess,
pub date: crate::syntax::Datetime,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsConfigRegionRuleIfAccountNewerThan {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 2u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("date")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.date.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("access")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.access)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.date.as_str())?;
pairs.push(("date", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.access)?;
pairs.push(("access", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_date: Option<crate::syntax::Datetime> = None;
let mut field_access: Option<AgeassuranceDefsAccess> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"date" => {
if let crate::cbor::Value::Text(s) = value {
field_date = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"access" => {
if let crate::cbor::Value::Text(s) = value {
field_access = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsConfigRegionRuleIfAccountNewerThan {
date: field_date.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'date'".into())
})?,
access: field_access.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'access'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsConfigRegionRuleIfAccountOlderThan {
pub access: AgeassuranceDefsAccess,
pub date: crate::syntax::Datetime,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsConfigRegionRuleIfAccountOlderThan {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 2u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("date")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.date.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("access")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.access)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.date.as_str())?;
pairs.push(("date", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.access)?;
pairs.push(("access", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_date: Option<crate::syntax::Datetime> = None;
let mut field_access: Option<AgeassuranceDefsAccess> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"date" => {
if let crate::cbor::Value::Text(s) = value {
field_date = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"access" => {
if let crate::cbor::Value::Text(s) = value {
field_access = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsConfigRegionRuleIfAccountOlderThan {
date: field_date.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'date'".into())
})?,
access: field_access.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'access'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsConfigRegionRuleIfAssuredOverAge {
pub access: AgeassuranceDefsAccess,
pub age: i64,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsConfigRegionRuleIfAssuredOverAge {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 2u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("age")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.age)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("access")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.access)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.age)?;
pairs.push(("age", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.access)?;
pairs.push(("access", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_age: Option<i64> = None;
let mut field_access: Option<AgeassuranceDefsAccess> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"age" => match value {
crate::cbor::Value::Unsigned(n) => {
field_age = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_age = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"access" => {
if let crate::cbor::Value::Text(s) = value {
field_access = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsConfigRegionRuleIfAssuredOverAge {
age: field_age.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'age'".into())
})?,
access: field_access.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'access'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge {
pub access: AgeassuranceDefsAccess,
pub age: i64,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 2u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("age")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.age)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("access")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.access)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.age)?;
pairs.push(("age", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.access)?;
pairs.push(("access", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_age: Option<i64> = None;
let mut field_access: Option<AgeassuranceDefsAccess> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"age" => match value {
crate::cbor::Value::Unsigned(n) => {
field_age = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_age = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"access" => {
if let crate::cbor::Value::Text(s) = value {
field_access = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsConfigRegionRuleIfAssuredUnderAge {
age: field_age.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'age'".into())
})?,
access: field_access.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'access'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge {
pub access: AgeassuranceDefsAccess,
pub age: i64,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 2u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("age")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.age)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("access")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.access)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.age)?;
pairs.push(("age", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.access)?;
pairs.push(("access", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_age: Option<i64> = None;
let mut field_access: Option<AgeassuranceDefsAccess> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"age" => match value {
crate::cbor::Value::Unsigned(n) => {
field_age = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_age = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"access" => {
if let crate::cbor::Value::Text(s) = value {
field_access = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsConfigRegionRuleIfDeclaredOverAge {
age: field_age.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'age'".into())
})?,
access: field_access.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'access'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge {
pub access: AgeassuranceDefsAccess,
pub age: i64,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 2u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("age")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.age)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("access")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.access)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.age)?;
pairs.push(("age", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.access)?;
pairs.push(("access", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_age: Option<i64> = None;
let mut field_access: Option<AgeassuranceDefsAccess> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"age" => match value {
crate::cbor::Value::Unsigned(n) => {
field_age = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_age = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"access" => {
if let crate::cbor::Value::Text(s) = value {
field_access = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsConfigRegionRuleIfDeclaredUnderAge {
age: field_age.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'age'".into())
})?,
access: field_access.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'access'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsEvent {
pub access: String,
pub attempt_id: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub complete_ip: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub complete_ua: Option<String>,
pub country_code: String,
pub created_at: crate::syntax::Datetime,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub init_ip: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub init_ua: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub region_code: Option<String>,
pub status: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsEvent {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 5u64;
if self.email.is_some() {
count += 1;
}
if self.init_ip.is_some() {
count += 1;
}
if self.init_ua.is_some() {
count += 1;
}
if self.complete_ip.is_some() {
count += 1;
}
if self.complete_ua.is_some() {
count += 1;
}
if self.region_code.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.email.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("email")?;
if let Some(ref val) = self.email {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("access")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.access)?;
if self.init_ip.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("initIp")?;
if let Some(ref val) = self.init_ip {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.init_ua.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("initUa")?;
if let Some(ref val) = self.init_ua {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("status")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.status)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("attemptId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.attempt_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.created_at.as_str())?;
if self.complete_ip.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("completeIp")?;
if let Some(ref val) = self.complete_ip {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.complete_ua.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("completeUa")?;
if let Some(ref val) = self.complete_ua {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.region_code.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("regionCode")?;
if let Some(ref val) = self.region_code {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("countryCode")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.country_code)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.email.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.email {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("email", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.access)?;
pairs.push(("access", vbuf));
}
if self.init_ip.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.init_ip {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("initIp", vbuf));
}
if self.init_ua.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.init_ua {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("initUa", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.status)?;
pairs.push(("status", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.attempt_id)?;
pairs.push(("attemptId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.created_at.as_str())?;
pairs.push(("createdAt", vbuf));
}
if self.complete_ip.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.complete_ip {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("completeIp", vbuf));
}
if self.complete_ua.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.complete_ua {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("completeUa", vbuf));
}
if self.region_code.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.region_code {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("regionCode", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.country_code)?;
pairs.push(("countryCode", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_email: Option<String> = None;
let mut field_access: Option<String> = None;
let mut field_init_ip: Option<String> = None;
let mut field_init_ua: Option<String> = None;
let mut field_status: Option<String> = None;
let mut field_attempt_id: Option<String> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_complete_ip: Option<String> = None;
let mut field_complete_ua: Option<String> = None;
let mut field_region_code: Option<String> = None;
let mut field_country_code: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"email" => {
if let crate::cbor::Value::Text(s) = value {
field_email = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"access" => {
if let crate::cbor::Value::Text(s) = value {
field_access = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"initIp" => {
if let crate::cbor::Value::Text(s) = value {
field_init_ip = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"initUa" => {
if let crate::cbor::Value::Text(s) = value {
field_init_ua = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"status" => {
if let crate::cbor::Value::Text(s) = value {
field_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"attemptId" => {
if let crate::cbor::Value::Text(s) = value {
field_attempt_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"createdAt" => {
if let crate::cbor::Value::Text(s) = value {
field_created_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"completeIp" => {
if let crate::cbor::Value::Text(s) = value {
field_complete_ip = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"completeUa" => {
if let crate::cbor::Value::Text(s) = value {
field_complete_ua = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"regionCode" => {
if let crate::cbor::Value::Text(s) = value {
field_region_code = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"countryCode" => {
if let crate::cbor::Value::Text(s) = value {
field_country_code = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsEvent {
email: field_email,
access: field_access.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'access'".into())
})?,
init_ip: field_init_ip,
init_ua: field_init_ua,
status: field_status.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'status'".into())
})?,
attempt_id: field_attempt_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'attemptId'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
complete_ip: field_complete_ip,
complete_ua: field_complete_ua,
region_code: field_region_code,
country_code: field_country_code.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'countryCode'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsState {
pub access: AgeassuranceDefsAccess,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub last_initiated_at: Option<crate::syntax::Datetime>,
pub status: AgeassuranceDefsStatus,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsState {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 2u64;
if self.last_initiated_at.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("access")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.access)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("status")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.status)?;
if self.last_initiated_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("lastInitiatedAt")?;
if let Some(ref val) = self.last_initiated_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.access)?;
pairs.push(("access", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.status)?;
pairs.push(("status", vbuf));
}
if self.last_initiated_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.last_initiated_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("lastInitiatedAt", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_access: Option<AgeassuranceDefsAccess> = None;
let mut field_status: Option<AgeassuranceDefsStatus> = None;
let mut field_last_initiated_at: Option<crate::syntax::Datetime> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"access" => {
if let crate::cbor::Value::Text(s) = value {
field_access = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"status" => {
if let crate::cbor::Value::Text(s) = value {
field_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"lastInitiatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_last_initiated_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsState {
access: field_access.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'access'".into())
})?,
status: field_status.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'status'".into())
})?,
last_initiated_at: field_last_initiated_at,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AgeassuranceDefsStateMetadata {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub account_created_at: Option<crate::syntax::Datetime>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl AgeassuranceDefsStateMetadata {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.account_created_at.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.account_created_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("accountCreatedAt")?;
if let Some(ref val) = self.account_created_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.account_created_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.account_created_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("accountCreatedAt", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_account_created_at: Option<crate::syntax::Datetime> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"accountCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_account_created_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(AgeassuranceDefsStateMetadata {
account_created_at: field_account_created_at,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
pub type AgeassuranceDefsStatus = String;