jacquard_api/com_atproto/sync/
get_blob.rs1#[allow(unused_imports)]
9use core::marker::PhantomData;
10use jacquard_common::CowStr;
11use jacquard_common::deps::bytes::Bytes;
12use jacquard_common::types::string::{Did, Cid};
13use jacquard_derive::{IntoStatic, open_union};
14use serde::{Serialize, Deserialize};
15
16#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
17#[serde(rename_all = "camelCase")]
18pub struct GetBlob<'a> {
19 #[serde(borrow)]
20 pub cid: Cid<'a>,
21 #[serde(borrow)]
22 pub did: Did<'a>,
23}
24
25
26#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
27#[serde(rename_all = "camelCase")]
28pub struct GetBlobOutput {
29 pub body: Bytes,
30}
31
32
33#[open_union]
34#[derive(
35 Serialize,
36 Deserialize,
37 Debug,
38 Clone,
39 PartialEq,
40 Eq,
41 thiserror::Error,
42 miette::Diagnostic,
43 IntoStatic
44)]
45
46#[serde(tag = "error", content = "message")]
47#[serde(bound(deserialize = "'de: 'a"))]
48pub enum GetBlobError<'a> {
49 #[serde(rename = "BlobNotFound")]
50 BlobNotFound(Option<CowStr<'a>>),
51 #[serde(rename = "RepoNotFound")]
52 RepoNotFound(Option<CowStr<'a>>),
53 #[serde(rename = "RepoTakendown")]
54 RepoTakendown(Option<CowStr<'a>>),
55 #[serde(rename = "RepoSuspended")]
56 RepoSuspended(Option<CowStr<'a>>),
57 #[serde(rename = "RepoDeactivated")]
58 RepoDeactivated(Option<CowStr<'a>>),
59}
60
61impl core::fmt::Display for GetBlobError<'_> {
62 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
63 match self {
64 Self::BlobNotFound(msg) => {
65 write!(f, "BlobNotFound")?;
66 if let Some(msg) = msg {
67 write!(f, ": {}", msg)?;
68 }
69 Ok(())
70 }
71 Self::RepoNotFound(msg) => {
72 write!(f, "RepoNotFound")?;
73 if let Some(msg) = msg {
74 write!(f, ": {}", msg)?;
75 }
76 Ok(())
77 }
78 Self::RepoTakendown(msg) => {
79 write!(f, "RepoTakendown")?;
80 if let Some(msg) = msg {
81 write!(f, ": {}", msg)?;
82 }
83 Ok(())
84 }
85 Self::RepoSuspended(msg) => {
86 write!(f, "RepoSuspended")?;
87 if let Some(msg) = msg {
88 write!(f, ": {}", msg)?;
89 }
90 Ok(())
91 }
92 Self::RepoDeactivated(msg) => {
93 write!(f, "RepoDeactivated")?;
94 if let Some(msg) = msg {
95 write!(f, ": {}", msg)?;
96 }
97 Ok(())
98 }
99 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
100 }
101 }
102}
103
104pub struct GetBlobResponse;
106impl jacquard_common::xrpc::XrpcResp for GetBlobResponse {
107 const NSID: &'static str = "com.atproto.sync.getBlob";
108 const ENCODING: &'static str = "*/*";
109 type Output<'de> = GetBlobOutput;
110 type Err<'de> = GetBlobError<'de>;
111 fn encode_output(
112 output: &Self::Output<'_>,
113 ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
114 Ok(output.body.to_vec())
115 }
116 fn decode_output<'de>(
117 body: &'de [u8],
118 ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
119 where
120 Self::Output<'de>: serde::Deserialize<'de>,
121 {
122 Ok(GetBlobOutput {
123 body: jacquard_common::deps::bytes::Bytes::copy_from_slice(body),
124 })
125 }
126}
127
128impl<'a> jacquard_common::xrpc::XrpcRequest for GetBlob<'a> {
129 const NSID: &'static str = "com.atproto.sync.getBlob";
130 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
131 type Response = GetBlobResponse;
132}
133
134pub struct GetBlobRequest;
136impl jacquard_common::xrpc::XrpcEndpoint for GetBlobRequest {
137 const PATH: &'static str = "/xrpc/com.atproto.sync.getBlob";
138 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
139 type Request<'de> = GetBlob<'de>;
140 type Response = GetBlobResponse;
141}
142
143pub mod get_blob_state {
144
145 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
146 #[allow(unused)]
147 use ::core::marker::PhantomData;
148 mod sealed {
149 pub trait Sealed {}
150 }
151 pub trait State: sealed::Sealed {
153 type Cid;
154 type Did;
155 }
156 pub struct Empty(());
158 impl sealed::Sealed for Empty {}
159 impl State for Empty {
160 type Cid = Unset;
161 type Did = Unset;
162 }
163 pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
165 impl<S: State> sealed::Sealed for SetCid<S> {}
166 impl<S: State> State for SetCid<S> {
167 type Cid = Set<members::cid>;
168 type Did = S::Did;
169 }
170 pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
172 impl<S: State> sealed::Sealed for SetDid<S> {}
173 impl<S: State> State for SetDid<S> {
174 type Cid = S::Cid;
175 type Did = Set<members::did>;
176 }
177 #[allow(non_camel_case_types)]
179 pub mod members {
180 pub struct cid(());
182 pub struct did(());
184 }
185}
186
187pub struct GetBlobBuilder<'a, S: get_blob_state::State> {
189 _state: PhantomData<fn() -> S>,
190 _fields: (Option<Cid<'a>>, Option<Did<'a>>),
191 _lifetime: PhantomData<&'a ()>,
192}
193
194impl<'a> GetBlob<'a> {
195 pub fn new() -> GetBlobBuilder<'a, get_blob_state::Empty> {
197 GetBlobBuilder::new()
198 }
199}
200
201impl<'a> GetBlobBuilder<'a, get_blob_state::Empty> {
202 pub fn new() -> Self {
204 GetBlobBuilder {
205 _state: PhantomData,
206 _fields: (None, None),
207 _lifetime: PhantomData,
208 }
209 }
210}
211
212impl<'a, S> GetBlobBuilder<'a, S>
213where
214 S: get_blob_state::State,
215 S::Cid: get_blob_state::IsUnset,
216{
217 pub fn cid(
219 mut self,
220 value: impl Into<Cid<'a>>,
221 ) -> GetBlobBuilder<'a, get_blob_state::SetCid<S>> {
222 self._fields.0 = Option::Some(value.into());
223 GetBlobBuilder {
224 _state: PhantomData,
225 _fields: self._fields,
226 _lifetime: PhantomData,
227 }
228 }
229}
230
231impl<'a, S> GetBlobBuilder<'a, S>
232where
233 S: get_blob_state::State,
234 S::Did: get_blob_state::IsUnset,
235{
236 pub fn did(
238 mut self,
239 value: impl Into<Did<'a>>,
240 ) -> GetBlobBuilder<'a, get_blob_state::SetDid<S>> {
241 self._fields.1 = Option::Some(value.into());
242 GetBlobBuilder {
243 _state: PhantomData,
244 _fields: self._fields,
245 _lifetime: PhantomData,
246 }
247 }
248}
249
250impl<'a, S> GetBlobBuilder<'a, S>
251where
252 S: get_blob_state::State,
253 S::Cid: get_blob_state::IsSet,
254 S::Did: get_blob_state::IsSet,
255{
256 pub fn build(self) -> GetBlob<'a> {
258 GetBlob {
259 cid: self._fields.0.unwrap(),
260 did: self._fields.1.unwrap(),
261 }
262 }
263}