pub const GRAPH_DEFS_CURATELIST: &str = "app.bsky.graph.defs#curatelist";
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphDefsListItemView {
pub subject: crate::api::app::bsky::ActorDefsProfileView,
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 GraphDefsListItemView {
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("uri")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.uri.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("subject")?;
self.subject.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.uri.as_str())?;
pairs.push(("uri", vbuf));
}
{
let mut vbuf = Vec::new();
self.subject.encode_cbor(&mut vbuf)?;
pairs.push(("subject", 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_subject: Option<crate::api::app::bsky::ActorDefsProfileView> = 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()));
}
}
"subject" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_subject = Some(crate::api::app::bsky::ActorDefsProfileView::decode_cbor(
&mut dec,
)?);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(GraphDefsListItemView {
uri: field_uri.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'uri'".into())
})?,
subject: field_subject.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'subject'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
pub type GraphDefsListPurpose = String;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphDefsListView {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avatar: Option<String>,
pub cid: String,
pub creator: crate::api::app::bsky::ActorDefsProfileView,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub description_facets: Vec<crate::api::app::bsky::RichtextFacet>,
pub indexed_at: 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 list_item_count: Option<i64>,
pub name: String,
pub purpose: GraphDefsListPurpose,
pub uri: crate::syntax::AtUri,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub viewer: Option<GraphDefsListViewerState>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GraphDefsListView {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 6u64;
if self.avatar.is_some() {
count += 1;
}
if !self.labels.is_empty() {
count += 1;
}
if self.viewer.is_some() {
count += 1;
}
if self.description.is_some() {
count += 1;
}
if self.list_item_count.is_some() {
count += 1;
}
if !self.description_facets.is_empty() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("cid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.cid)?;
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("name")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.name)?;
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.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.viewer.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("viewer")?;
if let Some(ref val) = self.viewer {
val.encode_cbor(buf)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("creator")?;
self.creator.encode_cbor(buf)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("purpose")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.purpose)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("indexedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.indexed_at.as_str())?;
if self.description.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("description")?;
if let Some(ref val) = self.description {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.list_item_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("listItemCount")?;
if let Some(ref val) = self.list_item_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if !self.description_facets.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("descriptionFacets")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.description_facets.len() as u64)?;
for item in &self.description_facets {
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_text(&self.cid)?;
pairs.push(("cid", vbuf));
}
{
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.name)?;
pairs.push(("name", 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.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.viewer.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.viewer {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("viewer", vbuf));
}
{
let mut vbuf = Vec::new();
self.creator.encode_cbor(&mut vbuf)?;
pairs.push(("creator", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.purpose)?;
pairs.push(("purpose", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.indexed_at.as_str())?;
pairs.push(("indexedAt", 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.list_item_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.list_item_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("listItemCount", vbuf));
}
if !self.description_facets.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.description_facets.len() as u64)?;
for item in &self.description_facets {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("descriptionFacets", 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_name: Option<String> = None;
let mut field_avatar: Option<String> = None;
let mut field_labels: Vec<crate::api::com::atproto::LabelDefsLabel> = Vec::new();
let mut field_viewer: Option<GraphDefsListViewerState> = None;
let mut field_creator: Option<crate::api::app::bsky::ActorDefsProfileView> = None;
let mut field_purpose: Option<GraphDefsListPurpose> = None;
let mut field_indexed_at: Option<crate::syntax::Datetime> = None;
let mut field_description: Option<String> = None;
let mut field_list_item_count: Option<i64> = None;
let mut field_description_facets: Vec<crate::api::app::bsky::RichtextFacet> = Vec::new();
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()));
}
}
"name" => {
if let crate::cbor::Value::Text(s) = value {
field_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"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()));
}
}
"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()));
}
}
"viewer" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_viewer = Some(GraphDefsListViewerState::decode_cbor(&mut dec)?);
}
"creator" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_creator = Some(crate::api::app::bsky::ActorDefsProfileView::decode_cbor(
&mut dec,
)?);
}
"purpose" => {
if let crate::cbor::Value::Text(s) = value {
field_purpose = Some(s.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()));
}
}
"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()));
}
}
"listItemCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_list_item_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_list_item_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"descriptionFacets" => {
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_description_facets
.push(crate::api::app::bsky::RichtextFacet::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(GraphDefsListView {
cid: field_cid.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'cid'".into())
})?,
uri: field_uri.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'uri'".into())
})?,
name: field_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'name'".into())
})?,
avatar: field_avatar,
labels: field_labels,
viewer: field_viewer,
creator: field_creator.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'creator'".into())
})?,
purpose: field_purpose.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'purpose'".into())
})?,
indexed_at: field_indexed_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'indexedAt'".into())
})?,
description: field_description,
list_item_count: field_list_item_count,
description_facets: field_description_facets,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphDefsListViewBasic {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avatar: Option<String>,
pub cid: String,
#[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 list_item_count: Option<i64>,
pub name: String,
pub purpose: GraphDefsListPurpose,
pub uri: crate::syntax::AtUri,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub viewer: Option<GraphDefsListViewerState>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GraphDefsListViewBasic {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 4u64;
if self.avatar.is_some() {
count += 1;
}
if !self.labels.is_empty() {
count += 1;
}
if self.viewer.is_some() {
count += 1;
}
if self.indexed_at.is_some() {
count += 1;
}
if self.list_item_count.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("cid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.cid)?;
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("name")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.name)?;
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.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.viewer.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("viewer")?;
if let Some(ref val) = self.viewer {
val.encode_cbor(buf)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("purpose")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.purpose)?;
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.list_item_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("listItemCount")?;
if let Some(ref val) = self.list_item_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.cid)?;
pairs.push(("cid", vbuf));
}
{
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.name)?;
pairs.push(("name", 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.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.viewer.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.viewer {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("viewer", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.purpose)?;
pairs.push(("purpose", 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.list_item_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.list_item_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("listItemCount", 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_name: Option<String> = None;
let mut field_avatar: Option<String> = None;
let mut field_labels: Vec<crate::api::com::atproto::LabelDefsLabel> = Vec::new();
let mut field_viewer: Option<GraphDefsListViewerState> = None;
let mut field_purpose: Option<GraphDefsListPurpose> = None;
let mut field_indexed_at: Option<crate::syntax::Datetime> = None;
let mut field_list_item_count: Option<i64> = 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()));
}
}
"name" => {
if let crate::cbor::Value::Text(s) = value {
field_name = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"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()));
}
}
"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()));
}
}
"viewer" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_viewer = Some(GraphDefsListViewerState::decode_cbor(&mut dec)?);
}
"purpose" => {
if let crate::cbor::Value::Text(s) = value {
field_purpose = Some(s.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()));
}
}
"listItemCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_list_item_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_list_item_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(GraphDefsListViewBasic {
cid: field_cid.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'cid'".into())
})?,
uri: field_uri.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'uri'".into())
})?,
name: field_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'name'".into())
})?,
avatar: field_avatar,
labels: field_labels,
viewer: field_viewer,
purpose: field_purpose.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'purpose'".into())
})?,
indexed_at: field_indexed_at,
list_item_count: field_list_item_count,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphDefsListViewerState {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub blocked: Option<crate::syntax::AtUri>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub muted: Option<bool>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GraphDefsListViewerState {
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.blocked.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.blocked.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("blocked")?;
if let Some(ref val) = self.blocked {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
} 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.blocked.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.blocked {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("blocked", 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_blocked: Option<crate::syntax::AtUri> = 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()));
}
}
"blocked" => {
if let crate::cbor::Value::Text(s) = value {
field_blocked = 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()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(GraphDefsListViewerState {
muted: field_muted,
blocked: field_blocked,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
pub const GRAPH_DEFS_MODLIST: &str = "app.bsky.graph.defs#modlist";
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphDefsNotFoundActor {
pub actor: crate::syntax::AtIdentifier,
pub not_found: bool,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GraphDefsNotFoundActor {
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("actor")?;
{
let __s = self.actor.to_string();
crate::cbor::Encoder::new(&mut *buf).encode_text(&__s)?;
}
crate::cbor::Encoder::new(&mut *buf).encode_text("notFound")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.not_found)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
{
let __s = self.actor.to_string();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&__s)?;
}
pairs.push(("actor", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.not_found)?;
pairs.push(("notFound", 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_actor: Option<crate::syntax::AtIdentifier> = None;
let mut field_not_found: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"actor" => {
if let crate::cbor::Value::Text(s) = value {
field_actor = Some(
crate::syntax::AtIdentifier::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"notFound" => {
if let crate::cbor::Value::Bool(b) = value {
field_not_found = 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(GraphDefsNotFoundActor {
actor: field_actor.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'actor'".into())
})?,
not_found: field_not_found.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'notFound'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
pub const GRAPH_DEFS_REFERENCELIST: &str = "app.bsky.graph.defs#referencelist";
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphDefsRelationship {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub blocked_by: Option<crate::syntax::AtUri>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub blocked_by_list: Option<crate::syntax::AtUri>,
#[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::syntax::AtUri>,
pub did: crate::syntax::Did,
#[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(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GraphDefsRelationship {
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.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.blocked_by_list.is_some() {
count += 1;
}
if self.blocking_by_list.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.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_text(val.as_str())?;
}
}
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.blocked_by_list.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("blockedByList")?;
if let Some(ref val) = self.blocked_by_list {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
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 {
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.did.as_str())?;
pairs.push(("did", 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_text(val.as_str())?;
}
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.blocked_by_list.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.blocked_by_list {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("blockedByList", vbuf));
}
if self.blocking_by_list.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.blocking_by_list {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("blockingByList", 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_blocking: Option<crate::syntax::AtUri> = None;
let mut field_blocked_by: Option<crate::syntax::AtUri> = None;
let mut field_following: Option<crate::syntax::AtUri> = None;
let mut field_followed_by: Option<crate::syntax::AtUri> = None;
let mut field_blocked_by_list: Option<crate::syntax::AtUri> = None;
let mut field_blocking_by_list: Option<crate::syntax::AtUri> = 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()));
}
}
"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::Text(s) = value {
field_blocked_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()));
}
}
"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()));
}
}
"blockedByList" => {
if let crate::cbor::Value::Text(s) = value {
field_blocked_by_list = 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()));
}
}
"blockingByList" => {
if let crate::cbor::Value::Text(s) = value {
field_blocking_by_list = 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()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(GraphDefsRelationship {
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
blocking: field_blocking,
blocked_by: field_blocked_by,
following: field_following,
followed_by: field_followed_by,
blocked_by_list: field_blocked_by_list,
blocking_by_list: field_blocking_by_list,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphDefsStarterPackView {
pub cid: String,
pub creator: crate::api::app::bsky::ActorDefsProfileViewBasic,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub feeds: Vec<crate::api::app::bsky::FeedDefsGeneratorView>,
pub indexed_at: crate::syntax::Datetime,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub joined_all_time_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub joined_week_count: Option<i64>,
#[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 list: Option<GraphDefsListViewBasic>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub list_items_sample: Vec<GraphDefsListItemView>,
pub record: serde_json::Value,
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 GraphDefsStarterPackView {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 4u64;
if self.list.is_some() {
count += 1;
}
if !self.feeds.is_empty() {
count += 1;
}
if !self.labels.is_empty() {
count += 1;
}
if self.joined_week_count.is_some() {
count += 1;
}
if !self.list_items_sample.is_empty() {
count += 1;
}
if self.joined_all_time_count.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("cid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.cid)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("uri")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.uri.as_str())?;
if self.list.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("list")?;
if let Some(ref val) = self.list {
val.encode_cbor(buf)?;
}
}
if !self.feeds.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("feeds")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.feeds.len() as u64)?;
for item in &self.feeds {
item.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("creator")?;
self.creator.encode_cbor(buf)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("indexedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.indexed_at.as_str())?;
if self.joined_week_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("joinedWeekCount")?;
if let Some(ref val) = self.joined_week_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if !self.list_items_sample.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("listItemsSample")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.list_items_sample.len() as u64)?;
for item in &self.list_items_sample {
item.encode_cbor(buf)?;
}
}
if self.joined_all_time_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("joinedAllTimeCount")?;
if let Some(ref val) = self.joined_all_time_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.cid)?;
pairs.push(("cid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.uri.as_str())?;
pairs.push(("uri", vbuf));
}
if self.list.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.list {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("list", vbuf));
}
if !self.feeds.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_array_header(self.feeds.len() as u64)?;
for item in &self.feeds {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("feeds", 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();
self.creator.encode_cbor(&mut vbuf)?;
pairs.push(("creator", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.indexed_at.as_str())?;
pairs.push(("indexedAt", vbuf));
}
if self.joined_week_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.joined_week_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("joinedWeekCount", vbuf));
}
if !self.list_items_sample.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.list_items_sample.len() as u64)?;
for item in &self.list_items_sample {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("listItemsSample", vbuf));
}
if self.joined_all_time_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.joined_all_time_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("joinedAllTimeCount", 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_list: Option<GraphDefsListViewBasic> = None;
let mut field_feeds: Vec<crate::api::app::bsky::FeedDefsGeneratorView> = Vec::new();
let mut field_labels: Vec<crate::api::com::atproto::LabelDefsLabel> = Vec::new();
let mut field_creator: Option<crate::api::app::bsky::ActorDefsProfileViewBasic> = None;
let mut field_indexed_at: Option<crate::syntax::Datetime> = None;
let mut field_joined_week_count: Option<i64> = None;
let mut field_list_items_sample: Vec<GraphDefsListItemView> = Vec::new();
let mut field_joined_all_time_count: Option<i64> = 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()));
}
}
"list" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_list = Some(GraphDefsListViewBasic::decode_cbor(&mut dec)?);
}
"feeds" => {
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_feeds.push(
crate::api::app::bsky::FeedDefsGeneratorView::decode_cbor(
&mut dec,
)?,
);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".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()));
}
}
"creator" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_creator = Some(
crate::api::app::bsky::ActorDefsProfileViewBasic::decode_cbor(&mut dec)?,
);
}
"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()));
}
}
"joinedWeekCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_joined_week_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_joined_week_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"listItemsSample" => {
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_list_items_sample
.push(GraphDefsListItemView::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"joinedAllTimeCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_joined_all_time_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_joined_all_time_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(GraphDefsStarterPackView {
cid: field_cid.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'cid'".into())
})?,
uri: field_uri.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'uri'".into())
})?,
list: field_list,
feeds: field_feeds,
labels: field_labels,
record: Default::default(),
creator: field_creator.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'creator'".into())
})?,
indexed_at: field_indexed_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'indexedAt'".into())
})?,
joined_week_count: field_joined_week_count,
list_items_sample: field_list_items_sample,
joined_all_time_count: field_joined_all_time_count,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraphDefsStarterPackViewBasic {
pub cid: String,
pub creator: crate::api::app::bsky::ActorDefsProfileViewBasic,
pub indexed_at: crate::syntax::Datetime,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub joined_all_time_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub joined_week_count: Option<i64>,
#[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 list_item_count: Option<i64>,
pub record: serde_json::Value,
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 GraphDefsStarterPackViewBasic {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 4u64;
if !self.labels.is_empty() {
count += 1;
}
if self.list_item_count.is_some() {
count += 1;
}
if self.joined_week_count.is_some() {
count += 1;
}
if self.joined_all_time_count.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("cid")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.cid)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("uri")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.uri.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)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("creator")?;
self.creator.encode_cbor(buf)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("indexedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.indexed_at.as_str())?;
if self.list_item_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("listItemCount")?;
if let Some(ref val) = self.list_item_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.joined_week_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("joinedWeekCount")?;
if let Some(ref val) = self.joined_week_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.joined_all_time_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("joinedAllTimeCount")?;
if let Some(ref val) = self.joined_all_time_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.cid)?;
pairs.push(("cid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.uri.as_str())?;
pairs.push(("uri", 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();
self.creator.encode_cbor(&mut vbuf)?;
pairs.push(("creator", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.indexed_at.as_str())?;
pairs.push(("indexedAt", vbuf));
}
if self.list_item_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.list_item_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("listItemCount", vbuf));
}
if self.joined_week_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.joined_week_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("joinedWeekCount", vbuf));
}
if self.joined_all_time_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.joined_all_time_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("joinedAllTimeCount", 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_labels: Vec<crate::api::com::atproto::LabelDefsLabel> = Vec::new();
let mut field_creator: Option<crate::api::app::bsky::ActorDefsProfileViewBasic> = None;
let mut field_indexed_at: Option<crate::syntax::Datetime> = None;
let mut field_list_item_count: Option<i64> = None;
let mut field_joined_week_count: Option<i64> = None;
let mut field_joined_all_time_count: Option<i64> = 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()));
}
}
"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()));
}
}
"creator" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_creator = Some(
crate::api::app::bsky::ActorDefsProfileViewBasic::decode_cbor(&mut dec)?,
);
}
"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()));
}
}
"listItemCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_list_item_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_list_item_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"joinedWeekCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_joined_week_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_joined_week_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"joinedAllTimeCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_joined_all_time_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_joined_all_time_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(GraphDefsStarterPackViewBasic {
cid: field_cid.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'cid'".into())
})?,
uri: field_uri.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'uri'".into())
})?,
labels: field_labels,
record: Default::default(),
creator: field_creator.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'creator'".into())
})?,
indexed_at: field_indexed_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'indexedAt'".into())
})?,
list_item_count: field_list_item_count,
joined_week_count: field_joined_week_count,
joined_all_time_count: field_joined_all_time_count,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}