surrealcs_kernel/messages/server/wrapper.rs
1//! The wrapper for the server message to be transferred between client and server.
2//!
3//! # Notes
4//! No unit testing has been assigned to this module as it is a simple wrapper around the server message. There
5//! is no functionality to test.
6use super::interface::ServerMessage;
7use revision::revisioned;
8use serde::{Deserialize, Serialize};
9use std::fmt::Debug;
10
11/// A server message wrapped in meta data around the message so the key value data can be processed and returned by the server.
12///
13/// # Fields
14/// * `client_id`: the client ID for the allocator in the client to route back to the transacrtion actor in the client
15/// * `server_id`: the server ID for the allocator in the server to route back to the transaction actor in the server
16/// * `connection_id`: the connection ID for the connection that the message is being sent over (for logging)
17/// * `transaction_id`: the transaction ID for the transaction that the message is being sent over (for logging)
18/// * `message`: the server message to be sent between the client and the server that contains all data to perform a key value operation.
19/// this will also contain the response from the key value operation
20#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
21#[revisioned(revision = 1)]
22pub struct WrappedServerMessage {
23 pub client_id: usize, // allocator for the client
24 pub server_id: Option<usize>, // allocator for the server
25 pub connection_id: String, // this is for logging TODO => turn to essnetial and get it on the registration
26 pub transaction_id: Option<String>,
27 pub message: ServerMessage,
28}
29
30impl WrappedServerMessage {
31 /// The constructor for the `WrappedServerMessage`.
32 ///
33 /// # Arguments
34 /// * `client_id`: the client ID for the allocator in the client to route back to the transacrtion actor in the client
35 /// * `message`: the server message to be sent between the client and the server that contains all data to perform a key value operation.
36 /// this will also contain the response from the key value operation
37 /// * `connection_id`: the connection ID for the connection that the message is being sent over (for logging)
38 ///
39 /// # Returns
40 /// * `WrappedServerMessage`: the wrapped server message
41 pub fn new(client_id: usize, message: ServerMessage, connection_id: String) -> Self {
42 WrappedServerMessage {
43 client_id,
44 server_id: None,
45 message,
46 connection_id,
47 transaction_id: None,
48 }
49 }
50
51 /// Assigns a server ID to the wrapped server message.
52 ///
53 /// # Arguments
54 /// * `server_id`: the server ID for the allocator in the server to route back to the transaction actor in the server
55 ///
56 /// # Returns
57 /// * `WrappedServerMessage`: the wrapped server message with the server ID assigned to `self.server_id`
58 pub fn server_id(mut self, server_id: usize) -> Self {
59 self.server_id = Some(server_id);
60 self
61 }
62
63 /// Assigns a transaction ID to the wrapped server message.
64 ///
65 /// # Arguments
66 /// * `transaction_id`: the transaction ID for the transaction that the message is being sent over (for logging)
67 ///
68 /// # Returns
69 /// * `WrappedServerMessage`: the wrapped server message with the transaction ID assigned to `self.transaction_id`
70 pub fn transaction_id(mut self, transaction_id: String) -> Self {
71 self.transaction_id = Some(transaction_id);
72 self
73 }
74}