#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QueueDefsAssignmentView {
pub did: crate::syntax::Did,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub end_at: Option<crate::syntax::Datetime>,
pub id: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub moderator: Option<crate::api::tools::ozone::TeamDefsMember>,
pub queue: QueueDefsQueueView,
pub start_at: crate::syntax::Datetime,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl QueueDefsAssignmentView {
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 = 4u64;
if self.end_at.is_some() {
count += 1;
}
if self.moderator.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("id")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("did")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.did.as_str())?;
if self.end_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("endAt")?;
if let Some(ref val) = self.end_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("queue")?;
self.queue.encode_cbor(buf)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("startAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.start_at.as_str())?;
if self.moderator.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("moderator")?;
if let Some(ref val) = self.moderator {
val.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_i64(self.id)?;
pairs.push(("id", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.did.as_str())?;
pairs.push(("did", vbuf));
}
if self.end_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.end_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("endAt", vbuf));
}
{
let mut vbuf = Vec::new();
self.queue.encode_cbor(&mut vbuf)?;
pairs.push(("queue", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.start_at.as_str())?;
pairs.push(("startAt", vbuf));
}
if self.moderator.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.moderator {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("moderator", 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_id: Option<i64> = None;
let mut field_did: Option<crate::syntax::Did> = None;
let mut field_end_at: Option<crate::syntax::Datetime> = None;
let mut field_queue: Option<QueueDefsQueueView> = None;
let mut field_start_at: Option<crate::syntax::Datetime> = None;
let mut field_moderator: Option<crate::api::tools::ozone::TeamDefsMember> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"id" => match value {
crate::cbor::Value::Unsigned(n) => {
field_id = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_id = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"did" => {
if let crate::cbor::Value::Text(s) = value {
field_did = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"endAt" => {
if let crate::cbor::Value::Text(s) = value {
field_end_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()));
}
}
"queue" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_queue = Some(QueueDefsQueueView::decode_cbor(&mut dec)?);
}
"startAt" => {
if let crate::cbor::Value::Text(s) = value {
field_start_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()));
}
}
"moderator" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_moderator = Some(crate::api::tools::ozone::TeamDefsMember::decode_cbor(
&mut dec,
)?);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(QueueDefsAssignmentView {
id: field_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'id'".into())
})?,
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
end_at: field_end_at,
queue: field_queue.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'queue'".into())
})?,
start_at: field_start_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'startAt'".into())
})?,
moderator: field_moderator,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QueueDefsQueueStats {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub action_rate: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub actioned_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avg_handling_time_sec: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub escalated_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub inbound_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub last_updated: Option<crate::syntax::Datetime>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pending_count: Option<i64>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl QueueDefsQueueStats {
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.action_rate.is_some() {
count += 1;
}
if self.last_updated.is_some() {
count += 1;
}
if self.inbound_count.is_some() {
count += 1;
}
if self.pending_count.is_some() {
count += 1;
}
if self.actioned_count.is_some() {
count += 1;
}
if self.escalated_count.is_some() {
count += 1;
}
if self.avg_handling_time_sec.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.action_rate.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actionRate")?;
if let Some(ref val) = self.action_rate {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.last_updated.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("lastUpdated")?;
if let Some(ref val) = self.last_updated {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.inbound_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("inboundCount")?;
if let Some(ref val) = self.inbound_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.pending_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("pendingCount")?;
if let Some(ref val) = self.pending_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.actioned_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actionedCount")?;
if let Some(ref val) = self.actioned_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.escalated_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("escalatedCount")?;
if let Some(ref val) = self.escalated_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.avg_handling_time_sec.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("avgHandlingTimeSec")?;
if let Some(ref val) = self.avg_handling_time_sec {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.action_rate.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.action_rate {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("actionRate", vbuf));
}
if self.last_updated.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.last_updated {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("lastUpdated", vbuf));
}
if self.inbound_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.inbound_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("inboundCount", vbuf));
}
if self.pending_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.pending_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("pendingCount", vbuf));
}
if self.actioned_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.actioned_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("actionedCount", vbuf));
}
if self.escalated_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.escalated_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("escalatedCount", vbuf));
}
if self.avg_handling_time_sec.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.avg_handling_time_sec {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("avgHandlingTimeSec", 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_action_rate: Option<i64> = None;
let mut field_last_updated: Option<crate::syntax::Datetime> = None;
let mut field_inbound_count: Option<i64> = None;
let mut field_pending_count: Option<i64> = None;
let mut field_actioned_count: Option<i64> = None;
let mut field_escalated_count: Option<i64> = None;
let mut field_avg_handling_time_sec: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"actionRate" => match value {
crate::cbor::Value::Unsigned(n) => {
field_action_rate = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_action_rate = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"lastUpdated" => {
if let crate::cbor::Value::Text(s) = value {
field_last_updated = 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()));
}
}
"inboundCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_inbound_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_inbound_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"pendingCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_pending_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_pending_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"actionedCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_actioned_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_actioned_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"escalatedCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_escalated_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_escalated_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"avgHandlingTimeSec" => match value {
crate::cbor::Value::Unsigned(n) => {
field_avg_handling_time_sec = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_avg_handling_time_sec = 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(QueueDefsQueueStats {
action_rate: field_action_rate,
last_updated: field_last_updated,
inbound_count: field_inbound_count,
pending_count: field_pending_count,
actioned_count: field_actioned_count,
escalated_count: field_escalated_count,
avg_handling_time_sec: field_avg_handling_time_sec,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QueueDefsQueueView {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub collection: Option<crate::syntax::Nsid>,
pub created_at: crate::syntax::Datetime,
pub created_by: crate::syntax::Did,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<crate::syntax::Datetime>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub enabled: bool,
pub id: i64,
pub name: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub report_types: Vec<String>,
pub stats: QueueDefsQueueStats,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub subject_types: Vec<String>,
pub updated_at: crate::syntax::Datetime,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl QueueDefsQueueView {
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 = 9u64;
if self.deleted_at.is_some() {
count += 1;
}
if self.collection.is_some() {
count += 1;
}
if self.description.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("id")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("name")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.name)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("stats")?;
self.stats.encode_cbor(buf)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("enabled")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.enabled)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("createdBy")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.created_by.as_str())?;
if self.deleted_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("deletedAt")?;
if let Some(ref val) = self.deleted_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("updatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.updated_at.as_str())?;
if self.collection.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("collection")?;
if let Some(ref val) = self.collection {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.description.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("description")?;
if let Some(ref val) = self.description {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("reportTypes")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.report_types.len() as u64)?;
for item in &self.report_types {
crate::cbor::Encoder::new(&mut *buf).encode_text(item)?;
}
crate::cbor::Encoder::new(&mut *buf).encode_text("subjectTypes")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.subject_types.len() as u64)?;
for item in &self.subject_types {
crate::cbor::Encoder::new(&mut *buf).encode_text(item)?;
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.id)?;
pairs.push(("id", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.name)?;
pairs.push(("name", vbuf));
}
{
let mut vbuf = Vec::new();
self.stats.encode_cbor(&mut vbuf)?;
pairs.push(("stats", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.enabled)?;
pairs.push(("enabled", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.created_at.as_str())?;
pairs.push(("createdAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.created_by.as_str())?;
pairs.push(("createdBy", vbuf));
}
if self.deleted_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.deleted_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("deletedAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.updated_at.as_str())?;
pairs.push(("updatedAt", vbuf));
}
if self.collection.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.collection {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("collection", vbuf));
}
if self.description.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.description {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("description", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.report_types.len() as u64)?;
for item in &self.report_types {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item)?;
}
pairs.push(("reportTypes", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.subject_types.len() as u64)?;
for item in &self.subject_types {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item)?;
}
pairs.push(("subjectTypes", 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_id: Option<i64> = None;
let mut field_name: Option<String> = None;
let mut field_stats: Option<QueueDefsQueueStats> = None;
let mut field_enabled: Option<bool> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_created_by: Option<crate::syntax::Did> = None;
let mut field_deleted_at: Option<crate::syntax::Datetime> = None;
let mut field_updated_at: Option<crate::syntax::Datetime> = None;
let mut field_collection: Option<crate::syntax::Nsid> = None;
let mut field_description: Option<String> = None;
let mut field_report_types: Vec<String> = Vec::new();
let mut field_subject_types: Vec<String> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"id" => match value {
crate::cbor::Value::Unsigned(n) => {
field_id = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_id = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"name" => {
if let crate::cbor::Value::Text(s) = value {
field_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"stats" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_stats = Some(QueueDefsQueueStats::decode_cbor(&mut dec)?);
}
"enabled" => {
if let crate::cbor::Value::Bool(b) = value {
field_enabled = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".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()));
}
}
"createdBy" => {
if let crate::cbor::Value::Text(s) = value {
field_created_by = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"deletedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_deleted_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()));
}
}
"updatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_updated_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()));
}
}
"collection" => {
if let crate::cbor::Value::Text(s) = value {
field_collection = Some(
crate::syntax::Nsid::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"description" => {
if let crate::cbor::Value::Text(s) = value {
field_description = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"reportTypes" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_report_types.push(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor(
"expected text in array".into(),
));
}
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"subjectTypes" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_subject_types.push(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor(
"expected text in array".into(),
));
}
}
} 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(QueueDefsQueueView {
id: field_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'id'".into())
})?,
name: field_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'name'".into())
})?,
stats: field_stats.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'stats'".into())
})?,
enabled: field_enabled.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'enabled'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
created_by: field_created_by.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdBy'".into())
})?,
deleted_at: field_deleted_at,
updated_at: field_updated_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'updatedAt'".into())
})?,
collection: field_collection,
description: field_description,
report_types: field_report_types,
subject_types: field_subject_types,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}