#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsAdultContentPref {
pub enabled: bool,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsAdultContentPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("enabled")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.enabled)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.enabled)?;
pairs.push(("enabled", 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_enabled: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"enabled" => {
if let crate::cbor::Value::Bool(b) = value {
field_enabled = 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(ActorDefsAdultContentPref {
enabled: field_enabled.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'enabled'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsBskyAppProgressGuide {
pub guide: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsBskyAppProgressGuide {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("guide")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.guide)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.guide)?;
pairs.push(("guide", 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_guide: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"guide" => {
if let crate::cbor::Value::Text(s) = value {
field_guide = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsBskyAppProgressGuide {
guide: field_guide.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'guide'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsBskyAppStatePref {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub active_progress_guide: Option<ActorDefsBskyAppProgressGuide>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub nuxs: Vec<ActorDefsNux>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub queued_nudges: Vec<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsBskyAppStatePref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if !self.nuxs.is_empty() {
count += 1;
}
if !self.queued_nudges.is_empty() {
count += 1;
}
if self.active_progress_guide.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if !self.nuxs.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("nuxs")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.nuxs.len() as u64)?;
for item in &self.nuxs {
item.encode_cbor(buf)?;
}
}
if !self.queued_nudges.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("queuedNudges")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.queued_nudges.len() as u64)?;
for item in &self.queued_nudges {
crate::cbor::Encoder::new(&mut *buf).encode_text(item)?;
}
}
if self.active_progress_guide.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("activeProgressGuide")?;
if let Some(ref val) = self.active_progress_guide {
val.encode_cbor(buf)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if !self.nuxs.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_array_header(self.nuxs.len() as u64)?;
for item in &self.nuxs {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("nuxs", vbuf));
}
if !self.queued_nudges.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.queued_nudges.len() as u64)?;
for item in &self.queued_nudges {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item)?;
}
pairs.push(("queuedNudges", vbuf));
}
if self.active_progress_guide.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.active_progress_guide {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("activeProgressGuide", 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_nuxs: Vec<ActorDefsNux> = Vec::new();
let mut field_queued_nudges: Vec<String> = Vec::new();
let mut field_active_progress_guide: Option<ActorDefsBskyAppProgressGuide> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"nuxs" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_nuxs.push(ActorDefsNux::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"queuedNudges" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_queued_nudges.push(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor(
"expected text in array".into(),
));
}
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"activeProgressGuide" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_active_progress_guide =
Some(ActorDefsBskyAppProgressGuide::decode_cbor(&mut dec)?);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsBskyAppStatePref {
nuxs: field_nuxs,
queued_nudges: field_queued_nudges,
active_progress_guide: field_active_progress_guide,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsContentLabelPref {
pub label: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub labeler_did: Option<crate::syntax::Did>,
pub visibility: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsContentLabelPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 2u64;
if self.labeler_did.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("label")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.label)?;
if self.labeler_did.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("labelerDid")?;
if let Some(ref val) = self.labeler_did {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("visibility")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.visibility)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.label)?;
pairs.push(("label", vbuf));
}
if self.labeler_did.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.labeler_did {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("labelerDid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.visibility)?;
pairs.push(("visibility", 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_label: Option<String> = None;
let mut field_labeler_did: Option<crate::syntax::Did> = None;
let mut field_visibility: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"label" => {
if let crate::cbor::Value::Text(s) = value {
field_label = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"labelerDid" => {
if let crate::cbor::Value::Text(s) = value {
field_labeler_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()));
}
}
"visibility" => {
if let crate::cbor::Value::Text(s) = value {
field_visibility = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsContentLabelPref {
label: field_label.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'label'".into())
})?,
labeler_did: field_labeler_did,
visibility: field_visibility.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'visibility'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsDeclaredAgePref {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_over_age13: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_over_age16: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_over_age18: Option<bool>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsDeclaredAgePref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.is_over_age13.is_some() {
count += 1;
}
if self.is_over_age16.is_some() {
count += 1;
}
if self.is_over_age18.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.is_over_age13.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("isOverAge13")?;
if let Some(ref val) = self.is_over_age13 {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.is_over_age16.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("isOverAge16")?;
if let Some(ref val) = self.is_over_age16 {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.is_over_age18.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("isOverAge18")?;
if let Some(ref val) = self.is_over_age18 {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.is_over_age13.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.is_over_age13 {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("isOverAge13", vbuf));
}
if self.is_over_age16.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.is_over_age16 {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("isOverAge16", vbuf));
}
if self.is_over_age18.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.is_over_age18 {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("isOverAge18", 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_is_over_age13: Option<bool> = None;
let mut field_is_over_age16: Option<bool> = None;
let mut field_is_over_age18: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"isOverAge13" => {
if let crate::cbor::Value::Bool(b) = value {
field_is_over_age13 = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"isOverAge16" => {
if let crate::cbor::Value::Bool(b) = value {
field_is_over_age16 = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"isOverAge18" => {
if let crate::cbor::Value::Bool(b) = value {
field_is_over_age18 = 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(ActorDefsDeclaredAgePref {
is_over_age13: field_is_over_age13,
is_over_age16: field_is_over_age16,
is_over_age18: field_is_over_age18,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsFeedViewPref {
pub feed: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hide_quote_posts: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hide_replies: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hide_replies_by_like_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hide_replies_by_unfollowed: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hide_reposts: Option<bool>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsFeedViewPref {
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 = 1u64;
if self.hide_replies.is_some() {
count += 1;
}
if self.hide_reposts.is_some() {
count += 1;
}
if self.hide_quote_posts.is_some() {
count += 1;
}
if self.hide_replies_by_like_count.is_some() {
count += 1;
}
if self.hide_replies_by_unfollowed.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("feed")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.feed)?;
if self.hide_replies.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("hideReplies")?;
if let Some(ref val) = self.hide_replies {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.hide_reposts.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("hideReposts")?;
if let Some(ref val) = self.hide_reposts {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.hide_quote_posts.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("hideQuotePosts")?;
if let Some(ref val) = self.hide_quote_posts {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.hide_replies_by_like_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("hideRepliesByLikeCount")?;
if let Some(ref val) = self.hide_replies_by_like_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.hide_replies_by_unfollowed.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("hideRepliesByUnfollowed")?;
if let Some(ref val) = self.hide_replies_by_unfollowed {
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.feed)?;
pairs.push(("feed", vbuf));
}
if self.hide_replies.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.hide_replies {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("hideReplies", vbuf));
}
if self.hide_reposts.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.hide_reposts {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("hideReposts", vbuf));
}
if self.hide_quote_posts.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.hide_quote_posts {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("hideQuotePosts", vbuf));
}
if self.hide_replies_by_like_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.hide_replies_by_like_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("hideRepliesByLikeCount", vbuf));
}
if self.hide_replies_by_unfollowed.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.hide_replies_by_unfollowed {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("hideRepliesByUnfollowed", 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_feed: Option<String> = None;
let mut field_hide_replies: Option<bool> = None;
let mut field_hide_reposts: Option<bool> = None;
let mut field_hide_quote_posts: Option<bool> = None;
let mut field_hide_replies_by_like_count: Option<i64> = None;
let mut field_hide_replies_by_unfollowed: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"feed" => {
if let crate::cbor::Value::Text(s) = value {
field_feed = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"hideReplies" => {
if let crate::cbor::Value::Bool(b) = value {
field_hide_replies = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"hideReposts" => {
if let crate::cbor::Value::Bool(b) = value {
field_hide_reposts = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"hideQuotePosts" => {
if let crate::cbor::Value::Bool(b) = value {
field_hide_quote_posts = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"hideRepliesByLikeCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_hide_replies_by_like_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_hide_replies_by_like_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"hideRepliesByUnfollowed" => {
if let crate::cbor::Value::Bool(b) = value {
field_hide_replies_by_unfollowed = 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(ActorDefsFeedViewPref {
feed: field_feed.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'feed'".into())
})?,
hide_replies: field_hide_replies,
hide_reposts: field_hide_reposts,
hide_quote_posts: field_hide_quote_posts,
hide_replies_by_like_count: field_hide_replies_by_like_count,
hide_replies_by_unfollowed: field_hide_replies_by_unfollowed,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsHiddenPostsPref {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub items: Vec<crate::syntax::AtUri>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsHiddenPostsPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("items")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.items.len() as u64)?;
for item in &self.items {
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_array_header(self.items.len() as u64)?;
for item in &self.items {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item.as_str())?;
}
pairs.push(("items", 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_items: Vec<crate::syntax::AtUri> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"items" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_items.push(crate::syntax::AtUri::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(ActorDefsHiddenPostsPref {
items: field_items,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsInterestsPref {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub tags: Vec<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsInterestsPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("tags")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.tags.len() as u64)?;
for item in &self.tags {
crate::cbor::Encoder::new(&mut *buf).encode_text(item)?;
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_array_header(self.tags.len() as u64)?;
for item in &self.tags {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item)?;
}
pairs.push(("tags", 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_tags: Vec<String> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"tags" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_tags.push(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor(
"expected text in array".into(),
));
}
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsInterestsPref {
tags: field_tags,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsKnownFollowers {
pub count: i64,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub followers: Vec<ActorDefsProfileViewBasic>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsKnownFollowers {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 2u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("count")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("followers")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.followers.len() as u64)?;
for item in &self.followers {
item.encode_cbor(buf)?;
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.count)?;
pairs.push(("count", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.followers.len() as u64)?;
for item in &self.followers {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("followers", 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_count: Option<i64> = None;
let mut field_followers: Vec<ActorDefsProfileViewBasic> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"count" => match value {
crate::cbor::Value::Unsigned(n) => {
field_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"followers" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_followers.push(ActorDefsProfileViewBasic::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsKnownFollowers {
count: field_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'count'".into())
})?,
followers: field_followers,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsLabelerPrefItem {
pub 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 ActorDefsLabelerPrefItem {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("did")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.did.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.did.as_str())?;
pairs.push(("did", 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_did: Option<crate::syntax::Did> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"did" => {
if let crate::cbor::Value::Text(s) = value {
field_did = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsLabelerPrefItem {
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsLabelersPref {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub labelers: Vec<ActorDefsLabelerPrefItem>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsLabelersPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("labelers")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.labelers.len() as u64)?;
for item in &self.labelers {
item.encode_cbor(buf)?;
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.labelers.len() as u64)?;
for item in &self.labelers {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("labelers", 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_labelers: Vec<ActorDefsLabelerPrefItem> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"labelers" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_labelers.push(ActorDefsLabelerPrefItem::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsLabelersPref {
labelers: field_labelers,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsLiveEventPreferences {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub hidden_feed_ids: Vec<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hide_all_feeds: Option<bool>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsLiveEventPreferences {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.hide_all_feeds.is_some() {
count += 1;
}
if !self.hidden_feed_ids.is_empty() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.hide_all_feeds.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("hideAllFeeds")?;
if let Some(ref val) = self.hide_all_feeds {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if !self.hidden_feed_ids.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("hiddenFeedIds")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.hidden_feed_ids.len() as u64)?;
for item in &self.hidden_feed_ids {
crate::cbor::Encoder::new(&mut *buf).encode_text(item)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.hide_all_feeds.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.hide_all_feeds {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("hideAllFeeds", vbuf));
}
if !self.hidden_feed_ids.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.hidden_feed_ids.len() as u64)?;
for item in &self.hidden_feed_ids {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item)?;
}
pairs.push(("hiddenFeedIds", 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_hide_all_feeds: Option<bool> = None;
let mut field_hidden_feed_ids: Vec<String> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"hideAllFeeds" => {
if let crate::cbor::Value::Bool(b) = value {
field_hide_all_feeds = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"hiddenFeedIds" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_hidden_feed_ids.push(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor(
"expected text in array".into(),
));
}
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsLiveEventPreferences {
hide_all_feeds: field_hide_all_feeds,
hidden_feed_ids: field_hidden_feed_ids,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsMutedWord {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub actor_target: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expires_at: Option<crate::syntax::Datetime>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub targets: Vec<ActorDefsMutedWordTarget>,
pub value: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsMutedWord {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 2u64;
if self.id.is_some() {
count += 1;
}
if self.expires_at.is_some() {
count += 1;
}
if self.actor_target.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.id.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("id")?;
if let Some(ref val) = self.id {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("value")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.value)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("targets")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.targets.len() as u64)?;
for item in &self.targets {
crate::cbor::Encoder::new(&mut *buf).encode_text(item)?;
}
if self.expires_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("expiresAt")?;
if let Some(ref val) = self.expires_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.actor_target.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actorTarget")?;
if let Some(ref val) = self.actor_target {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.id.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.id {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("id", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.value)?;
pairs.push(("value", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.targets.len() as u64)?;
for item in &self.targets {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item)?;
}
pairs.push(("targets", vbuf));
}
if self.expires_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.expires_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("expiresAt", vbuf));
}
if self.actor_target.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.actor_target {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("actorTarget", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_id: Option<String> = None;
let mut field_value: Option<String> = None;
let mut field_targets: Vec<ActorDefsMutedWordTarget> = Vec::new();
let mut field_expires_at: Option<crate::syntax::Datetime> = None;
let mut field_actor_target: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"id" => {
if let crate::cbor::Value::Text(s) = value {
field_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"value" => {
if let crate::cbor::Value::Text(s) = value {
field_value = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"targets" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_targets.push(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor(
"expected text in array".into(),
));
}
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"expiresAt" => {
if let crate::cbor::Value::Text(s) = value {
field_expires_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()));
}
}
"actorTarget" => {
if let crate::cbor::Value::Text(s) = value {
field_actor_target = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsMutedWord {
id: field_id,
value: field_value.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'value'".into())
})?,
targets: field_targets,
expires_at: field_expires_at,
actor_target: field_actor_target,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
pub type ActorDefsMutedWordTarget = String;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsMutedWordsPref {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub items: Vec<ActorDefsMutedWord>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsMutedWordsPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("items")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.items.len() as u64)?;
for item in &self.items {
item.encode_cbor(buf)?;
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_array_header(self.items.len() as u64)?;
for item in &self.items {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("items", 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_items: Vec<ActorDefsMutedWord> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"items" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_items.push(ActorDefsMutedWord::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsMutedWordsPref {
items: field_items,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsNux {
pub completed: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub data: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expires_at: Option<crate::syntax::Datetime>,
pub id: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsNux {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 2u64;
if self.data.is_some() {
count += 1;
}
if self.expires_at.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("id")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.id)?;
if self.data.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("data")?;
if let Some(ref val) = self.data {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("completed")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.completed)?;
if self.expires_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("expiresAt")?;
if let Some(ref val) = self.expires_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.id)?;
pairs.push(("id", vbuf));
}
if self.data.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.data {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("data", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.completed)?;
pairs.push(("completed", vbuf));
}
if self.expires_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.expires_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("expiresAt", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_id: Option<String> = None;
let mut field_data: Option<String> = None;
let mut field_completed: Option<bool> = None;
let mut field_expires_at: Option<crate::syntax::Datetime> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"id" => {
if let crate::cbor::Value::Text(s) = value {
field_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"data" => {
if let crate::cbor::Value::Text(s) = value {
field_data = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"completed" => {
if let crate::cbor::Value::Bool(b) = value {
field_completed = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"expiresAt" => {
if let crate::cbor::Value::Text(s) = value {
field_expires_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(ActorDefsNux {
id: field_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'id'".into())
})?,
data: field_data,
completed: field_completed.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'completed'".into())
})?,
expires_at: field_expires_at,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsPersonalDetailsPref {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub birth_date: Option<crate::syntax::Datetime>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsPersonalDetailsPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.birth_date.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.birth_date.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("birthDate")?;
if let Some(ref val) = self.birth_date {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.birth_date.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.birth_date {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("birthDate", 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_birth_date: Option<crate::syntax::Datetime> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"birthDate" => {
if let crate::cbor::Value::Text(s) = value {
field_birth_date = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsPersonalDetailsPref {
birth_date: field_birth_date,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsPostInteractionSettingsPref {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub postgate_embedding_rules:
Vec<ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub threadgate_allow_rules: Vec<ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
#[derive(Debug, Clone)]
pub enum ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion {
FeedPostgateDisableRule(Box<crate::api::app::bsky::FeedPostgateDisableRule>),
Unknown(crate::api::UnknownUnionVariant),
}
impl serde::Serialize for ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion::FeedPostgateDisableRule(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.feed.postgate#disableRule".to_string()));
}
map.serialize(serializer)
}
ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion::Unknown(v) => {
if let Some(ref j) = v.json {
j.serialize(serializer)
} else {
Err(serde::ser::Error::custom("no JSON data for unknown union variant"))
}
}
}
}
}
impl<'de> serde::Deserialize<'de>
for ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion
{
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = serde_json::Value::deserialize(deserializer)?;
let type_str = value
.get("$type")
.and_then(|v| v.as_str())
.unwrap_or_default();
match type_str {
"app.bsky.feed.postgate#disableRule" => {
let inner: crate::api::app::bsky::FeedPostgateDisableRule =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion::FeedPostgateDisableRule(Box::new(inner)))
}
_ => Ok(
ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: Some(value),
cbor: None,
},
),
),
}
}
}
impl ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
match self {
ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion::FeedPostgateDisableRule(inner) => inner.encode_cbor(buf),
ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion::Unknown(v) => {
if let Some(ref data) = v.cbor {
buf.extend_from_slice(data);
Ok(())
} else {
Err(crate::cbor::CborError::InvalidCbor("no CBOR data for unknown union variant".into()))
}
}
}
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let start = decoder.position();
let val = decoder.decode()?;
let end = decoder.position();
let raw = &decoder.raw_input()[start..end];
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected map for union".into(),
));
}
};
let type_str = entries
.iter()
.find(|(k, _)| *k == "$type")
.and_then(|(_, v)| match v {
crate::cbor::Value::Text(s) => Some(*s),
_ => None,
})
.unwrap_or_default();
match type_str {
"app.bsky.feed.postgate#disableRule" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = crate::api::app::bsky::FeedPostgateDisableRule::decode_cbor(&mut dec)?;
Ok(ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion::FeedPostgateDisableRule(Box::new(inner)))
}
_ => Ok(
ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: None,
cbor: Some(raw.to_vec()),
},
),
),
}
}
}
#[derive(Debug, Clone)]
pub enum ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion {
FeedThreadgateMentionRule(Box<crate::api::app::bsky::FeedThreadgateMentionRule>),
FeedThreadgateFollowerRule(Box<crate::api::app::bsky::FeedThreadgateFollowerRule>),
FeedThreadgateFollowingRule(Box<crate::api::app::bsky::FeedThreadgateFollowingRule>),
FeedThreadgateListRule(Box<crate::api::app::bsky::FeedThreadgateListRule>),
Unknown(crate::api::UnknownUnionVariant),
}
impl serde::Serialize for ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateMentionRule(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.feed.threadgate#mentionRule".to_string()));
}
map.serialize(serializer)
}
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateFollowerRule(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.feed.threadgate#followerRule".to_string()));
}
map.serialize(serializer)
}
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateFollowingRule(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.feed.threadgate#followingRule".to_string()));
}
map.serialize(serializer)
}
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateListRule(inner) => {
let mut map = serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert("$type".to_string(), serde_json::Value::String("app.bsky.feed.threadgate#listRule".to_string()));
}
map.serialize(serializer)
}
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::Unknown(v) => {
if let Some(ref j) = v.json {
j.serialize(serializer)
} else {
Err(serde::ser::Error::custom("no JSON data for unknown union variant"))
}
}
}
}
}
impl<'de> serde::Deserialize<'de>
for ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion
{
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = serde_json::Value::deserialize(deserializer)?;
let type_str = value
.get("$type")
.and_then(|v| v.as_str())
.unwrap_or_default();
match type_str {
"app.bsky.feed.threadgate#mentionRule" => {
let inner: crate::api::app::bsky::FeedThreadgateMentionRule =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateMentionRule(Box::new(inner)))
}
"app.bsky.feed.threadgate#followerRule" => {
let inner: crate::api::app::bsky::FeedThreadgateFollowerRule =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateFollowerRule(Box::new(inner)))
}
"app.bsky.feed.threadgate#followingRule" => {
let inner: crate::api::app::bsky::FeedThreadgateFollowingRule =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateFollowingRule(Box::new(inner)))
}
"app.bsky.feed.threadgate#listRule" => {
let inner: crate::api::app::bsky::FeedThreadgateListRule =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateListRule(Box::new(inner)))
}
_ => Ok(
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: Some(value),
cbor: None,
},
),
),
}
}
}
impl ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
match self {
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateMentionRule(inner) => inner.encode_cbor(buf),
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateFollowerRule(inner) => inner.encode_cbor(buf),
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateFollowingRule(inner) => inner.encode_cbor(buf),
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateListRule(inner) => inner.encode_cbor(buf),
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::Unknown(v) => {
if let Some(ref data) = v.cbor {
buf.extend_from_slice(data);
Ok(())
} else {
Err(crate::cbor::CborError::InvalidCbor("no CBOR data for unknown union variant".into()))
}
}
}
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let start = decoder.position();
let val = decoder.decode()?;
let end = decoder.position();
let raw = &decoder.raw_input()[start..end];
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected map for union".into(),
));
}
};
let type_str = entries
.iter()
.find(|(k, _)| *k == "$type")
.and_then(|(_, v)| match v {
crate::cbor::Value::Text(s) => Some(*s),
_ => None,
})
.unwrap_or_default();
match type_str {
"app.bsky.feed.threadgate#mentionRule" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner =
crate::api::app::bsky::FeedThreadgateMentionRule::decode_cbor(&mut dec)?;
Ok(ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateMentionRule(Box::new(inner)))
}
"app.bsky.feed.threadgate#followerRule" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner =
crate::api::app::bsky::FeedThreadgateFollowerRule::decode_cbor(&mut dec)?;
Ok(ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateFollowerRule(Box::new(inner)))
}
"app.bsky.feed.threadgate#followingRule" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner =
crate::api::app::bsky::FeedThreadgateFollowingRule::decode_cbor(&mut dec)?;
Ok(ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateFollowingRule(Box::new(inner)))
}
"app.bsky.feed.threadgate#listRule" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = crate::api::app::bsky::FeedThreadgateListRule::decode_cbor(&mut dec)?;
Ok(ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::FeedThreadgateListRule(Box::new(inner)))
}
_ => Ok(
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: None,
cbor: Some(raw.to_vec()),
},
),
),
}
}
}
impl ActorDefsPostInteractionSettingsPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if !self.threadgate_allow_rules.is_empty() {
count += 1;
}
if !self.postgate_embedding_rules.is_empty() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if !self.threadgate_allow_rules.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("threadgateAllowRules")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.threadgate_allow_rules.len() as u64)?;
for item in &self.threadgate_allow_rules {
item.encode_cbor(buf)?;
}
}
if !self.postgate_embedding_rules.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("postgateEmbeddingRules")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.postgate_embedding_rules.len() as u64)?;
for item in &self.postgate_embedding_rules {
item.encode_cbor(buf)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if !self.threadgate_allow_rules.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.threadgate_allow_rules.len() as u64)?;
for item in &self.threadgate_allow_rules {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("threadgateAllowRules", vbuf));
}
if !self.postgate_embedding_rules.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.postgate_embedding_rules.len() as u64)?;
for item in &self.postgate_embedding_rules {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("postgateEmbeddingRules", 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_threadgate_allow_rules: Vec<
ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion,
> = Vec::new();
let mut field_postgate_embedding_rules: Vec<
ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion,
> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"threadgateAllowRules" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_threadgate_allow_rules.push(ActorDefsPostInteractionSettingsPrefThreadgateAllowRulesUnion::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"postgateEmbeddingRules" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_postgate_embedding_rules.push(ActorDefsPostInteractionSettingsPrefPostgateEmbeddingRulesUnion::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsPostInteractionSettingsPref {
threadgate_allow_rules: field_threadgate_allow_rules,
postgate_embedding_rules: field_postgate_embedding_rules,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone)]
pub enum ActorDefsPreferencesItem {
ActorDefsAdultContentPref(Box<ActorDefsAdultContentPref>),
ActorDefsContentLabelPref(Box<ActorDefsContentLabelPref>),
ActorDefsSavedFeedsPref(Box<ActorDefsSavedFeedsPref>),
ActorDefsSavedFeedsPrefV2(Box<ActorDefsSavedFeedsPrefV2>),
ActorDefsPersonalDetailsPref(Box<ActorDefsPersonalDetailsPref>),
ActorDefsDeclaredAgePref(Box<ActorDefsDeclaredAgePref>),
ActorDefsFeedViewPref(Box<ActorDefsFeedViewPref>),
ActorDefsThreadViewPref(Box<ActorDefsThreadViewPref>),
ActorDefsInterestsPref(Box<ActorDefsInterestsPref>),
ActorDefsMutedWordsPref(Box<ActorDefsMutedWordsPref>),
ActorDefsHiddenPostsPref(Box<ActorDefsHiddenPostsPref>),
ActorDefsBskyAppStatePref(Box<ActorDefsBskyAppStatePref>),
ActorDefsLabelersPref(Box<ActorDefsLabelersPref>),
ActorDefsPostInteractionSettingsPref(Box<ActorDefsPostInteractionSettingsPref>),
ActorDefsVerificationPrefs(Box<ActorDefsVerificationPrefs>),
ActorDefsLiveEventPreferences(Box<ActorDefsLiveEventPreferences>),
Unknown(crate::api::UnknownUnionVariant),
}
impl serde::Serialize for ActorDefsPreferencesItem {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
ActorDefsPreferencesItem::ActorDefsAdultContentPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#adultContentPref".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsContentLabelPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#contentLabelPref".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsSavedFeedsPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String("app.bsky.actor.defs#savedFeedsPref".to_string()),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsSavedFeedsPrefV2(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#savedFeedsPrefV2".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsPersonalDetailsPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#personalDetailsPref".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsDeclaredAgePref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#declaredAgePref".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsFeedViewPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String("app.bsky.actor.defs#feedViewPref".to_string()),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsThreadViewPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String("app.bsky.actor.defs#threadViewPref".to_string()),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsInterestsPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String("app.bsky.actor.defs#interestsPref".to_string()),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsMutedWordsPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String("app.bsky.actor.defs#mutedWordsPref".to_string()),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsHiddenPostsPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#hiddenPostsPref".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsBskyAppStatePref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#bskyAppStatePref".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsLabelersPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String("app.bsky.actor.defs#labelersPref".to_string()),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsPostInteractionSettingsPref(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#postInteractionSettingsPref".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsVerificationPrefs(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#verificationPrefs".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::ActorDefsLiveEventPreferences(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"app.bsky.actor.defs#liveEventPreferences".to_string(),
),
);
}
map.serialize(serializer)
}
ActorDefsPreferencesItem::Unknown(v) => {
if let Some(ref j) = v.json {
j.serialize(serializer)
} else {
Err(serde::ser::Error::custom(
"no JSON data for unknown union variant",
))
}
}
}
}
}
impl<'de> serde::Deserialize<'de> for ActorDefsPreferencesItem {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = serde_json::Value::deserialize(deserializer)?;
let type_str = value
.get("$type")
.and_then(|v| v.as_str())
.unwrap_or_default();
match type_str {
"app.bsky.actor.defs#adultContentPref" => {
let inner: ActorDefsAdultContentPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsAdultContentPref(
Box::new(inner),
))
}
"app.bsky.actor.defs#contentLabelPref" => {
let inner: ActorDefsContentLabelPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsContentLabelPref(
Box::new(inner),
))
}
"app.bsky.actor.defs#savedFeedsPref" => {
let inner: ActorDefsSavedFeedsPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsSavedFeedsPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#savedFeedsPrefV2" => {
let inner: ActorDefsSavedFeedsPrefV2 =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsSavedFeedsPrefV2(
Box::new(inner),
))
}
"app.bsky.actor.defs#personalDetailsPref" => {
let inner: ActorDefsPersonalDetailsPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsPersonalDetailsPref(
Box::new(inner),
))
}
"app.bsky.actor.defs#declaredAgePref" => {
let inner: ActorDefsDeclaredAgePref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsDeclaredAgePref(
Box::new(inner),
))
}
"app.bsky.actor.defs#feedViewPref" => {
let inner: ActorDefsFeedViewPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsFeedViewPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#threadViewPref" => {
let inner: ActorDefsThreadViewPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsThreadViewPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#interestsPref" => {
let inner: ActorDefsInterestsPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsInterestsPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#mutedWordsPref" => {
let inner: ActorDefsMutedWordsPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsMutedWordsPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#hiddenPostsPref" => {
let inner: ActorDefsHiddenPostsPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsHiddenPostsPref(
Box::new(inner),
))
}
"app.bsky.actor.defs#bskyAppStatePref" => {
let inner: ActorDefsBskyAppStatePref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsBskyAppStatePref(
Box::new(inner),
))
}
"app.bsky.actor.defs#labelersPref" => {
let inner: ActorDefsLabelersPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsLabelersPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#postInteractionSettingsPref" => {
let inner: ActorDefsPostInteractionSettingsPref =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsPostInteractionSettingsPref(Box::new(inner)))
}
"app.bsky.actor.defs#verificationPrefs" => {
let inner: ActorDefsVerificationPrefs =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsVerificationPrefs(
Box::new(inner),
))
}
"app.bsky.actor.defs#liveEventPreferences" => {
let inner: ActorDefsLiveEventPreferences =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsPreferencesItem::ActorDefsLiveEventPreferences(
Box::new(inner),
))
}
_ => Ok(ActorDefsPreferencesItem::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: Some(value),
cbor: None,
},
)),
}
}
}
impl ActorDefsPreferencesItem {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
match self {
ActorDefsPreferencesItem::ActorDefsAdultContentPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsContentLabelPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsSavedFeedsPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsSavedFeedsPrefV2(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsPersonalDetailsPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsDeclaredAgePref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsFeedViewPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsThreadViewPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsInterestsPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsMutedWordsPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsHiddenPostsPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsBskyAppStatePref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsLabelersPref(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsPostInteractionSettingsPref(inner) => {
inner.encode_cbor(buf)
}
ActorDefsPreferencesItem::ActorDefsVerificationPrefs(inner) => inner.encode_cbor(buf),
ActorDefsPreferencesItem::ActorDefsLiveEventPreferences(inner) => {
inner.encode_cbor(buf)
}
ActorDefsPreferencesItem::Unknown(v) => {
if let Some(ref data) = v.cbor {
buf.extend_from_slice(data);
Ok(())
} else {
Err(crate::cbor::CborError::InvalidCbor(
"no CBOR data for unknown union variant".into(),
))
}
}
}
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let start = decoder.position();
let val = decoder.decode()?;
let end = decoder.position();
let raw = &decoder.raw_input()[start..end];
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected map for union".into(),
));
}
};
let type_str = entries
.iter()
.find(|(k, _)| *k == "$type")
.and_then(|(_, v)| match v {
crate::cbor::Value::Text(s) => Some(*s),
_ => None,
})
.unwrap_or_default();
match type_str {
"app.bsky.actor.defs#adultContentPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsAdultContentPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsAdultContentPref(
Box::new(inner),
))
}
"app.bsky.actor.defs#contentLabelPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsContentLabelPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsContentLabelPref(
Box::new(inner),
))
}
"app.bsky.actor.defs#savedFeedsPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsSavedFeedsPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsSavedFeedsPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#savedFeedsPrefV2" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsSavedFeedsPrefV2::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsSavedFeedsPrefV2(
Box::new(inner),
))
}
"app.bsky.actor.defs#personalDetailsPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsPersonalDetailsPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsPersonalDetailsPref(
Box::new(inner),
))
}
"app.bsky.actor.defs#declaredAgePref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsDeclaredAgePref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsDeclaredAgePref(
Box::new(inner),
))
}
"app.bsky.actor.defs#feedViewPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsFeedViewPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsFeedViewPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#threadViewPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsThreadViewPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsThreadViewPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#interestsPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsInterestsPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsInterestsPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#mutedWordsPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsMutedWordsPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsMutedWordsPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#hiddenPostsPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsHiddenPostsPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsHiddenPostsPref(
Box::new(inner),
))
}
"app.bsky.actor.defs#bskyAppStatePref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsBskyAppStatePref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsBskyAppStatePref(
Box::new(inner),
))
}
"app.bsky.actor.defs#labelersPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsLabelersPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsLabelersPref(Box::new(
inner,
)))
}
"app.bsky.actor.defs#postInteractionSettingsPref" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsPostInteractionSettingsPref::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsPostInteractionSettingsPref(Box::new(inner)))
}
"app.bsky.actor.defs#verificationPrefs" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsVerificationPrefs::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsVerificationPrefs(
Box::new(inner),
))
}
"app.bsky.actor.defs#liveEventPreferences" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ActorDefsLiveEventPreferences::decode_cbor(&mut dec)?;
Ok(ActorDefsPreferencesItem::ActorDefsLiveEventPreferences(
Box::new(inner),
))
}
_ => Ok(ActorDefsPreferencesItem::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: None,
cbor: Some(raw.to_vec()),
},
)),
}
}
}
pub type ActorDefsPreferences = Vec<ActorDefsPreferencesItem>;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsProfileAssociated {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub activity_subscription: Option<ActorDefsProfileAssociatedActivitySubscription>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub chat: Option<ActorDefsProfileAssociatedChat>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub feedgens: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub germ: Option<ActorDefsProfileAssociatedGerm>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub labeler: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub lists: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub starter_packs: Option<i64>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsProfileAssociated {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.chat.is_some() {
count += 1;
}
if self.germ.is_some() {
count += 1;
}
if self.lists.is_some() {
count += 1;
}
if self.labeler.is_some() {
count += 1;
}
if self.feedgens.is_some() {
count += 1;
}
if self.starter_packs.is_some() {
count += 1;
}
if self.activity_subscription.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.chat.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("chat")?;
if let Some(ref val) = self.chat {
val.encode_cbor(buf)?;
}
}
if self.germ.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("germ")?;
if let Some(ref val) = self.germ {
val.encode_cbor(buf)?;
}
}
if self.lists.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("lists")?;
if let Some(ref val) = self.lists {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.labeler.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("labeler")?;
if let Some(ref val) = self.labeler {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.feedgens.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("feedgens")?;
if let Some(ref val) = self.feedgens {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.starter_packs.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("starterPacks")?;
if let Some(ref val) = self.starter_packs {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.activity_subscription.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("activitySubscription")?;
if let Some(ref val) = self.activity_subscription {
val.encode_cbor(buf)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.chat.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.chat {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("chat", vbuf));
}
if self.germ.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.germ {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("germ", vbuf));
}
if self.lists.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.lists {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("lists", vbuf));
}
if self.labeler.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.labeler {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("labeler", vbuf));
}
if self.feedgens.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.feedgens {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("feedgens", vbuf));
}
if self.starter_packs.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.starter_packs {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("starterPacks", vbuf));
}
if self.activity_subscription.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.activity_subscription {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("activitySubscription", 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_chat: Option<ActorDefsProfileAssociatedChat> = None;
let mut field_germ: Option<ActorDefsProfileAssociatedGerm> = None;
let mut field_lists: Option<i64> = None;
let mut field_labeler: Option<bool> = None;
let mut field_feedgens: Option<i64> = None;
let mut field_starter_packs: Option<i64> = None;
let mut field_activity_subscription: Option<
ActorDefsProfileAssociatedActivitySubscription,
> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"chat" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_chat = Some(ActorDefsProfileAssociatedChat::decode_cbor(&mut dec)?);
}
"germ" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_germ = Some(ActorDefsProfileAssociatedGerm::decode_cbor(&mut dec)?);
}
"lists" => match value {
crate::cbor::Value::Unsigned(n) => {
field_lists = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_lists = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"labeler" => {
if let crate::cbor::Value::Bool(b) = value {
field_labeler = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"feedgens" => match value {
crate::cbor::Value::Unsigned(n) => {
field_feedgens = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_feedgens = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"starterPacks" => match value {
crate::cbor::Value::Unsigned(n) => {
field_starter_packs = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_starter_packs = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"activitySubscription" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_activity_subscription = Some(
ActorDefsProfileAssociatedActivitySubscription::decode_cbor(&mut dec)?,
);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsProfileAssociated {
chat: field_chat,
germ: field_germ,
lists: field_lists,
labeler: field_labeler,
feedgens: field_feedgens,
starter_packs: field_starter_packs,
activity_subscription: field_activity_subscription,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsProfileAssociatedActivitySubscription {
pub allow_subscriptions: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsProfileAssociatedActivitySubscription {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("allowSubscriptions")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.allow_subscriptions)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.allow_subscriptions)?;
pairs.push(("allowSubscriptions", 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_allow_subscriptions: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"allowSubscriptions" => {
if let crate::cbor::Value::Text(s) = value {
field_allow_subscriptions = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsProfileAssociatedActivitySubscription {
allow_subscriptions: field_allow_subscriptions.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'allowSubscriptions'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsProfileAssociatedChat {
pub allow_incoming: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsProfileAssociatedChat {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("allowIncoming")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.allow_incoming)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.allow_incoming)?;
pairs.push(("allowIncoming", 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_allow_incoming: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"allowIncoming" => {
if let crate::cbor::Value::Text(s) = value {
field_allow_incoming = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsProfileAssociatedChat {
allow_incoming: field_allow_incoming.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'allowIncoming'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsProfileAssociatedGerm {
pub message_me_url: String,
pub show_button_to: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsProfileAssociatedGerm {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 2u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("messageMeUrl")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.message_me_url)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("showButtonTo")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.show_button_to)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.message_me_url)?;
pairs.push(("messageMeUrl", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.show_button_to)?;
pairs.push(("showButtonTo", 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_message_me_url: Option<String> = None;
let mut field_show_button_to: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"messageMeUrl" => {
if let crate::cbor::Value::Text(s) = value {
field_message_me_url = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"showButtonTo" => {
if let crate::cbor::Value::Text(s) = value {
field_show_button_to = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsProfileAssociatedGerm {
message_me_url: field_message_me_url.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'messageMeUrl'".into())
})?,
show_button_to: field_show_button_to.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'showButtonTo'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsProfileView {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub associated: Option<ActorDefsProfileAssociated>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avatar: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub created_at: Option<crate::syntax::Datetime>,
pub debug: serde_json::Value,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub did: crate::syntax::Did,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub display_name: Option<String>,
pub handle: crate::syntax::Handle,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub indexed_at: Option<crate::syntax::Datetime>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub labels: Vec<crate::api::com::atproto::LabelDefsLabel>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pronouns: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status: Option<ActorDefsStatusView>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub verification: Option<ActorDefsVerificationState>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub viewer: Option<ActorDefsViewerState>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsProfileView {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 2u64;
if self.avatar.is_some() {
count += 1;
}
if !self.labels.is_empty() {
count += 1;
}
if self.status.is_some() {
count += 1;
}
if self.viewer.is_some() {
count += 1;
}
if self.pronouns.is_some() {
count += 1;
}
if self.created_at.is_some() {
count += 1;
}
if self.indexed_at.is_some() {
count += 1;
}
if self.associated.is_some() {
count += 1;
}
if self.description.is_some() {
count += 1;
}
if self.display_name.is_some() {
count += 1;
}
if self.verification.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("did")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.did.as_str())?;
if self.avatar.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("avatar")?;
if let Some(ref val) = self.avatar {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("handle")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.handle.as_str())?;
if !self.labels.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("labels")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.labels.len() as u64)?;
for item in &self.labels {
item.encode_cbor(buf)?;
}
}
if self.status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("status")?;
if let Some(ref val) = self.status {
val.encode_cbor(buf)?;
}
}
if self.viewer.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("viewer")?;
if let Some(ref val) = self.viewer {
val.encode_cbor(buf)?;
}
}
if self.pronouns.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("pronouns")?;
if let Some(ref val) = self.pronouns {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.created_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
if let Some(ref val) = self.created_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.indexed_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("indexedAt")?;
if let Some(ref val) = self.indexed_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.associated.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("associated")?;
if let Some(ref val) = self.associated {
val.encode_cbor(buf)?;
}
}
if self.description.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("description")?;
if let Some(ref val) = self.description {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.display_name.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("displayName")?;
if let Some(ref val) = self.display_name {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.verification.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("verification")?;
if let Some(ref val) = self.verification {
val.encode_cbor(buf)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.did.as_str())?;
pairs.push(("did", vbuf));
}
if self.avatar.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.avatar {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("avatar", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.handle.as_str())?;
pairs.push(("handle", vbuf));
}
if !self.labels.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.labels.len() as u64)?;
for item in &self.labels {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("labels", vbuf));
}
if self.status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.status {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("status", vbuf));
}
if self.viewer.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.viewer {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("viewer", vbuf));
}
if self.pronouns.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.pronouns {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("pronouns", vbuf));
}
if self.created_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.created_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("createdAt", vbuf));
}
if self.indexed_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.indexed_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("indexedAt", vbuf));
}
if self.associated.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.associated {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("associated", vbuf));
}
if self.description.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.description {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("description", vbuf));
}
if self.display_name.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.display_name {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("displayName", vbuf));
}
if self.verification.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.verification {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("verification", 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_did: Option<crate::syntax::Did> = None;
let mut field_avatar: Option<String> = None;
let mut field_handle: Option<crate::syntax::Handle> = None;
let mut field_labels: Vec<crate::api::com::atproto::LabelDefsLabel> = Vec::new();
let mut field_status: Option<ActorDefsStatusView> = None;
let mut field_viewer: Option<ActorDefsViewerState> = None;
let mut field_pronouns: Option<String> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_indexed_at: Option<crate::syntax::Datetime> = None;
let mut field_associated: Option<ActorDefsProfileAssociated> = None;
let mut field_description: Option<String> = None;
let mut field_display_name: Option<String> = None;
let mut field_verification: Option<ActorDefsVerificationState> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"did" => {
if let crate::cbor::Value::Text(s) = value {
field_did = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"avatar" => {
if let crate::cbor::Value::Text(s) = value {
field_avatar = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"handle" => {
if let crate::cbor::Value::Text(s) = value {
field_handle = Some(
crate::syntax::Handle::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"labels" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_labels.push(
crate::api::com::atproto::LabelDefsLabel::decode_cbor(&mut dec)?,
);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"status" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_status = Some(ActorDefsStatusView::decode_cbor(&mut dec)?);
}
"viewer" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_viewer = Some(ActorDefsViewerState::decode_cbor(&mut dec)?);
}
"pronouns" => {
if let crate::cbor::Value::Text(s) = value {
field_pronouns = 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()));
}
}
"indexedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_indexed_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()));
}
}
"associated" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_associated = Some(ActorDefsProfileAssociated::decode_cbor(&mut dec)?);
}
"description" => {
if let crate::cbor::Value::Text(s) = value {
field_description = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"displayName" => {
if let crate::cbor::Value::Text(s) = value {
field_display_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"verification" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_verification = Some(ActorDefsVerificationState::decode_cbor(&mut dec)?);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsProfileView {
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
debug: Default::default(),
avatar: field_avatar,
handle: field_handle.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'handle'".into())
})?,
labels: field_labels,
status: field_status,
viewer: field_viewer,
pronouns: field_pronouns,
created_at: field_created_at,
indexed_at: field_indexed_at,
associated: field_associated,
description: field_description,
display_name: field_display_name,
verification: field_verification,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsProfileViewBasic {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub associated: Option<ActorDefsProfileAssociated>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avatar: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub created_at: Option<crate::syntax::Datetime>,
pub debug: serde_json::Value,
pub did: crate::syntax::Did,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub display_name: Option<String>,
pub handle: crate::syntax::Handle,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub labels: Vec<crate::api::com::atproto::LabelDefsLabel>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pronouns: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status: Option<ActorDefsStatusView>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub verification: Option<ActorDefsVerificationState>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub viewer: Option<ActorDefsViewerState>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsProfileViewBasic {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 2u64;
if self.avatar.is_some() {
count += 1;
}
if !self.labels.is_empty() {
count += 1;
}
if self.status.is_some() {
count += 1;
}
if self.viewer.is_some() {
count += 1;
}
if self.pronouns.is_some() {
count += 1;
}
if self.created_at.is_some() {
count += 1;
}
if self.associated.is_some() {
count += 1;
}
if self.display_name.is_some() {
count += 1;
}
if self.verification.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("did")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.did.as_str())?;
if self.avatar.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("avatar")?;
if let Some(ref val) = self.avatar {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("handle")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.handle.as_str())?;
if !self.labels.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("labels")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.labels.len() as u64)?;
for item in &self.labels {
item.encode_cbor(buf)?;
}
}
if self.status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("status")?;
if let Some(ref val) = self.status {
val.encode_cbor(buf)?;
}
}
if self.viewer.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("viewer")?;
if let Some(ref val) = self.viewer {
val.encode_cbor(buf)?;
}
}
if self.pronouns.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("pronouns")?;
if let Some(ref val) = self.pronouns {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.created_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
if let Some(ref val) = self.created_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.associated.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("associated")?;
if let Some(ref val) = self.associated {
val.encode_cbor(buf)?;
}
}
if self.display_name.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("displayName")?;
if let Some(ref val) = self.display_name {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.verification.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("verification")?;
if let Some(ref val) = self.verification {
val.encode_cbor(buf)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.did.as_str())?;
pairs.push(("did", vbuf));
}
if self.avatar.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.avatar {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("avatar", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.handle.as_str())?;
pairs.push(("handle", vbuf));
}
if !self.labels.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.labels.len() as u64)?;
for item in &self.labels {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("labels", vbuf));
}
if self.status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.status {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("status", vbuf));
}
if self.viewer.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.viewer {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("viewer", vbuf));
}
if self.pronouns.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.pronouns {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("pronouns", vbuf));
}
if self.created_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.created_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("createdAt", vbuf));
}
if self.associated.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.associated {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("associated", vbuf));
}
if self.display_name.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.display_name {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("displayName", vbuf));
}
if self.verification.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.verification {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("verification", 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_did: Option<crate::syntax::Did> = None;
let mut field_avatar: Option<String> = None;
let mut field_handle: Option<crate::syntax::Handle> = None;
let mut field_labels: Vec<crate::api::com::atproto::LabelDefsLabel> = Vec::new();
let mut field_status: Option<ActorDefsStatusView> = None;
let mut field_viewer: Option<ActorDefsViewerState> = None;
let mut field_pronouns: Option<String> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_associated: Option<ActorDefsProfileAssociated> = None;
let mut field_display_name: Option<String> = None;
let mut field_verification: Option<ActorDefsVerificationState> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"did" => {
if let crate::cbor::Value::Text(s) = value {
field_did = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"avatar" => {
if let crate::cbor::Value::Text(s) = value {
field_avatar = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"handle" => {
if let crate::cbor::Value::Text(s) = value {
field_handle = Some(
crate::syntax::Handle::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"labels" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_labels.push(
crate::api::com::atproto::LabelDefsLabel::decode_cbor(&mut dec)?,
);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"status" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_status = Some(ActorDefsStatusView::decode_cbor(&mut dec)?);
}
"viewer" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_viewer = Some(ActorDefsViewerState::decode_cbor(&mut dec)?);
}
"pronouns" => {
if let crate::cbor::Value::Text(s) = value {
field_pronouns = 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()));
}
}
"associated" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_associated = Some(ActorDefsProfileAssociated::decode_cbor(&mut dec)?);
}
"displayName" => {
if let crate::cbor::Value::Text(s) = value {
field_display_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"verification" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_verification = Some(ActorDefsVerificationState::decode_cbor(&mut dec)?);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsProfileViewBasic {
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
debug: Default::default(),
avatar: field_avatar,
handle: field_handle.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'handle'".into())
})?,
labels: field_labels,
status: field_status,
viewer: field_viewer,
pronouns: field_pronouns,
created_at: field_created_at,
associated: field_associated,
display_name: field_display_name,
verification: field_verification,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsProfileViewDetailed {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub associated: Option<ActorDefsProfileAssociated>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avatar: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub banner: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub created_at: Option<crate::syntax::Datetime>,
pub debug: serde_json::Value,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub did: crate::syntax::Did,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub display_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub followers_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub follows_count: Option<i64>,
pub handle: crate::syntax::Handle,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub indexed_at: Option<crate::syntax::Datetime>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub joined_via_starter_pack: Option<crate::api::app::bsky::GraphDefsStarterPackViewBasic>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub labels: Vec<crate::api::com::atproto::LabelDefsLabel>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pinned_post: Option<crate::api::com::atproto::RepoStrongRef>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub posts_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pronouns: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status: Option<ActorDefsStatusView>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub verification: Option<ActorDefsVerificationState>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub viewer: Option<ActorDefsViewerState>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub website: Option<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsProfileViewDetailed {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 2u64;
if self.avatar.is_some() {
count += 1;
}
if self.banner.is_some() {
count += 1;
}
if !self.labels.is_empty() {
count += 1;
}
if self.status.is_some() {
count += 1;
}
if self.viewer.is_some() {
count += 1;
}
if self.website.is_some() {
count += 1;
}
if self.pronouns.is_some() {
count += 1;
}
if self.created_at.is_some() {
count += 1;
}
if self.indexed_at.is_some() {
count += 1;
}
if self.associated.is_some() {
count += 1;
}
if self.pinned_post.is_some() {
count += 1;
}
if self.posts_count.is_some() {
count += 1;
}
if self.description.is_some() {
count += 1;
}
if self.display_name.is_some() {
count += 1;
}
if self.follows_count.is_some() {
count += 1;
}
if self.verification.is_some() {
count += 1;
}
if self.followers_count.is_some() {
count += 1;
}
if self.joined_via_starter_pack.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("did")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.did.as_str())?;
if self.avatar.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("avatar")?;
if let Some(ref val) = self.avatar {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.banner.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("banner")?;
if let Some(ref val) = self.banner {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("handle")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.handle.as_str())?;
if !self.labels.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("labels")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.labels.len() as u64)?;
for item in &self.labels {
item.encode_cbor(buf)?;
}
}
if self.status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("status")?;
if let Some(ref val) = self.status {
val.encode_cbor(buf)?;
}
}
if self.viewer.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("viewer")?;
if let Some(ref val) = self.viewer {
val.encode_cbor(buf)?;
}
}
if self.website.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("website")?;
if let Some(ref val) = self.website {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.pronouns.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("pronouns")?;
if let Some(ref val) = self.pronouns {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.created_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
if let Some(ref val) = self.created_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.indexed_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("indexedAt")?;
if let Some(ref val) = self.indexed_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.associated.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("associated")?;
if let Some(ref val) = self.associated {
val.encode_cbor(buf)?;
}
}
if self.pinned_post.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("pinnedPost")?;
if let Some(ref val) = self.pinned_post {
val.encode_cbor(buf)?;
}
}
if self.posts_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("postsCount")?;
if let Some(ref val) = self.posts_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.description.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("description")?;
if let Some(ref val) = self.description {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.display_name.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("displayName")?;
if let Some(ref val) = self.display_name {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.follows_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("followsCount")?;
if let Some(ref val) = self.follows_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.verification.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("verification")?;
if let Some(ref val) = self.verification {
val.encode_cbor(buf)?;
}
}
if self.followers_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("followersCount")?;
if let Some(ref val) = self.followers_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.joined_via_starter_pack.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("joinedViaStarterPack")?;
if let Some(ref val) = self.joined_via_starter_pack {
val.encode_cbor(buf)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.did.as_str())?;
pairs.push(("did", vbuf));
}
if self.avatar.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.avatar {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("avatar", vbuf));
}
if self.banner.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.banner {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("banner", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.handle.as_str())?;
pairs.push(("handle", vbuf));
}
if !self.labels.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.labels.len() as u64)?;
for item in &self.labels {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("labels", vbuf));
}
if self.status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.status {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("status", vbuf));
}
if self.viewer.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.viewer {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("viewer", vbuf));
}
if self.website.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.website {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("website", vbuf));
}
if self.pronouns.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.pronouns {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("pronouns", vbuf));
}
if self.created_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.created_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("createdAt", vbuf));
}
if self.indexed_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.indexed_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("indexedAt", vbuf));
}
if self.associated.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.associated {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("associated", vbuf));
}
if self.pinned_post.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.pinned_post {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("pinnedPost", vbuf));
}
if self.posts_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.posts_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("postsCount", vbuf));
}
if self.description.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.description {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("description", vbuf));
}
if self.display_name.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.display_name {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("displayName", vbuf));
}
if self.follows_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.follows_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("followsCount", vbuf));
}
if self.verification.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.verification {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("verification", vbuf));
}
if self.followers_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.followers_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("followersCount", vbuf));
}
if self.joined_via_starter_pack.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.joined_via_starter_pack {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("joinedViaStarterPack", 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_did: Option<crate::syntax::Did> = None;
let mut field_avatar: Option<String> = None;
let mut field_banner: Option<String> = None;
let mut field_handle: Option<crate::syntax::Handle> = None;
let mut field_labels: Vec<crate::api::com::atproto::LabelDefsLabel> = Vec::new();
let mut field_status: Option<ActorDefsStatusView> = None;
let mut field_viewer: Option<ActorDefsViewerState> = None;
let mut field_website: Option<String> = None;
let mut field_pronouns: Option<String> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_indexed_at: Option<crate::syntax::Datetime> = None;
let mut field_associated: Option<ActorDefsProfileAssociated> = None;
let mut field_pinned_post: Option<crate::api::com::atproto::RepoStrongRef> = None;
let mut field_posts_count: Option<i64> = None;
let mut field_description: Option<String> = None;
let mut field_display_name: Option<String> = None;
let mut field_follows_count: Option<i64> = None;
let mut field_verification: Option<ActorDefsVerificationState> = None;
let mut field_followers_count: Option<i64> = None;
let mut field_joined_via_starter_pack: Option<
crate::api::app::bsky::GraphDefsStarterPackViewBasic,
> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"did" => {
if let crate::cbor::Value::Text(s) = value {
field_did = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"avatar" => {
if let crate::cbor::Value::Text(s) = value {
field_avatar = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"banner" => {
if let crate::cbor::Value::Text(s) = value {
field_banner = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"handle" => {
if let crate::cbor::Value::Text(s) = value {
field_handle = Some(
crate::syntax::Handle::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"labels" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_labels.push(
crate::api::com::atproto::LabelDefsLabel::decode_cbor(&mut dec)?,
);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"status" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_status = Some(ActorDefsStatusView::decode_cbor(&mut dec)?);
}
"viewer" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_viewer = Some(ActorDefsViewerState::decode_cbor(&mut dec)?);
}
"website" => {
if let crate::cbor::Value::Text(s) = value {
field_website = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"pronouns" => {
if let crate::cbor::Value::Text(s) = value {
field_pronouns = 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()));
}
}
"indexedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_indexed_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()));
}
}
"associated" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_associated = Some(ActorDefsProfileAssociated::decode_cbor(&mut dec)?);
}
"pinnedPost" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_pinned_post = Some(crate::api::com::atproto::RepoStrongRef::decode_cbor(
&mut dec,
)?);
}
"postsCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_posts_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_posts_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"description" => {
if let crate::cbor::Value::Text(s) = value {
field_description = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"displayName" => {
if let crate::cbor::Value::Text(s) = value {
field_display_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"followsCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_follows_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_follows_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"verification" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_verification = Some(ActorDefsVerificationState::decode_cbor(&mut dec)?);
}
"followersCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_followers_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_followers_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"joinedViaStarterPack" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_joined_via_starter_pack = Some(
crate::api::app::bsky::GraphDefsStarterPackViewBasic::decode_cbor(
&mut dec,
)?,
);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsProfileViewDetailed {
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
debug: Default::default(),
avatar: field_avatar,
banner: field_banner,
handle: field_handle.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'handle'".into())
})?,
labels: field_labels,
status: field_status,
viewer: field_viewer,
website: field_website,
pronouns: field_pronouns,
created_at: field_created_at,
indexed_at: field_indexed_at,
associated: field_associated,
pinned_post: field_pinned_post,
posts_count: field_posts_count,
description: field_description,
display_name: field_display_name,
follows_count: field_follows_count,
verification: field_verification,
followers_count: field_followers_count,
joined_via_starter_pack: field_joined_via_starter_pack,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsSavedFeed {
pub id: String,
pub pinned: bool,
pub r#type: String,
pub value: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsSavedFeed {
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("id")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("type")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.r#type)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("value")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.value)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("pinned")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.pinned)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.id)?;
pairs.push(("id", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.r#type)?;
pairs.push(("type", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.value)?;
pairs.push(("value", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.pinned)?;
pairs.push(("pinned", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_id: Option<String> = None;
let mut field_type: Option<String> = None;
let mut field_value: Option<String> = None;
let mut field_pinned: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"id" => {
if let crate::cbor::Value::Text(s) = value {
field_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"type" => {
if let crate::cbor::Value::Text(s) = value {
field_type = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"value" => {
if let crate::cbor::Value::Text(s) = value {
field_value = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"pinned" => {
if let crate::cbor::Value::Bool(b) = value {
field_pinned = 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(ActorDefsSavedFeed {
id: field_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'id'".into())
})?,
r#type: field_type.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'type'".into())
})?,
value: field_value.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'value'".into())
})?,
pinned: field_pinned.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'pinned'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsSavedFeedsPref {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub pinned: Vec<crate::syntax::AtUri>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub saved: Vec<crate::syntax::AtUri>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub timeline_index: Option<i64>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsSavedFeedsPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 2u64;
if self.timeline_index.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("saved")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.saved.len() as u64)?;
for item in &self.saved {
crate::cbor::Encoder::new(&mut *buf).encode_text(item.as_str())?;
}
crate::cbor::Encoder::new(&mut *buf).encode_text("pinned")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.pinned.len() as u64)?;
for item in &self.pinned {
crate::cbor::Encoder::new(&mut *buf).encode_text(item.as_str())?;
}
if self.timeline_index.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("timelineIndex")?;
if let Some(ref val) = self.timeline_index {
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_array_header(self.saved.len() as u64)?;
for item in &self.saved {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item.as_str())?;
}
pairs.push(("saved", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.pinned.len() as u64)?;
for item in &self.pinned {
crate::cbor::Encoder::new(&mut vbuf).encode_text(item.as_str())?;
}
pairs.push(("pinned", vbuf));
}
if self.timeline_index.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.timeline_index {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("timelineIndex", 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_saved: Vec<crate::syntax::AtUri> = Vec::new();
let mut field_pinned: Vec<crate::syntax::AtUri> = Vec::new();
let mut field_timeline_index: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"saved" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_saved.push(crate::syntax::AtUri::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()));
}
}
"pinned" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Text(s) = item {
field_pinned.push(crate::syntax::AtUri::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()));
}
}
"timelineIndex" => match value {
crate::cbor::Value::Unsigned(n) => {
field_timeline_index = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_timeline_index = 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(ActorDefsSavedFeedsPref {
saved: field_saved,
pinned: field_pinned,
timeline_index: field_timeline_index,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsSavedFeedsPrefV2 {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub items: Vec<ActorDefsSavedFeed>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsSavedFeedsPrefV2 {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 1u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("items")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.items.len() as u64)?;
for item in &self.items {
item.encode_cbor(buf)?;
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_array_header(self.items.len() as u64)?;
for item in &self.items {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("items", 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_items: Vec<ActorDefsSavedFeed> = Vec::new();
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"items" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_items.push(ActorDefsSavedFeed::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsSavedFeedsPrefV2 {
items: field_items,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsStatusView {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cid: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub embed: Option<ActorDefsStatusViewEmbedUnion>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expires_at: Option<crate::syntax::Datetime>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_active: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_disabled: Option<bool>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub labels: Vec<crate::api::com::atproto::LabelDefsLabel>,
pub record: serde_json::Value,
pub status: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub uri: Option<crate::syntax::AtUri>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
#[derive(Debug, Clone)]
pub enum ActorDefsStatusViewEmbedUnion {
EmbedExternalView(Box<crate::api::app::bsky::EmbedExternalView>),
Unknown(crate::api::UnknownUnionVariant),
}
impl serde::Serialize for ActorDefsStatusViewEmbedUnion {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
ActorDefsStatusViewEmbedUnion::EmbedExternalView(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String("app.bsky.embed.external#view".to_string()),
);
}
map.serialize(serializer)
}
ActorDefsStatusViewEmbedUnion::Unknown(v) => {
if let Some(ref j) = v.json {
j.serialize(serializer)
} else {
Err(serde::ser::Error::custom(
"no JSON data for unknown union variant",
))
}
}
}
}
}
impl<'de> serde::Deserialize<'de> for ActorDefsStatusViewEmbedUnion {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = serde_json::Value::deserialize(deserializer)?;
let type_str = value
.get("$type")
.and_then(|v| v.as_str())
.unwrap_or_default();
match type_str {
"app.bsky.embed.external#view" => {
let inner: crate::api::app::bsky::EmbedExternalView =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(ActorDefsStatusViewEmbedUnion::EmbedExternalView(Box::new(
inner,
)))
}
_ => Ok(ActorDefsStatusViewEmbedUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: Some(value),
cbor: None,
},
)),
}
}
}
impl ActorDefsStatusViewEmbedUnion {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
match self {
ActorDefsStatusViewEmbedUnion::EmbedExternalView(inner) => inner.encode_cbor(buf),
ActorDefsStatusViewEmbedUnion::Unknown(v) => {
if let Some(ref data) = v.cbor {
buf.extend_from_slice(data);
Ok(())
} else {
Err(crate::cbor::CborError::InvalidCbor(
"no CBOR data for unknown union variant".into(),
))
}
}
}
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let start = decoder.position();
let val = decoder.decode()?;
let end = decoder.position();
let raw = &decoder.raw_input()[start..end];
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected map for union".into(),
));
}
};
let type_str = entries
.iter()
.find(|(k, _)| *k == "$type")
.and_then(|(_, v)| match v {
crate::cbor::Value::Text(s) => Some(*s),
_ => None,
})
.unwrap_or_default();
match type_str {
"app.bsky.embed.external#view" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = crate::api::app::bsky::EmbedExternalView::decode_cbor(&mut dec)?;
Ok(ActorDefsStatusViewEmbedUnion::EmbedExternalView(Box::new(
inner,
)))
}
_ => Ok(ActorDefsStatusViewEmbedUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: None,
cbor: Some(raw.to_vec()),
},
)),
}
}
}
impl ActorDefsStatusView {
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 = 1u64;
if self.cid.is_some() {
count += 1;
}
if self.uri.is_some() {
count += 1;
}
if self.embed.is_some() {
count += 1;
}
if !self.labels.is_empty() {
count += 1;
}
if self.is_active.is_some() {
count += 1;
}
if self.expires_at.is_some() {
count += 1;
}
if self.is_disabled.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.cid.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("cid")?;
if let Some(ref val) = self.cid {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.uri.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("uri")?;
if let Some(ref val) = self.uri {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.embed.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("embed")?;
if let Some(ref val) = self.embed {
val.encode_cbor(buf)?;
}
}
if !self.labels.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("labels")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.labels.len() as u64)?;
for item in &self.labels {
item.encode_cbor(buf)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("status")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.status)?;
if self.is_active.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("isActive")?;
if let Some(ref val) = self.is_active {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.expires_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("expiresAt")?;
if let Some(ref val) = self.expires_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.is_disabled.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("isDisabled")?;
if let Some(ref val) = self.is_disabled {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.cid.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.cid {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("cid", vbuf));
}
if self.uri.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.uri {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("uri", vbuf));
}
if self.embed.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.embed {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("embed", vbuf));
}
if !self.labels.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.labels.len() as u64)?;
for item in &self.labels {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("labels", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.status)?;
pairs.push(("status", vbuf));
}
if self.is_active.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.is_active {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("isActive", vbuf));
}
if self.expires_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.expires_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("expiresAt", vbuf));
}
if self.is_disabled.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.is_disabled {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("isDisabled", 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_cid: Option<String> = None;
let mut field_uri: Option<crate::syntax::AtUri> = None;
let mut field_embed: Option<ActorDefsStatusViewEmbedUnion> = None;
let mut field_labels: Vec<crate::api::com::atproto::LabelDefsLabel> = Vec::new();
let mut field_status: Option<String> = None;
let mut field_is_active: Option<bool> = None;
let mut field_expires_at: Option<crate::syntax::Datetime> = None;
let mut field_is_disabled: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"cid" => {
if let crate::cbor::Value::Text(s) = value {
field_cid = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"uri" => {
if let crate::cbor::Value::Text(s) = value {
field_uri = Some(
crate::syntax::AtUri::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"embed" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_embed = Some(ActorDefsStatusViewEmbedUnion::decode_cbor(&mut dec)?);
}
"labels" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_labels.push(
crate::api::com::atproto::LabelDefsLabel::decode_cbor(&mut dec)?,
);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"status" => {
if let crate::cbor::Value::Text(s) = value {
field_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"isActive" => {
if let crate::cbor::Value::Bool(b) = value {
field_is_active = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"expiresAt" => {
if let crate::cbor::Value::Text(s) = value {
field_expires_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()));
}
}
"isDisabled" => {
if let crate::cbor::Value::Bool(b) = value {
field_is_disabled = 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(ActorDefsStatusView {
cid: field_cid,
uri: field_uri,
embed: field_embed,
labels: field_labels,
record: Default::default(),
status: field_status.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'status'".into())
})?,
is_active: field_is_active,
expires_at: field_expires_at,
is_disabled: field_is_disabled,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsThreadViewPref {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sort: Option<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsThreadViewPref {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.sort.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.sort.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("sort")?;
if let Some(ref val) = self.sort {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.sort.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.sort {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("sort", 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_sort: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"sort" => {
if let crate::cbor::Value::Text(s) = value {
field_sort = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsThreadViewPref {
sort: field_sort,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsVerificationPrefs {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hide_badges: Option<bool>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsVerificationPrefs {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.hide_badges.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.hide_badges.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("hideBadges")?;
if let Some(ref val) = self.hide_badges {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.hide_badges.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.hide_badges {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("hideBadges", 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_hide_badges: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"hideBadges" => {
if let crate::cbor::Value::Bool(b) = value {
field_hide_badges = 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(ActorDefsVerificationPrefs {
hide_badges: field_hide_badges,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsVerificationState {
pub trusted_verifier_status: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub verifications: Vec<ActorDefsVerificationView>,
pub verified_status: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsVerificationState {
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 = 3u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("verifications")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.verifications.len() as u64)?;
for item in &self.verifications {
item.encode_cbor(buf)?;
}
crate::cbor::Encoder::new(&mut *buf).encode_text("verifiedStatus")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.verified_status)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("trustedVerifierStatus")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.trusted_verifier_status)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.verifications.len() as u64)?;
for item in &self.verifications {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("verifications", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.verified_status)?;
pairs.push(("verifiedStatus", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.trusted_verifier_status)?;
pairs.push(("trustedVerifierStatus", 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_verifications: Vec<ActorDefsVerificationView> = Vec::new();
let mut field_verified_status: Option<String> = None;
let mut field_trusted_verifier_status: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"verifications" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_verifications
.push(ActorDefsVerificationView::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"verifiedStatus" => {
if let crate::cbor::Value::Text(s) = value {
field_verified_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"trustedVerifierStatus" => {
if let crate::cbor::Value::Text(s) = value {
field_trusted_verifier_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsVerificationState {
verifications: field_verifications,
verified_status: field_verified_status.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'verifiedStatus'".into(),
)
})?,
trusted_verifier_status: field_trusted_verifier_status.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'trustedVerifierStatus'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsVerificationView {
pub created_at: crate::syntax::Datetime,
pub is_valid: bool,
pub issuer: crate::syntax::Did,
pub uri: crate::syntax::AtUri,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsVerificationView {
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("uri")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.uri.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("issuer")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.issuer.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("isValid")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.is_valid)?;
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.uri.as_str())?;
pairs.push(("uri", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.issuer.as_str())?;
pairs.push(("issuer", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.is_valid)?;
pairs.push(("isValid", 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_uri: Option<crate::syntax::AtUri> = None;
let mut field_issuer: Option<crate::syntax::Did> = None;
let mut field_is_valid: Option<bool> = 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 {
"uri" => {
if let crate::cbor::Value::Text(s) = value {
field_uri = Some(
crate::syntax::AtUri::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"issuer" => {
if let crate::cbor::Value::Text(s) = value {
field_issuer = 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()));
}
}
"isValid" => {
if let crate::cbor::Value::Bool(b) = value {
field_is_valid = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"createdAt" => {
if let crate::cbor::Value::Text(s) = value {
field_created_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsVerificationView {
uri: field_uri.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'uri'".into())
})?,
issuer: field_issuer.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'issuer'".into())
})?,
is_valid: field_is_valid.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'isValid'".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,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorDefsViewerState {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub activity_subscription: Option<crate::api::app::bsky::NotificationDefsActivitySubscription>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub blocked_by: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub blocking: Option<crate::syntax::AtUri>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub blocking_by_list: Option<crate::api::app::bsky::GraphDefsListViewBasic>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub followed_by: Option<crate::syntax::AtUri>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub following: Option<crate::syntax::AtUri>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub known_followers: Option<ActorDefsKnownFollowers>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub muted: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub muted_by_list: Option<crate::api::app::bsky::GraphDefsListViewBasic>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ActorDefsViewerState {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.muted.is_some() {
count += 1;
}
if self.blocking.is_some() {
count += 1;
}
if self.blocked_by.is_some() {
count += 1;
}
if self.following.is_some() {
count += 1;
}
if self.followed_by.is_some() {
count += 1;
}
if self.muted_by_list.is_some() {
count += 1;
}
if self.blocking_by_list.is_some() {
count += 1;
}
if self.known_followers.is_some() {
count += 1;
}
if self.activity_subscription.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.muted.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("muted")?;
if let Some(ref val) = self.muted {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.blocking.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("blocking")?;
if let Some(ref val) = self.blocking {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.blocked_by.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("blockedBy")?;
if let Some(ref val) = self.blocked_by {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
if self.following.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("following")?;
if let Some(ref val) = self.following {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.followed_by.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("followedBy")?;
if let Some(ref val) = self.followed_by {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.muted_by_list.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("mutedByList")?;
if let Some(ref val) = self.muted_by_list {
val.encode_cbor(buf)?;
}
}
if self.blocking_by_list.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("blockingByList")?;
if let Some(ref val) = self.blocking_by_list {
val.encode_cbor(buf)?;
}
}
if self.known_followers.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("knownFollowers")?;
if let Some(ref val) = self.known_followers {
val.encode_cbor(buf)?;
}
}
if self.activity_subscription.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("activitySubscription")?;
if let Some(ref val) = self.activity_subscription {
val.encode_cbor(buf)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.muted.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.muted {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("muted", vbuf));
}
if self.blocking.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.blocking {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("blocking", vbuf));
}
if self.blocked_by.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.blocked_by {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("blockedBy", vbuf));
}
if self.following.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.following {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("following", vbuf));
}
if self.followed_by.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.followed_by {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("followedBy", vbuf));
}
if self.muted_by_list.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.muted_by_list {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("mutedByList", vbuf));
}
if self.blocking_by_list.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.blocking_by_list {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("blockingByList", vbuf));
}
if self.known_followers.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.known_followers {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("knownFollowers", vbuf));
}
if self.activity_subscription.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.activity_subscription {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("activitySubscription", 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_muted: Option<bool> = None;
let mut field_blocking: Option<crate::syntax::AtUri> = None;
let mut field_blocked_by: Option<bool> = None;
let mut field_following: Option<crate::syntax::AtUri> = None;
let mut field_followed_by: Option<crate::syntax::AtUri> = None;
let mut field_muted_by_list: Option<crate::api::app::bsky::GraphDefsListViewBasic> = None;
let mut field_blocking_by_list: Option<crate::api::app::bsky::GraphDefsListViewBasic> =
None;
let mut field_known_followers: Option<ActorDefsKnownFollowers> = None;
let mut field_activity_subscription: Option<
crate::api::app::bsky::NotificationDefsActivitySubscription,
> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"muted" => {
if let crate::cbor::Value::Bool(b) = value {
field_muted = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"blocking" => {
if let crate::cbor::Value::Text(s) = value {
field_blocking = Some(
crate::syntax::AtUri::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"blockedBy" => {
if let crate::cbor::Value::Bool(b) = value {
field_blocked_by = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"following" => {
if let crate::cbor::Value::Text(s) = value {
field_following = Some(
crate::syntax::AtUri::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"followedBy" => {
if let crate::cbor::Value::Text(s) = value {
field_followed_by = Some(
crate::syntax::AtUri::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"mutedByList" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_muted_by_list = Some(
crate::api::app::bsky::GraphDefsListViewBasic::decode_cbor(&mut dec)?,
);
}
"blockingByList" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_blocking_by_list = Some(
crate::api::app::bsky::GraphDefsListViewBasic::decode_cbor(&mut dec)?,
);
}
"knownFollowers" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_known_followers = Some(ActorDefsKnownFollowers::decode_cbor(&mut dec)?);
}
"activitySubscription" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_activity_subscription = Some(
crate::api::app::bsky::NotificationDefsActivitySubscription::decode_cbor(
&mut dec,
)?,
);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ActorDefsViewerState {
muted: field_muted,
blocking: field_blocking,
blocked_by: field_blocked_by,
following: field_following,
followed_by: field_followed_by,
muted_by_list: field_muted_by_list,
blocking_by_list: field_blocking_by_list,
known_followers: field_known_followers,
activity_subscription: field_activity_subscription,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}