#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventChatAccepted {
pub actor_did: crate::syntax::Did,
pub convo_created_at: crate::syntax::Datetime,
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub group_member_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub group_name: Option<String>,
pub method: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub owner_did: Option<crate::syntax::Did>,
pub rev: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventChatAccepted {
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 = 6u64;
if self.owner_did.is_some() {
count += 1;
}
if self.group_name.is_some() {
count += 1;
}
if self.group_member_count.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("method")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.method)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
if self.owner_did.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("ownerDid")?;
if let Some(ref val) = self.owner_did {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.created_at.as_str())?;
if self.group_name.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("groupName")?;
if let Some(ref val) = self.group_name {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("convoCreatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.convo_created_at.as_str())?;
if self.group_member_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("groupMemberCount")?;
if let Some(ref val) = self.group_member_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.method)?;
pairs.push(("method", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
if self.owner_did.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.owner_did {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("ownerDid", 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.group_name.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.group_name {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("groupName", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.convo_created_at.as_str())?;
pairs.push(("convoCreatedAt", vbuf));
}
if self.group_member_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.group_member_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("groupMemberCount", 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_rev: Option<String> = None;
let mut field_method: Option<String> = None;
let mut field_convo_id: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_owner_did: Option<crate::syntax::Did> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_name: Option<String> = None;
let mut field_convo_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_member_count: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"method" => {
if let crate::cbor::Value::Text(s) = value {
field_method = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"ownerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_owner_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()));
}
}
"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()));
}
}
"groupName" => {
if let crate::cbor::Value::Text(s) = value {
field_group_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"groupMemberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_group_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_group_member_count = 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(ModerationSubscribeModEventsEventChatAccepted {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
method: field_method.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'method'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
owner_did: field_owner_did,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
group_name: field_group_name,
convo_created_at: field_convo_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'convoCreatedAt'".into(),
)
})?,
group_member_count: field_group_member_count,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventConvoFirstMessage {
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub message_id: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub recipients: Vec<crate::syntax::Did>,
pub rev: String,
pub user: crate::syntax::Did,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventConvoFirstMessage {
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.message_id.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("user")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.user.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_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.message_id.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("messageId")?;
if let Some(ref val) = self.message_id {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("recipients")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.recipients.len() as u64)?;
for item in &self.recipients {
crate::cbor::Encoder::new(&mut *buf).encode_text(item.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.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.user.as_str())?;
pairs.push(("user", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", 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.message_id.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.message_id {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("messageId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.recipients.len() as u64)?;
for item in &self.recipients {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item.as_str())?;
}
pairs.push(("recipients", 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_rev: Option<String> = None;
let mut field_user: Option<crate::syntax::Did> = None;
let mut field_convo_id: Option<String> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_message_id: Option<String> = None;
let mut field_recipients: Vec<crate::syntax::Did> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"user" => {
if let crate::cbor::Value::Text(s) = value {
field_user = 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()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"messageId" => {
if let crate::cbor::Value::Text(s) = value {
field_message_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"recipients" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_recipients.push(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 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(ModerationSubscribeModEventsEventConvoFirstMessage {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
user: field_user.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'user'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
message_id: field_message_id,
recipients: field_recipients,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventGroupChatCreated {
pub actor_did: crate::syntax::Did,
pub convo_created_at: crate::syntax::Datetime,
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
pub group_member_count: i64,
pub group_name: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub initial_member_dids: Vec<crate::syntax::Did>,
pub owner_did: crate::syntax::Did,
pub rev: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventGroupChatCreated {
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 = 9u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("ownerDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.owner_did.as_str())?;
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("groupName")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.group_name)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoCreatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.convo_created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("groupMemberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.group_member_count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("initialMemberDids")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.initial_member_dids.len() as u64)?;
for item in &self.initial_member_dids {
crate::cbor::Encoder::new(&mut *buf).encode_text(item.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.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.owner_did.as_str())?;
pairs.push(("ownerDid", 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.group_name)?;
pairs.push(("groupName", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.convo_created_at.as_str())?;
pairs.push(("convoCreatedAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.group_member_count)?;
pairs.push(("groupMemberCount", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.initial_member_dids.len() as u64)?;
for item in &self.initial_member_dids {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item.as_str())?;
}
pairs.push(("initialMemberDids", 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_rev: Option<String> = None;
let mut field_convo_id: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_owner_did: Option<crate::syntax::Did> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_name: Option<String> = None;
let mut field_convo_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_member_count: Option<i64> = None;
let mut field_initial_member_dids: Vec<crate::syntax::Did> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"ownerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_owner_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()));
}
}
"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()));
}
}
"groupName" => {
if let crate::cbor::Value::Text(s) = value {
field_group_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"groupMemberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_group_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_group_member_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"initialMemberDids" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_initial_member_dids.push(
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 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(ModerationSubscribeModEventsEventGroupChatCreated {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
owner_did: field_owner_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'ownerDid'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
group_name: field_group_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'groupName'".into())
})?,
convo_created_at: field_convo_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'convoCreatedAt'".into(),
)
})?,
group_member_count: field_group_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'groupMemberCount'".into(),
)
})?,
initial_member_dids: field_initial_member_dids,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventGroupChatJoinRequest {
pub actor_did: crate::syntax::Did,
pub convo_created_at: crate::syntax::Datetime,
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
pub group_member_count: i64,
pub group_name: String,
pub join_link_code: String,
pub owner_did: crate::syntax::Did,
pub rev: String,
pub subject_follows_owner: bool,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventGroupChatJoinRequest {
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 = 10u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("ownerDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.owner_did.as_str())?;
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("groupName")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.group_name)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("joinLinkCode")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.join_link_code)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoCreatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.convo_created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("groupMemberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.group_member_count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("subjectFollowsOwner")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.subject_follows_owner)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.owner_did.as_str())?;
pairs.push(("ownerDid", 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.group_name)?;
pairs.push(("groupName", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.join_link_code)?;
pairs.push(("joinLinkCode", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.convo_created_at.as_str())?;
pairs.push(("convoCreatedAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.group_member_count)?;
pairs.push(("groupMemberCount", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.subject_follows_owner)?;
pairs.push(("subjectFollowsOwner", 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_rev: Option<String> = None;
let mut field_convo_id: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_owner_did: Option<crate::syntax::Did> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_name: Option<String> = None;
let mut field_join_link_code: Option<String> = None;
let mut field_convo_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_member_count: Option<i64> = None;
let mut field_subject_follows_owner: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"ownerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_owner_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()));
}
}
"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()));
}
}
"groupName" => {
if let crate::cbor::Value::Text(s) = value {
field_group_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"joinLinkCode" => {
if let crate::cbor::Value::Text(s) = value {
field_join_link_code = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"groupMemberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_group_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_group_member_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"subjectFollowsOwner" => {
if let crate::cbor::Value::Bool(b) = value {
field_subject_follows_owner = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ModerationSubscribeModEventsEventGroupChatJoinRequest {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
owner_did: field_owner_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'ownerDid'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
group_name: field_group_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'groupName'".into())
})?,
join_link_code: field_join_link_code.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'joinLinkCode'".into())
})?,
convo_created_at: field_convo_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'convoCreatedAt'".into(),
)
})?,
group_member_count: field_group_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'groupMemberCount'".into(),
)
})?,
subject_follows_owner: field_subject_follows_owner.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'subjectFollowsOwner'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventGroupChatJoinRequestApproved {
pub actor_did: crate::syntax::Did,
pub convo_created_at: crate::syntax::Datetime,
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
pub group_member_count: i64,
pub group_name: String,
pub owner_did: crate::syntax::Did,
pub rev: String,
pub subject_did: crate::syntax::Did,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventGroupChatJoinRequestApproved {
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 = 9u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("ownerDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.owner_did.as_str())?;
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("groupName")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.group_name)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("subjectDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.subject_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoCreatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.convo_created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("groupMemberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.group_member_count)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.owner_did.as_str())?;
pairs.push(("ownerDid", 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.group_name)?;
pairs.push(("groupName", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.subject_did.as_str())?;
pairs.push(("subjectDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.convo_created_at.as_str())?;
pairs.push(("convoCreatedAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.group_member_count)?;
pairs.push(("groupMemberCount", 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_rev: Option<String> = None;
let mut field_convo_id: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_owner_did: Option<crate::syntax::Did> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_name: Option<String> = None;
let mut field_subject_did: Option<crate::syntax::Did> = None;
let mut field_convo_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_member_count: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"ownerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_owner_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()));
}
}
"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()));
}
}
"groupName" => {
if let crate::cbor::Value::Text(s) = value {
field_group_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"subjectDid" => {
if let crate::cbor::Value::Text(s) = value {
field_subject_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()));
}
}
"convoCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"groupMemberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_group_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_group_member_count = 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(
ModerationSubscribeModEventsEventGroupChatJoinRequestApproved {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
owner_did: field_owner_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'ownerDid'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
group_name: field_group_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'groupName'".into())
})?,
subject_did: field_subject_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'subjectDid'".into(),
)
})?,
convo_created_at: field_convo_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'convoCreatedAt'".into(),
)
})?,
group_member_count: field_group_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'groupMemberCount'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
},
)
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventGroupChatJoinRequestRejected {
pub actor_did: crate::syntax::Did,
pub convo_created_at: crate::syntax::Datetime,
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
pub group_member_count: i64,
pub group_name: String,
pub owner_did: crate::syntax::Did,
pub rev: String,
pub subject_did: crate::syntax::Did,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventGroupChatJoinRequestRejected {
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 = 9u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("ownerDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.owner_did.as_str())?;
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("groupName")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.group_name)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("subjectDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.subject_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoCreatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.convo_created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("groupMemberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.group_member_count)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.owner_did.as_str())?;
pairs.push(("ownerDid", 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.group_name)?;
pairs.push(("groupName", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.subject_did.as_str())?;
pairs.push(("subjectDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.convo_created_at.as_str())?;
pairs.push(("convoCreatedAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.group_member_count)?;
pairs.push(("groupMemberCount", 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_rev: Option<String> = None;
let mut field_convo_id: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_owner_did: Option<crate::syntax::Did> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_name: Option<String> = None;
let mut field_subject_did: Option<crate::syntax::Did> = None;
let mut field_convo_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_member_count: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"ownerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_owner_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()));
}
}
"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()));
}
}
"groupName" => {
if let crate::cbor::Value::Text(s) = value {
field_group_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"subjectDid" => {
if let crate::cbor::Value::Text(s) = value {
field_subject_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()));
}
}
"convoCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"groupMemberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_group_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_group_member_count = 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(
ModerationSubscribeModEventsEventGroupChatJoinRequestRejected {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
owner_did: field_owner_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'ownerDid'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
group_name: field_group_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'groupName'".into())
})?,
subject_did: field_subject_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'subjectDid'".into(),
)
})?,
convo_created_at: field_convo_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'convoCreatedAt'".into(),
)
})?,
group_member_count: field_group_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'groupMemberCount'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
},
)
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventGroupChatMemberAdded {
pub actor_did: crate::syntax::Did,
pub convo_created_at: crate::syntax::Datetime,
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
pub group_member_count: i64,
pub group_name: String,
pub owner_did: crate::syntax::Did,
pub request_members_count: i64,
pub rev: String,
pub subject_did: crate::syntax::Did,
pub subject_follows_owner: bool,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventGroupChatMemberAdded {
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 = 11u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("ownerDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.owner_did.as_str())?;
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("groupName")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.group_name)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("subjectDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.subject_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoCreatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.convo_created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("groupMemberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.group_member_count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("requestMembersCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.request_members_count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("subjectFollowsOwner")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.subject_follows_owner)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.owner_did.as_str())?;
pairs.push(("ownerDid", 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.group_name)?;
pairs.push(("groupName", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.subject_did.as_str())?;
pairs.push(("subjectDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.convo_created_at.as_str())?;
pairs.push(("convoCreatedAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.group_member_count)?;
pairs.push(("groupMemberCount", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.request_members_count)?;
pairs.push(("requestMembersCount", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.subject_follows_owner)?;
pairs.push(("subjectFollowsOwner", 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_rev: Option<String> = None;
let mut field_convo_id: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_owner_did: Option<crate::syntax::Did> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_name: Option<String> = None;
let mut field_subject_did: Option<crate::syntax::Did> = None;
let mut field_convo_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_member_count: Option<i64> = None;
let mut field_request_members_count: Option<i64> = None;
let mut field_subject_follows_owner: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"ownerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_owner_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()));
}
}
"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()));
}
}
"groupName" => {
if let crate::cbor::Value::Text(s) = value {
field_group_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"subjectDid" => {
if let crate::cbor::Value::Text(s) = value {
field_subject_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()));
}
}
"convoCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"groupMemberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_group_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_group_member_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"requestMembersCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_request_members_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_request_members_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"subjectFollowsOwner" => {
if let crate::cbor::Value::Bool(b) = value {
field_subject_follows_owner = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ModerationSubscribeModEventsEventGroupChatMemberAdded {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
owner_did: field_owner_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'ownerDid'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
group_name: field_group_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'groupName'".into())
})?,
subject_did: field_subject_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'subjectDid'".into())
})?,
convo_created_at: field_convo_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'convoCreatedAt'".into(),
)
})?,
group_member_count: field_group_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'groupMemberCount'".into(),
)
})?,
request_members_count: field_request_members_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'requestMembersCount'".into(),
)
})?,
subject_follows_owner: field_subject_follows_owner.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'subjectFollowsOwner'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventGroupChatMemberJoined {
pub actor_did: crate::syntax::Did,
pub convo_created_at: crate::syntax::Datetime,
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
pub group_member_count: i64,
pub group_name: String,
pub join_link_code: String,
pub owner_did: crate::syntax::Did,
pub rev: String,
pub subject_follows_owner: bool,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventGroupChatMemberJoined {
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 = 10u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("ownerDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.owner_did.as_str())?;
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("groupName")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.group_name)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("joinLinkCode")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.join_link_code)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoCreatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.convo_created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("groupMemberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.group_member_count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("subjectFollowsOwner")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.subject_follows_owner)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.owner_did.as_str())?;
pairs.push(("ownerDid", 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.group_name)?;
pairs.push(("groupName", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.join_link_code)?;
pairs.push(("joinLinkCode", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.convo_created_at.as_str())?;
pairs.push(("convoCreatedAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.group_member_count)?;
pairs.push(("groupMemberCount", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.subject_follows_owner)?;
pairs.push(("subjectFollowsOwner", 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_rev: Option<String> = None;
let mut field_convo_id: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_owner_did: Option<crate::syntax::Did> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_name: Option<String> = None;
let mut field_join_link_code: Option<String> = None;
let mut field_convo_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_member_count: Option<i64> = None;
let mut field_subject_follows_owner: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"ownerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_owner_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()));
}
}
"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()));
}
}
"groupName" => {
if let crate::cbor::Value::Text(s) = value {
field_group_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"joinLinkCode" => {
if let crate::cbor::Value::Text(s) = value {
field_join_link_code = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"groupMemberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_group_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_group_member_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"subjectFollowsOwner" => {
if let crate::cbor::Value::Bool(b) = value {
field_subject_follows_owner = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ModerationSubscribeModEventsEventGroupChatMemberJoined {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
owner_did: field_owner_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'ownerDid'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
group_name: field_group_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'groupName'".into())
})?,
join_link_code: field_join_link_code.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'joinLinkCode'".into())
})?,
convo_created_at: field_convo_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'convoCreatedAt'".into(),
)
})?,
group_member_count: field_group_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'groupMemberCount'".into(),
)
})?,
subject_follows_owner: field_subject_follows_owner.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'subjectFollowsOwner'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventGroupChatMemberLeft {
pub actor_did: crate::syntax::Did,
pub convo_created_at: crate::syntax::Datetime,
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
pub group_member_count: i64,
pub group_name: String,
pub leave_method: String,
pub owner_did: crate::syntax::Did,
pub rev: String,
pub subject_did: crate::syntax::Did,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventGroupChatMemberLeft {
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 = 10u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("ownerDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.owner_did.as_str())?;
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("groupName")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.group_name)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("subjectDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.subject_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("leaveMethod")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.leave_method)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoCreatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.convo_created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("groupMemberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.group_member_count)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.owner_did.as_str())?;
pairs.push(("ownerDid", 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.group_name)?;
pairs.push(("groupName", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.subject_did.as_str())?;
pairs.push(("subjectDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.leave_method)?;
pairs.push(("leaveMethod", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.convo_created_at.as_str())?;
pairs.push(("convoCreatedAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.group_member_count)?;
pairs.push(("groupMemberCount", 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_rev: Option<String> = None;
let mut field_convo_id: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_owner_did: Option<crate::syntax::Did> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_name: Option<String> = None;
let mut field_subject_did: Option<crate::syntax::Did> = None;
let mut field_leave_method: Option<String> = None;
let mut field_convo_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_member_count: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"ownerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_owner_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()));
}
}
"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()));
}
}
"groupName" => {
if let crate::cbor::Value::Text(s) = value {
field_group_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"subjectDid" => {
if let crate::cbor::Value::Text(s) = value {
field_subject_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()));
}
}
"leaveMethod" => {
if let crate::cbor::Value::Text(s) = value {
field_leave_method = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"groupMemberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_group_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_group_member_count = 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(ModerationSubscribeModEventsEventGroupChatMemberLeft {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
owner_did: field_owner_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'ownerDid'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
group_name: field_group_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'groupName'".into())
})?,
subject_did: field_subject_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'subjectDid'".into())
})?,
leave_method: field_leave_method.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'leaveMethod'".into())
})?,
convo_created_at: field_convo_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'convoCreatedAt'".into(),
)
})?,
group_member_count: field_group_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'groupMemberCount'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventGroupChatUpdated {
pub actor_did: crate::syntax::Did,
pub convo_created_at: crate::syntax::Datetime,
pub convo_id: String,
pub created_at: crate::syntax::Datetime,
pub group_member_count: i64,
pub group_name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub join_link_code: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub join_link_followers_only: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub join_link_requires_approval: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub lock_reason: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub new_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub old_name: Option<String>,
pub owner_did: crate::syntax::Did,
pub rev: String,
pub update_type: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventGroupChatUpdated {
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.new_name.is_some() {
count += 1;
}
if self.old_name.is_some() {
count += 1;
}
if self.lock_reason.is_some() {
count += 1;
}
if self.join_link_code.is_some() {
count += 1;
}
if self.join_link_followers_only.is_some() {
count += 1;
}
if self.join_link_requires_approval.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
if self.new_name.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("newName")?;
if let Some(ref val) = self.new_name {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.old_name.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("oldName")?;
if let Some(ref val) = self.old_name {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("ownerDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.owner_did.as_str())?;
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("groupName")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.group_name)?;
if self.lock_reason.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("lockReason")?;
if let Some(ref val) = self.lock_reason {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("updateType")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.update_type)?;
if self.join_link_code.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("joinLinkCode")?;
if let Some(ref val) = self.join_link_code {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("convoCreatedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.convo_created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("groupMemberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.group_member_count)?;
if self.join_link_followers_only.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("joinLinkFollowersOnly")?;
if let Some(ref val) = self.join_link_followers_only {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.join_link_requires_approval.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("joinLinkRequiresApproval")?;
if let Some(ref val) = self.join_link_requires_approval {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
if self.new_name.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.new_name {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("newName", vbuf));
}
if self.old_name.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.old_name {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("oldName", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.owner_did.as_str())?;
pairs.push(("ownerDid", 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.group_name)?;
pairs.push(("groupName", vbuf));
}
if self.lock_reason.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.lock_reason {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("lockReason", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.update_type)?;
pairs.push(("updateType", vbuf));
}
if self.join_link_code.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.join_link_code {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("joinLinkCode", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.convo_created_at.as_str())?;
pairs.push(("convoCreatedAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.group_member_count)?;
pairs.push(("groupMemberCount", vbuf));
}
if self.join_link_followers_only.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.join_link_followers_only {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("joinLinkFollowersOnly", vbuf));
}
if self.join_link_requires_approval.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.join_link_requires_approval {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("joinLinkRequiresApproval", 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_rev: Option<String> = None;
let mut field_convo_id: Option<String> = None;
let mut field_new_name: Option<String> = None;
let mut field_old_name: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_owner_did: Option<crate::syntax::Did> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_name: Option<String> = None;
let mut field_lock_reason: Option<String> = None;
let mut field_update_type: Option<String> = None;
let mut field_join_link_code: Option<String> = None;
let mut field_convo_created_at: Option<crate::syntax::Datetime> = None;
let mut field_group_member_count: Option<i64> = None;
let mut field_join_link_followers_only: Option<bool> = None;
let mut field_join_link_requires_approval: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"newName" => {
if let crate::cbor::Value::Text(s) = value {
field_new_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"oldName" => {
if let crate::cbor::Value::Text(s) = value {
field_old_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"ownerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_owner_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()));
}
}
"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()));
}
}
"groupName" => {
if let crate::cbor::Value::Text(s) = value {
field_group_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"lockReason" => {
if let crate::cbor::Value::Text(s) = value {
field_lock_reason = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"updateType" => {
if let crate::cbor::Value::Text(s) = value {
field_update_type = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"joinLinkCode" => {
if let crate::cbor::Value::Text(s) = value {
field_join_link_code = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"convoCreatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_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()));
}
}
"groupMemberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_group_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_group_member_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"joinLinkFollowersOnly" => {
if let crate::cbor::Value::Bool(b) = value {
field_join_link_followers_only = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"joinLinkRequiresApproval" => {
if let crate::cbor::Value::Bool(b) = value {
field_join_link_requires_approval = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ModerationSubscribeModEventsEventGroupChatUpdated {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
new_name: field_new_name,
old_name: field_old_name,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
owner_did: field_owner_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'ownerDid'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
group_name: field_group_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'groupName'".into())
})?,
lock_reason: field_lock_reason,
update_type: field_update_type.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'updateType'".into())
})?,
join_link_code: field_join_link_code,
convo_created_at: field_convo_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'convoCreatedAt'".into(),
)
})?,
group_member_count: field_group_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'groupMemberCount'".into(),
)
})?,
join_link_followers_only: field_join_link_followers_only,
join_link_requires_approval: field_join_link_requires_approval,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ModerationSubscribeModEventsEventRateLimitExceeded {
pub actor_did: crate::syntax::Did,
pub created_at: crate::syntax::Datetime,
pub endpoint: String,
pub rev: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ModerationSubscribeModEventsEventRateLimitExceeded {
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 = 4u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("actorDid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.actor_did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("endpoint")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.endpoint)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.created_at.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.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.actor_did.as_str())?;
pairs.push(("actorDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.endpoint)?;
pairs.push(("endpoint", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.created_at.as_str())?;
pairs.push(("createdAt", 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_rev: Option<String> = None;
let mut field_actor_did: Option<crate::syntax::Did> = None;
let mut field_endpoint: Option<String> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actorDid" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_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()));
}
}
"endpoint" => {
if let crate::cbor::Value::Text(s) = value {
field_endpoint = 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()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ModerationSubscribeModEventsEventRateLimitExceeded {
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
actor_did: field_actor_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actorDid'".into())
})?,
endpoint: field_endpoint.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'endpoint'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}