Skip to main content

doublecrypt_core/
proto.rs

1//! Protobuf types for the doublecrypt block-store protocol.
2//!
3//! These are hand-written prost structs matching `proto/blockstore.proto`.
4//! They are wire-compatible with the length-prefixed protobuf protocol used
5//! by `doublecrypt-server` and can be imported directly by both the client
6//! ([`NetworkBlockStore`](crate::network_store::NetworkBlockStore)) and the
7//! server, avoiding any need for `protoc` or `prost-build`.
8//!
9//! # Usage from `doublecrypt-server`
10//!
11//! ```toml
12//! [dependencies]
13//! doublecrypt-core = { version = "0.1", default-features = false }
14//! ```
15//!
16//! ```rust,ignore
17//! use doublecrypt_core::proto::{Request, Response, request, response};
18//! ```
19
20// ── Requests ────────────────────────────────────────────────
21
22#[derive(Clone, PartialEq, ::prost::Message)]
23pub struct Request {
24    #[prost(uint64, tag = "1")]
25    pub request_id: u64,
26    #[prost(oneof = "request::Command", tags = "2, 3, 4, 5")]
27    pub command: ::core::option::Option<request::Command>,
28}
29
30pub mod request {
31    #[derive(Clone, PartialEq, ::prost::Oneof)]
32    pub enum Command {
33        #[prost(message, tag = "2")]
34        ReadBlock(super::ReadBlockRequest),
35        #[prost(message, tag = "3")]
36        WriteBlock(super::WriteBlockRequest),
37        #[prost(message, tag = "4")]
38        Sync(super::SyncRequest),
39        #[prost(message, tag = "5")]
40        GetInfo(super::GetInfoRequest),
41    }
42}
43
44#[derive(Clone, PartialEq, ::prost::Message)]
45pub struct ReadBlockRequest {
46    #[prost(uint64, tag = "1")]
47    pub block_id: u64,
48}
49
50#[derive(Clone, PartialEq, ::prost::Message)]
51pub struct WriteBlockRequest {
52    #[prost(uint64, tag = "1")]
53    pub block_id: u64,
54    #[prost(bytes = "vec", tag = "2")]
55    pub data: Vec<u8>,
56}
57
58#[derive(Clone, PartialEq, ::prost::Message)]
59pub struct SyncRequest {}
60
61#[derive(Clone, PartialEq, ::prost::Message)]
62pub struct GetInfoRequest {}
63
64// ── Responses ───────────────────────────────────────────────
65
66#[derive(Clone, PartialEq, ::prost::Message)]
67pub struct Response {
68    #[prost(uint64, tag = "1")]
69    pub request_id: u64,
70    #[prost(oneof = "response::Result", tags = "2, 3, 4, 5, 6")]
71    pub result: ::core::option::Option<response::Result>,
72}
73
74pub mod response {
75    #[derive(Clone, PartialEq, ::prost::Oneof)]
76    pub enum Result {
77        #[prost(message, tag = "2")]
78        ReadBlock(super::ReadBlockResponse),
79        #[prost(message, tag = "3")]
80        WriteBlock(super::WriteBlockResponse),
81        #[prost(message, tag = "4")]
82        Sync(super::SyncResponse),
83        #[prost(message, tag = "5")]
84        GetInfo(super::GetInfoResponse),
85        #[prost(message, tag = "6")]
86        Error(super::ErrorResponse),
87    }
88}
89
90#[derive(Clone, PartialEq, ::prost::Message)]
91pub struct ReadBlockResponse {
92    #[prost(bytes = "vec", tag = "1")]
93    pub data: Vec<u8>,
94}
95
96#[derive(Clone, PartialEq, ::prost::Message)]
97pub struct WriteBlockResponse {}
98
99#[derive(Clone, PartialEq, ::prost::Message)]
100pub struct SyncResponse {}
101
102#[derive(Clone, PartialEq, ::prost::Message)]
103pub struct GetInfoResponse {
104    #[prost(uint32, tag = "1")]
105    pub block_size: u32,
106    #[prost(uint64, tag = "2")]
107    pub total_blocks: u64,
108}
109
110#[derive(Clone, PartialEq, ::prost::Message)]
111pub struct ErrorResponse {
112    #[prost(int32, tag = "1")]
113    pub code: i32,
114    #[prost(string, tag = "2")]
115    pub message: String,
116}