summaryrefslogtreecommitdiff
path: root/crates/arti-rpc-client-core/src/msgs.rs
blob: 239b47005a7b23243861114778698a184a503198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Support for decoding and encoding RPC messages.
//!
//! Every message is either a Request (sent to Arti)
//! or a Response (received from Arti).

pub(crate) mod request;
pub(crate) mod response;

use serde::{Deserialize, Serialize};

/// An identifier for a request made to the Arti RPC system.
///
/// Every request must have an ID, chosen by the application that's sending it.
/// If these IDs are not distinct, the application can get confused about
/// which reply corresponds to which request.
///
/// The [`RpcConn`](crate::conn::RpcConn) type can generate unique IDs
/// for outbound requests as needed.
#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, derive_more::From)]
#[serde(untagged)]
#[non_exhaustive]
pub enum AnyRequestId {
    /// A numeric request ID.
    ///
    /// Note that values larger than `±2^53-1` may not work with all
    /// JSON implementations.
    Number(i64),
    /// A string request ID.
    String(String),
}

/// An identifier for some object visible to the Arti RPC system.
///
/// A single object may have multiple underlying identifiers.
/// These identifiers should always be treated as opaque
/// from the application's perspective.
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    Hash,
    Eq,
    PartialEq,
    derive_more::AsRef,
    derive_more::From,
    derive_more::Into,
)]
#[serde(transparent)]
pub struct ObjectId(String);