solidb_client/protocol/
response.rs1use super::error::DriverError;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6#[serde(tag = "status", rename_all = "snake_case")]
7pub enum Response {
8 Ok {
9 #[serde(skip_serializing_if = "Option::is_none")]
10 data: Option<Value>,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 count: Option<usize>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 tx_id: Option<String>,
15 },
16 Error {
17 error: DriverError,
18 },
19 Pong {
20 timestamp: i64,
21 },
22 Batch {
23 responses: Vec<Response>,
24 },
25}
26
27impl Response {
28 pub fn ok(data: Value) -> Self {
29 Response::Ok {
30 data: Some(data),
31 count: None,
32 tx_id: None,
33 }
34 }
35
36 pub fn ok_count(count: usize) -> Self {
37 Response::Ok {
38 data: None,
39 count: Some(count),
40 tx_id: None,
41 }
42 }
43
44 pub fn ok_empty() -> Self {
45 Response::Ok {
46 data: None,
47 count: None,
48 tx_id: None,
49 }
50 }
51
52 pub fn ok_tx(tx_id: String) -> Self {
53 Response::Ok {
54 data: None,
55 count: None,
56 tx_id: Some(tx_id),
57 }
58 }
59
60 pub fn error(err: DriverError) -> Self {
61 Response::Error { error: err }
62 }
63
64 pub fn pong() -> Self {
65 Response::Pong {
66 timestamp: chrono::Utc::now().timestamp_millis(),
67 }
68 }
69}