#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GroupDefsJoinLinkPreviewView {
pub code: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub convo: Option<crate::api::chat::bsky::ConvoDefsConvoView>,
pub enabled_status: GroupDefsLinkEnabledStatus,
pub join_rule: GroupDefsJoinRule,
pub member_count: i64,
pub member_limit: i64,
pub name: String,
pub owner: crate::api::chat::bsky::ActorDefsProfileViewBasic,
pub require_approval: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub viewer: Option<GroupDefsJoinLinkViewerState>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GroupDefsJoinLinkPreviewView {
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 = 8u64;
if self.convo.is_some() {
count += 1;
}
if self.viewer.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("code")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.code)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("name")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.name)?;
if self.convo.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("convo")?;
if let Some(ref val) = self.convo {
val.encode_cbor(buf)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("owner")?;
self.owner.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("joinRule")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.join_rule)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("memberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.member_count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("memberLimit")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.member_limit)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("enabledStatus")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.enabled_status)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("requireApproval")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.require_approval)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.code)?;
pairs.push(("code", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.name)?;
pairs.push(("name", vbuf));
}
if self.convo.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.convo {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("convo", vbuf));
}
{
let mut vbuf = Vec::new();
self.owner.encode_cbor(&mut vbuf)?;
pairs.push(("owner", 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.join_rule)?;
pairs.push(("joinRule", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.member_count)?;
pairs.push(("memberCount", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.member_limit)?;
pairs.push(("memberLimit", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.enabled_status)?;
pairs.push(("enabledStatus", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.require_approval)?;
pairs.push(("requireApproval", 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_code: Option<String> = None;
let mut field_name: Option<String> = None;
let mut field_convo: Option<crate::api::chat::bsky::ConvoDefsConvoView> = None;
let mut field_owner: Option<crate::api::chat::bsky::ActorDefsProfileViewBasic> = None;
let mut field_viewer: Option<GroupDefsJoinLinkViewerState> = None;
let mut field_join_rule: Option<GroupDefsJoinRule> = None;
let mut field_member_count: Option<i64> = None;
let mut field_member_limit: Option<i64> = None;
let mut field_enabled_status: Option<GroupDefsLinkEnabledStatus> = None;
let mut field_require_approval: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"code" => {
if let crate::cbor::Value::Text(s) = value {
field_code = Some(s.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()));
}
}
"convo" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_convo = Some(crate::api::chat::bsky::ConvoDefsConvoView::decode_cbor(
&mut dec,
)?);
}
"owner" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_owner = Some(
crate::api::chat::bsky::ActorDefsProfileViewBasic::decode_cbor(&mut dec)?,
);
}
"viewer" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_viewer = Some(GroupDefsJoinLinkViewerState::decode_cbor(&mut dec)?);
}
"joinRule" => {
if let crate::cbor::Value::Text(s) = value {
field_join_rule = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"memberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_member_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"memberLimit" => match value {
crate::cbor::Value::Unsigned(n) => {
field_member_limit = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_member_limit = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"enabledStatus" => {
if let crate::cbor::Value::Text(s) = value {
field_enabled_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"requireApproval" => {
if let crate::cbor::Value::Bool(b) = value {
field_require_approval = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(GroupDefsJoinLinkPreviewView {
code: field_code.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'code'".into())
})?,
name: field_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'name'".into())
})?,
convo: field_convo,
owner: field_owner.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'owner'".into())
})?,
viewer: field_viewer,
join_rule: field_join_rule.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'joinRule'".into())
})?,
member_count: field_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'memberCount'".into())
})?,
member_limit: field_member_limit.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'memberLimit'".into())
})?,
enabled_status: field_enabled_status.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'enabledStatus'".into())
})?,
require_approval: field_require_approval.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'requireApproval'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GroupDefsJoinLinkView {
pub code: String,
pub created_at: crate::syntax::Datetime,
pub enabled_status: GroupDefsLinkEnabledStatus,
pub join_rule: GroupDefsJoinRule,
pub require_approval: bool,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GroupDefsJoinLinkView {
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 = 5u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("code")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.code)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("joinRule")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.join_rule)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("enabledStatus")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.enabled_status)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("requireApproval")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.require_approval)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.code)?;
pairs.push(("code", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.join_rule)?;
pairs.push(("joinRule", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.created_at.as_str())?;
pairs.push(("createdAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.enabled_status)?;
pairs.push(("enabledStatus", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.require_approval)?;
pairs.push(("requireApproval", 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_code: Option<String> = None;
let mut field_join_rule: Option<GroupDefsJoinRule> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_enabled_status: Option<GroupDefsLinkEnabledStatus> = None;
let mut field_require_approval: Option<bool> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"code" => {
if let crate::cbor::Value::Text(s) = value {
field_code = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"joinRule" => {
if let crate::cbor::Value::Text(s) = value {
field_join_rule = 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()));
}
}
"enabledStatus" => {
if let crate::cbor::Value::Text(s) = value {
field_enabled_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"requireApproval" => {
if let crate::cbor::Value::Bool(b) = value {
field_require_approval = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(GroupDefsJoinLinkView {
code: field_code.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'code'".into())
})?,
join_rule: field_join_rule.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'joinRule'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
enabled_status: field_enabled_status.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'enabledStatus'".into())
})?,
require_approval: field_require_approval.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor(
"missing required field 'requireApproval'".into(),
)
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GroupDefsJoinLinkViewerState {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub requested_at: Option<crate::syntax::Datetime>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GroupDefsJoinLinkViewerState {
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.requested_at.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.requested_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("requestedAt")?;
if let Some(ref val) = self.requested_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.requested_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.requested_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("requestedAt", 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_requested_at: Option<crate::syntax::Datetime> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"requestedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_requested_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(GroupDefsJoinLinkViewerState {
requested_at: field_requested_at,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GroupDefsJoinRequestConvoView {
pub convo_id: String,
pub member_count: i64,
pub member_limit: i64,
pub name: String,
pub owner: crate::api::chat::bsky::ActorDefsProfileViewBasic,
pub requested_at: crate::syntax::Datetime,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GroupDefsJoinRequestConvoView {
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 = 6u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("name")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.name)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("owner")?;
self.owner.encode_cbor(buf)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("memberCount")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.member_count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("memberLimit")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.member_limit)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("requestedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.requested_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.name)?;
pairs.push(("name", vbuf));
}
{
let mut vbuf = Vec::new();
self.owner.encode_cbor(&mut vbuf)?;
pairs.push(("owner", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.member_count)?;
pairs.push(("memberCount", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.member_limit)?;
pairs.push(("memberLimit", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.requested_at.as_str())?;
pairs.push(("requestedAt", 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_name: Option<String> = None;
let mut field_owner: Option<crate::api::chat::bsky::ActorDefsProfileViewBasic> = None;
let mut field_convo_id: Option<String> = None;
let mut field_member_count: Option<i64> = None;
let mut field_member_limit: Option<i64> = None;
let mut field_requested_at: Option<crate::syntax::Datetime> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"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()));
}
}
"owner" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_owner = Some(
crate::api::chat::bsky::ActorDefsProfileViewBasic::decode_cbor(&mut dec)?,
);
}
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"memberCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_member_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_member_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"memberLimit" => match value {
crate::cbor::Value::Unsigned(n) => {
field_member_limit = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_member_limit = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"requestedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_requested_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(GroupDefsJoinRequestConvoView {
name: field_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'name'".into())
})?,
owner: field_owner.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'owner'".into())
})?,
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
member_count: field_member_count.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'memberCount'".into())
})?,
member_limit: field_member_limit.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'memberLimit'".into())
})?,
requested_at: field_requested_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'requestedAt'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GroupDefsJoinRequestView {
pub convo_id: String,
pub requested_at: crate::syntax::Datetime,
pub requested_by: crate::api::chat::bsky::ActorDefsProfileViewBasic,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl GroupDefsJoinRequestView {
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("convoId")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.convo_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("requestedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.requested_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("requestedBy")?;
self.requested_by.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.convo_id)?;
pairs.push(("convoId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.requested_at.as_str())?;
pairs.push(("requestedAt", vbuf));
}
{
let mut vbuf = Vec::new();
self.requested_by.encode_cbor(&mut vbuf)?;
pairs.push(("requestedBy", 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_convo_id: Option<String> = None;
let mut field_requested_at: Option<crate::syntax::Datetime> = None;
let mut field_requested_by: Option<crate::api::chat::bsky::ActorDefsProfileViewBasic> =
None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"convoId" => {
if let crate::cbor::Value::Text(s) = value {
field_convo_id = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"requestedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_requested_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()));
}
}
"requestedBy" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_requested_by = Some(
crate::api::chat::bsky::ActorDefsProfileViewBasic::decode_cbor(&mut dec)?,
);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(GroupDefsJoinRequestView {
convo_id: field_convo_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'convoId'".into())
})?,
requested_at: field_requested_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'requestedAt'".into())
})?,
requested_by: field_requested_by.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'requestedBy'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
pub type GroupDefsJoinRule = String;
pub type GroupDefsLinkEnabledStatus = String;