grafos_registry/
endpoint.rs

1//! Service endpoint types.
2//!
3//! [`ServiceEndpoint`] describes how to reach a service instance. Variants
4//! cover common transport patterns; `Queue` and `Store` use opaque byte
5//! locators to avoid hard dependencies on `grafos-mq` and `grafos-store`.
6
7extern crate alloc;
8use alloc::string::String;
9use alloc::vec::Vec;
10
11use serde::{Deserialize, Serialize};
12
13/// A reachable endpoint for a service instance.
14///
15/// Each variant carries enough information for a client to connect. The
16/// `Queue` and `Store` variants use opaque byte locators (with a protocol
17/// tag embedded in the bytes) so that this crate has no compile-time
18/// dependency on `grafos-mq` or `grafos-store`.
19#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
20pub enum ServiceEndpoint {
21    /// RPC arena locator (inline locator bytes from grafos-locator).
22    Rpc {
23        /// Serialized `RpcArenaLocator` bytes.
24        locator: Vec<u8>,
25    },
26    /// Network socket address (IPv4).
27    Net {
28        /// IPv4 address octets.
29        addr: [u8; 4],
30        /// Port number.
31        port: u16,
32    },
33    /// Message queue topic (opaque locator bytes).
34    Queue {
35        /// Opaque topic locator bytes (e.g. `b"topic://events"`).
36        locator: Vec<u8>,
37    },
38    /// Object/block store bucket (opaque locator bytes).
39    Store {
40        /// Opaque bucket locator bytes (e.g. `b"bucket://data"`).
41        locator: Vec<u8>,
42    },
43    /// Custom protocol endpoint.
44    Custom {
45        /// Protocol identifier (e.g. `"grpc"`, `"mqtt"`).
46        protocol: String,
47        /// Opaque endpoint data.
48        data: Vec<u8>,
49    },
50}
51
52impl ServiceEndpoint {
53    /// Create a network endpoint from IPv4 address octets and port.
54    pub fn net(addr: [u8; 4], port: u16) -> Self {
55        ServiceEndpoint::Net { addr, port }
56    }
57
58    /// Create an RPC arena endpoint from serialized locator bytes.
59    pub fn rpc(locator: &[u8]) -> Self {
60        ServiceEndpoint::Rpc {
61            locator: locator.to_vec(),
62        }
63    }
64
65    /// Create a queue endpoint from opaque topic locator bytes.
66    pub fn queue(locator: &[u8]) -> Self {
67        ServiceEndpoint::Queue {
68            locator: locator.to_vec(),
69        }
70    }
71
72    /// Create a store endpoint from opaque bucket locator bytes.
73    pub fn store(locator: &[u8]) -> Self {
74        ServiceEndpoint::Store {
75            locator: locator.to_vec(),
76        }
77    }
78
79    /// Create a custom protocol endpoint.
80    pub fn custom(protocol: &str, data: &[u8]) -> Self {
81        ServiceEndpoint::Custom {
82            protocol: String::from(protocol),
83            data: data.to_vec(),
84        }
85    }
86}