#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncSubscribeReposAccount {
pub active: bool,
pub did: crate::syntax::Did,
pub seq: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
pub time: crate::syntax::Datetime,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl SyncSubscribeReposAccount {
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.status.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())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("seq")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.seq)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("time")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.time.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("active")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.active)?;
if self.status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("status")?;
if let Some(ref val) = self.status {
crate::cbor::Encoder::new(&mut *buf).encode_text(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.did.as_str())?;
pairs.push(("did", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.seq)?;
pairs.push(("seq", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.time.as_str())?;
pairs.push(("time", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.active)?;
pairs.push(("active", vbuf));
}
if self.status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.status {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("status", 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_seq: Option<i64> = None;
let mut field_time: Option<crate::syntax::Datetime> = None;
let mut field_active: Option<bool> = None;
let mut field_status: Option<String> = 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()));
}
}
"seq" => match value {
crate::cbor::Value::Unsigned(n) => {
field_seq = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_seq = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"time" => {
if let crate::cbor::Value::Text(s) = value {
field_time = 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()));
}
}
"active" => {
if let crate::cbor::Value::Bool(b) = value {
field_active = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".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()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(SyncSubscribeReposAccount {
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
seq: field_seq.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'seq'".into())
})?,
time: field_time.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'time'".into())
})?,
active: field_active.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'active'".into())
})?,
status: field_status,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncSubscribeReposCommit {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub blobs: Vec<crate::api::CidLink>,
pub blocks: String,
pub commit: crate::api::CidLink,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub ops: Vec<SyncSubscribeReposRepoOp>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub prev_data: Option<crate::api::CidLink>,
pub rebase: bool,
pub repo: crate::syntax::Did,
pub rev: crate::syntax::Tid,
pub seq: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub since: Option<crate::syntax::Tid>,
pub time: crate::syntax::Datetime,
pub too_big: bool,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl SyncSubscribeReposCommit {
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 = 10u64;
if self.since.is_some() {
count += 1;
}
if self.prev_data.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("ops")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.ops.len() as u64)?;
for item in &self.ops {
item.encode_cbor(buf)?;
}
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
{
let __s = self.rev.to_string();
crate::cbor::Encoder::new(&mut *buf).encode_text(&__s)?;
}
crate::cbor::Encoder::new(&mut *buf).encode_text("seq")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.seq)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("repo")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.repo.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("time")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.time.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("blobs")?;
crate::cbor::Encoder::new(&mut *buf).encode_array_header(self.blobs.len() as u64)?;
for item in &self.blobs {
let cid = item.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut *buf).encode_cid(&cid)?;
}
if self.since.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("since")?;
if let Some(ref val) = self.since {
{
let __s = val.to_string();
crate::cbor::Encoder::new(&mut *buf).encode_text(&__s)?;
}
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("blocks")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.blocks)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("commit")?;
let cid =
self.commit.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut *buf).encode_cid(&cid)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rebase")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.rebase)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("tooBig")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.too_big)?;
if self.prev_data.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("prevData")?;
if let Some(ref val) = self.prev_data {
let cid = val.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut *buf).encode_cid(&cid)?;
}
}
} 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.ops.len() as u64)?;
for item in &self.ops {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("ops", vbuf));
}
{
let mut vbuf = Vec::new();
{
let __s = self.rev.to_string();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&__s)?;
}
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.seq)?;
pairs.push(("seq", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.repo.as_str())?;
pairs.push(("repo", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.time.as_str())?;
pairs.push(("time", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_array_header(self.blobs.len() as u64)?;
for item in &self.blobs {
let cid = item.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut vbuf).encode_cid(&cid)?;
}
pairs.push(("blobs", vbuf));
}
if self.since.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.since {
{
let __s = val.to_string();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&__s)?;
}
}
pairs.push(("since", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.blocks)?;
pairs.push(("blocks", vbuf));
}
{
let mut vbuf = Vec::new();
let cid = self.commit.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut vbuf).encode_cid(&cid)?;
pairs.push(("commit", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.rebase)?;
pairs.push(("rebase", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.too_big)?;
pairs.push(("tooBig", vbuf));
}
if self.prev_data.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.prev_data {
let cid = val.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut vbuf).encode_cid(&cid)?;
}
pairs.push(("prevData", 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_ops: Vec<SyncSubscribeReposRepoOp> = Vec::new();
let mut field_rev: Option<crate::syntax::Tid> = None;
let mut field_seq: Option<i64> = None;
let mut field_repo: Option<crate::syntax::Did> = None;
let mut field_time: Option<crate::syntax::Datetime> = None;
let mut field_blobs: Vec<crate::api::CidLink> = Vec::new();
let mut field_since: Option<crate::syntax::Tid> = None;
let mut field_blocks: Option<String> = None;
let mut field_commit: Option<crate::api::CidLink> = None;
let mut field_rebase: Option<bool> = None;
let mut field_too_big: Option<bool> = None;
let mut field_prev_data: Option<crate::api::CidLink> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"ops" => {
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_ops.push(SyncSubscribeReposRepoOp::decode_cbor(&mut dec)?);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(
crate::syntax::Tid::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"seq" => match value {
crate::cbor::Value::Unsigned(n) => {
field_seq = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_seq = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"repo" => {
if let crate::cbor::Value::Text(s) = value {
field_repo = 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()));
}
}
"time" => {
if let crate::cbor::Value::Text(s) = value {
field_time = 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()));
}
}
"blobs" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
if let crate::cbor::Value::Cid(c) = item {
field_blobs.push(crate::api::CidLink {
link: c.to_string(),
});
} else {
return Err(crate::cbor::CborError::InvalidCbor(
"expected CID in array".into(),
));
}
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"since" => {
if let crate::cbor::Value::Text(s) = value {
field_since = Some(
crate::syntax::Tid::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"blocks" => {
if let crate::cbor::Value::Text(s) = value {
field_blocks = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor(
"expected text for bytes field".into(),
));
}
}
"commit" => {
if let crate::cbor::Value::Cid(c) = value {
field_commit = Some(crate::api::CidLink {
link: c.to_string(),
});
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected CID".into()));
}
}
"rebase" => {
if let crate::cbor::Value::Bool(b) = value {
field_rebase = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"tooBig" => {
if let crate::cbor::Value::Bool(b) = value {
field_too_big = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"prevData" => {
if let crate::cbor::Value::Cid(c) = value {
field_prev_data = Some(crate::api::CidLink {
link: c.to_string(),
});
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected CID".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(SyncSubscribeReposCommit {
ops: field_ops,
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
seq: field_seq.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'seq'".into())
})?,
repo: field_repo.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'repo'".into())
})?,
time: field_time.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'time'".into())
})?,
blobs: field_blobs,
since: field_since,
blocks: field_blocks.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'blocks'".into())
})?,
commit: field_commit.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'commit'".into())
})?,
rebase: field_rebase.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rebase'".into())
})?,
too_big: field_too_big.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'tooBig'".into())
})?,
prev_data: field_prev_data,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncSubscribeReposIdentity {
pub did: crate::syntax::Did,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub handle: Option<crate::syntax::Handle>,
pub seq: i64,
pub time: crate::syntax::Datetime,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl SyncSubscribeReposIdentity {
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 = 3u64;
if self.handle.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())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("seq")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.seq)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("time")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.time.as_str())?;
if self.handle.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("handle")?;
if let Some(ref val) = self.handle {
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));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.seq)?;
pairs.push(("seq", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.time.as_str())?;
pairs.push(("time", vbuf));
}
if self.handle.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.handle {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("handle", 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_seq: Option<i64> = None;
let mut field_time: Option<crate::syntax::Datetime> = None;
let mut field_handle: Option<crate::syntax::Handle> = 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()));
}
}
"seq" => match value {
crate::cbor::Value::Unsigned(n) => {
field_seq = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_seq = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"time" => {
if let crate::cbor::Value::Text(s) = value {
field_time = 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()));
}
}
"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()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(SyncSubscribeReposIdentity {
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
seq: field_seq.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'seq'".into())
})?,
time: field_time.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'time'".into())
})?,
handle: field_handle,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncSubscribeReposInfo {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
pub name: String,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl SyncSubscribeReposInfo {
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.message.is_some() {
count += 1;
}
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)?;
if self.message.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("message")?;
if let Some(ref val) = self.message {
crate::cbor::Encoder::new(&mut *buf).encode_text(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.name)?;
pairs.push(("name", vbuf));
}
if self.message.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.message {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("message", 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_message: Option<String> = 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()));
}
}
"message" => {
if let crate::cbor::Value::Text(s) = value {
field_message = 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(SyncSubscribeReposInfo {
name: field_name.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'name'".into())
})?,
message: field_message,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncSubscribeReposRepoOp {
pub action: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cid: Option<crate::api::CidLink>,
pub path: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub prev: Option<crate::api::CidLink>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl SyncSubscribeReposRepoOp {
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.cid.is_some() {
count += 1;
}
if self.prev.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 {
let cid = val.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut *buf).encode_cid(&cid)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("path")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.path)?;
if self.prev.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("prev")?;
if let Some(ref val) = self.prev {
let cid = val.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut *buf).encode_cid(&cid)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("action")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.action)?;
} 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 {
let cid = val.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut vbuf).encode_cid(&cid)?;
}
pairs.push(("cid", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.path)?;
pairs.push(("path", vbuf));
}
if self.prev.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.prev {
let cid = val.link.parse::<crate::cbor::Cid>().map_err(|e| {
crate::cbor::CborError::InvalidCbor(format!("invalid CID: {e}"))
})?;
crate::cbor::Encoder::new(&mut vbuf).encode_cid(&cid)?;
}
pairs.push(("prev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.action)?;
pairs.push(("action", 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<crate::api::CidLink> = None;
let mut field_path: Option<String> = None;
let mut field_prev: Option<crate::api::CidLink> = None;
let mut field_action: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"cid" => {
if let crate::cbor::Value::Cid(c) = value {
field_cid = Some(crate::api::CidLink {
link: c.to_string(),
});
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected CID".into()));
}
}
"path" => {
if let crate::cbor::Value::Text(s) = value {
field_path = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"prev" => {
if let crate::cbor::Value::Cid(c) = value {
field_prev = Some(crate::api::CidLink {
link: c.to_string(),
});
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected CID".into()));
}
}
"action" => {
if let crate::cbor::Value::Text(s) = value {
field_action = 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(SyncSubscribeReposRepoOp {
cid: field_cid,
path: field_path.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'path'".into())
})?,
prev: field_prev,
action: field_action.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'action'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncSubscribeReposSync {
pub blocks: String,
pub did: crate::syntax::Did,
pub rev: String,
pub seq: i64,
pub time: crate::syntax::Datetime,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl SyncSubscribeReposSync {
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("did")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.did.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("rev")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.rev)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("seq")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.seq)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("time")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.time.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("blocks")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.blocks)?;
} 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));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.rev)?;
pairs.push(("rev", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.seq)?;
pairs.push(("seq", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.time.as_str())?;
pairs.push(("time", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.blocks)?;
pairs.push(("blocks", 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_rev: Option<String> = None;
let mut field_seq: Option<i64> = None;
let mut field_time: Option<crate::syntax::Datetime> = None;
let mut field_blocks: Option<String> = 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()));
}
}
"rev" => {
if let crate::cbor::Value::Text(s) = value {
field_rev = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"seq" => match value {
crate::cbor::Value::Unsigned(n) => {
field_seq = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_seq = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"time" => {
if let crate::cbor::Value::Text(s) = value {
field_time = 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()));
}
}
"blocks" => {
if let crate::cbor::Value::Text(s) = value {
field_blocks = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor(
"expected text for bytes field".into(),
));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(SyncSubscribeReposSync {
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
rev: field_rev.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'rev'".into())
})?,
seq: field_seq.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'seq'".into())
})?,
time: field_time.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'time'".into())
})?,
blocks: field_blocks.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'blocks'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}