1use std::path::PathBuf;
3
4use bytes::Bytes;
5use nested_enum_utils::enum_conversions;
6use quic_rpc_derive::rpc_requests;
7use serde::{Deserialize, Serialize};
8
9use super::{RpcError, RpcResult, RpcService};
10use crate::{
11 export::ExportProgress,
12 format::collection::Collection,
13 get::db::DownloadProgress,
14 net_protocol::{BatchId, BlobDownloadRequest},
15 provider::{AddProgress, BatchAddPathProgress},
16 rpc::client::blobs::{BlobInfo, BlobStatus, IncompleteBlobInfo, ReadAtLen, WrapOption},
17 store::{
18 BaoBlobSize, ConsistencyCheckProgress, ExportFormat, ExportMode, ImportMode,
19 ValidateProgress,
20 },
21 util::SetTagOption,
22 BlobFormat, Hash, HashAndFormat, Tag,
23};
24
25#[allow(missing_docs)]
26#[derive(strum::Display, Debug, Serialize, Deserialize)]
27#[enum_conversions(super::Request)]
28#[rpc_requests(RpcService)]
29pub enum Request {
30 #[server_streaming(response = RpcResult<ReadAtResponse>)]
31 ReadAt(ReadAtRequest),
32 #[bidi_streaming(update = AddStreamUpdate, response = AddStreamResponse)]
33 AddStream(AddStreamRequest),
34 AddStreamUpdate(AddStreamUpdate),
35 #[server_streaming(response = AddPathResponse)]
36 AddPath(AddPathRequest),
37 #[server_streaming(response = DownloadResponse)]
38 Download(BlobDownloadRequest),
39 #[server_streaming(response = ExportResponse)]
40 Export(ExportRequest),
41 #[server_streaming(response = RpcResult<BlobInfo>)]
42 List(ListRequest),
43 #[server_streaming(response = RpcResult<IncompleteBlobInfo>)]
44 ListIncomplete(ListIncompleteRequest),
45 #[rpc(response = RpcResult<()>)]
46 Delete(DeleteRequest),
47 #[server_streaming(response = ValidateProgress)]
48 Validate(ValidateRequest),
49 #[server_streaming(response = ConsistencyCheckProgress)]
50 Fsck(ConsistencyCheckRequest),
51 #[rpc(response = RpcResult<CreateCollectionResponse>)]
52 CreateCollection(CreateCollectionRequest),
53 #[rpc(response = RpcResult<BlobStatusResponse>)]
54 BlobStatus(BlobStatusRequest),
55
56 #[bidi_streaming(update = BatchUpdate, response = BatchCreateResponse)]
57 BatchCreate(BatchCreateRequest),
58 BatchUpdate(BatchUpdate),
59 #[bidi_streaming(update = BatchAddStreamUpdate, response = BatchAddStreamResponse)]
60 BatchAddStream(BatchAddStreamRequest),
61 BatchAddStreamUpdate(BatchAddStreamUpdate),
62 #[server_streaming(response = BatchAddPathResponse)]
63 BatchAddPath(BatchAddPathRequest),
64 #[rpc(response = RpcResult<()>)]
65 BatchCreateTempTag(BatchCreateTempTagRequest),
66}
67
68#[allow(missing_docs)]
69#[derive(strum::Display, Debug, Serialize, Deserialize)]
70#[enum_conversions(super::Response)]
71pub enum Response {
72 ReadAt(RpcResult<ReadAtResponse>),
73 AddStream(AddStreamResponse),
74 AddPath(AddPathResponse),
75 List(RpcResult<BlobInfo>),
76 ListIncomplete(RpcResult<IncompleteBlobInfo>),
77 Download(DownloadResponse),
78 Fsck(ConsistencyCheckProgress),
79 Export(ExportResponse),
80 Validate(ValidateProgress),
81 CreateCollection(RpcResult<CreateCollectionResponse>),
82 BlobStatus(RpcResult<BlobStatusResponse>),
83 BatchCreate(BatchCreateResponse),
84 BatchAddStream(BatchAddStreamResponse),
85 BatchAddPath(BatchAddPathResponse),
86}
87
88#[derive(Debug, Serialize, Deserialize)]
92pub struct AddPathRequest {
93 pub path: PathBuf,
99 pub in_place: bool,
102 pub tag: SetTagOption,
104 pub wrap: WrapOption,
106}
107
108#[derive(Debug, Serialize, Deserialize, derive_more::Into)]
110pub struct AddPathResponse(pub AddProgress);
111
112#[derive(Debug, Clone, Serialize, Deserialize, derive_more::From, derive_more::Into)]
114pub struct DownloadResponse(pub DownloadProgress);
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct ExportRequest {
119 pub hash: Hash,
121 pub path: PathBuf,
126 pub format: ExportFormat,
129 pub mode: ExportMode,
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize, derive_more::From, derive_more::Into)]
137pub struct ExportResponse(pub ExportProgress);
138
139#[derive(Debug, Serialize, Deserialize)]
141pub struct ConsistencyCheckRequest {
142 pub repair: bool,
144}
145
146#[derive(Debug, Serialize, Deserialize)]
148pub struct ValidateRequest {
149 pub repair: bool,
151}
152
153#[derive(Debug, Serialize, Deserialize)]
155pub struct ListRequest;
156
157#[derive(Debug, Serialize, Deserialize)]
159pub struct ListIncompleteRequest;
160
161#[derive(Serialize, Deserialize, Debug)]
163pub struct ReadAtRequest {
164 pub hash: Hash,
166 pub offset: u64,
168 pub len: ReadAtLen,
170}
171
172#[derive(Serialize, Deserialize, Debug)]
174pub enum ReadAtResponse {
175 Entry {
177 size: BaoBlobSize,
179 is_complete: bool,
181 },
182 Data {
184 chunk: Bytes,
186 },
187}
188
189#[derive(Serialize, Deserialize, Debug)]
191pub struct AddStreamRequest {
192 pub tag: SetTagOption,
194}
195
196#[derive(Serialize, Deserialize, Debug)]
198pub enum AddStreamUpdate {
199 Chunk(Bytes),
201 Abort,
203}
204
205#[derive(Debug, Serialize, Deserialize, derive_more::Into)]
207pub struct AddStreamResponse(pub AddProgress);
208
209#[derive(Debug, Serialize, Deserialize)]
211pub struct DeleteRequest {
212 pub hash: Hash,
214}
215
216#[derive(Debug, Serialize, Deserialize)]
218pub struct CreateCollectionRequest {
219 pub collection: Collection,
221 pub tag: SetTagOption,
223 pub tags_to_delete: Vec<Tag>,
225}
226
227#[derive(Debug, Serialize, Deserialize)]
229pub struct CreateCollectionResponse {
230 pub hash: Hash,
232 pub tag: Tag,
234}
235
236#[derive(Debug, Serialize, Deserialize)]
238pub struct BlobStatusRequest {
239 pub hash: Hash,
241}
242
243#[derive(Debug, Serialize, Deserialize, derive_more::From, derive_more::Into)]
245pub struct BlobStatusResponse(pub BlobStatus);
246
247#[derive(Debug, Serialize, Deserialize)]
249pub struct BatchCreateRequest;
250
251#[derive(Debug, Serialize, Deserialize)]
253pub enum BatchUpdate {
254 Drop(HashAndFormat),
256 Ping,
258}
259
260#[derive(Debug, Serialize, Deserialize)]
262pub enum BatchCreateResponse {
263 Id(BatchId),
265}
266
267#[derive(Debug, Serialize, Deserialize)]
269pub struct BatchCreateTempTagRequest {
270 pub content: HashAndFormat,
272 pub batch: BatchId,
274}
275
276#[derive(Serialize, Deserialize, Debug)]
278pub struct BatchAddStreamRequest {
279 pub format: BlobFormat,
281 pub batch: BatchId,
283}
284
285#[derive(Serialize, Deserialize, Debug)]
287pub enum BatchAddStreamUpdate {
288 Chunk(Bytes),
290 Abort,
292}
293
294#[allow(missing_docs)]
296#[derive(Debug, Serialize, Deserialize)]
297pub enum BatchAddStreamResponse {
298 Abort(RpcError),
299 OutboardProgress { offset: u64 },
300 Result { hash: Hash },
301}
302
303#[derive(Serialize, Deserialize, Debug)]
305pub struct BatchAddPathRequest {
306 pub path: PathBuf,
308 pub import_mode: ImportMode,
310 pub format: BlobFormat,
312 pub batch: BatchId,
314}
315
316#[derive(Serialize, Deserialize, Debug)]
318pub struct BatchAddPathResponse(pub BatchAddPathProgress);