jacquard_api/com_atproto/sync/
get_blocks.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: com.atproto.sync.getBlocks
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[derive(
9    serde::Serialize,
10    serde::Deserialize,
11    Debug,
12    Clone,
13    PartialEq,
14    Eq,
15    bon::Builder,
16    jacquard_derive::IntoStatic
17)]
18#[builder(start_fn = new)]
19#[serde(rename_all = "camelCase")]
20pub struct GetBlocks<'a> {
21    #[serde(borrow)]
22    pub cids: Vec<jacquard_common::types::string::Cid<'a>>,
23    #[serde(borrow)]
24    pub did: jacquard_common::types::string::Did<'a>,
25}
26
27#[derive(
28    serde::Serialize,
29    serde::Deserialize,
30    Debug,
31    Clone,
32    PartialEq,
33    Eq,
34    jacquard_derive::IntoStatic
35)]
36#[serde(rename_all = "camelCase")]
37pub struct GetBlocksOutput {
38    pub body: bytes::Bytes,
39}
40
41#[jacquard_derive::open_union]
42#[derive(
43    serde::Serialize,
44    serde::Deserialize,
45    Debug,
46    Clone,
47    PartialEq,
48    Eq,
49    thiserror::Error,
50    miette::Diagnostic,
51    jacquard_derive::IntoStatic
52)]
53#[serde(tag = "error", content = "message")]
54#[serde(bound(deserialize = "'de: 'a"))]
55pub enum GetBlocksError<'a> {
56    #[serde(rename = "BlockNotFound")]
57    BlockNotFound(std::option::Option<String>),
58    #[serde(rename = "RepoNotFound")]
59    RepoNotFound(std::option::Option<String>),
60    #[serde(rename = "RepoTakendown")]
61    RepoTakendown(std::option::Option<String>),
62    #[serde(rename = "RepoSuspended")]
63    RepoSuspended(std::option::Option<String>),
64    #[serde(rename = "RepoDeactivated")]
65    RepoDeactivated(std::option::Option<String>),
66}
67
68impl std::fmt::Display for GetBlocksError<'_> {
69    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70        match self {
71            Self::BlockNotFound(msg) => {
72                write!(f, "BlockNotFound")?;
73                if let Some(msg) = msg {
74                    write!(f, ": {}", msg)?;
75                }
76                Ok(())
77            }
78            Self::RepoNotFound(msg) => {
79                write!(f, "RepoNotFound")?;
80                if let Some(msg) = msg {
81                    write!(f, ": {}", msg)?;
82                }
83                Ok(())
84            }
85            Self::RepoTakendown(msg) => {
86                write!(f, "RepoTakendown")?;
87                if let Some(msg) = msg {
88                    write!(f, ": {}", msg)?;
89                }
90                Ok(())
91            }
92            Self::RepoSuspended(msg) => {
93                write!(f, "RepoSuspended")?;
94                if let Some(msg) = msg {
95                    write!(f, ": {}", msg)?;
96                }
97                Ok(())
98            }
99            Self::RepoDeactivated(msg) => {
100                write!(f, "RepoDeactivated")?;
101                if let Some(msg) = msg {
102                    write!(f, ": {}", msg)?;
103                }
104                Ok(())
105            }
106            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
107        }
108    }
109}
110
111/// Response type for
112///com.atproto.sync.getBlocks
113pub struct GetBlocksResponse;
114impl jacquard_common::xrpc::XrpcResp for GetBlocksResponse {
115    const NSID: &'static str = "com.atproto.sync.getBlocks";
116    const ENCODING: &'static str = "application/vnd.ipld.car";
117    type Output<'de> = GetBlocksOutput;
118    type Err<'de> = GetBlocksError<'de>;
119    fn encode_output(
120        output: &Self::Output<'_>,
121    ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
122        Ok(output.body.to_vec())
123    }
124    fn decode_output<'de>(
125        body: &'de [u8],
126    ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
127    where
128        Self::Output<'de>: serde::Deserialize<'de>,
129    {
130        Ok(GetBlocksOutput {
131            body: bytes::Bytes::copy_from_slice(body),
132        })
133    }
134}
135
136impl<'a> jacquard_common::xrpc::XrpcRequest for GetBlocks<'a> {
137    const NSID: &'static str = "com.atproto.sync.getBlocks";
138    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
139    type Response = GetBlocksResponse;
140}
141
142/// Endpoint type for
143///com.atproto.sync.getBlocks
144pub struct GetBlocksRequest;
145impl jacquard_common::xrpc::XrpcEndpoint for GetBlocksRequest {
146    const PATH: &'static str = "/xrpc/com.atproto.sync.getBlocks";
147    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
148    type Request<'de> = GetBlocks<'de>;
149    type Response = GetBlocksResponse;
150}