Skip to main content

reddb_grpc_proto/
lib.rs

1//! Generated gRPC protobuf types for RedDB.
2//!
3//! This crate exists so `reddb-server` and `reddb-client` can both
4//! reference the same tonic-generated client + server stubs without
5//! one depending on the other (which would create a cycle).
6//! The `.proto` source lives in this crate's `proto/` directory.
7//!
8//! Re-exports the entire `reddb.v1` module produced by
9//! `tonic_prost_build` at compile time.
10
11#![allow(clippy::all)]
12
13tonic::include_proto!("reddb.v1");
14
15// Re-export the canonical Topology Rust type from reddb-wire so
16// gRPC consumers reach for one place when they need the schema.
17// The on-wire bytes carried in `TopologyReply.topology_bytes` are
18// produced by `reddb_wire::topology::encode_topology` — the same
19// bytes the RedWire HelloAck embeds base64-wrapped. (Issue #166)
20pub use reddb_wire::topology as topology_schema;
21pub use reddb_wire::{
22    decode_topology, encode_topology, Endpoint as TopologyEndpoint, ReplicaInfo as TopologyReplica,
23    Topology, TopologyError, MAX_KNOWN_TOPOLOGY_VERSION, TOPOLOGY_HEADER_SIZE,
24    TOPOLOGY_WIRE_VERSION_V1,
25};
26
27#[cfg(test)]
28mod topology_tests {
29    use super::*;
30
31    fn fixture() -> Topology {
32        Topology {
33            epoch: 7,
34            primary: TopologyEndpoint {
35                addr: "primary:5050".into(),
36                region: "eu-west-1".into(),
37            },
38            replicas: vec![TopologyReplica {
39                addr: "r1:5050".into(),
40                region: "eu-west-1".into(),
41                healthy: true,
42                lag_ms: 4,
43                last_applied_lsn: 99,
44            }],
45        }
46    }
47
48    #[test]
49    fn topology_round_trip_through_grpc_message() {
50        // The acceptance criterion (#166 §5): encode a fixture, ship
51        // it as `TopologyReply.topology_bytes`, decode at the other
52        // end, assert byte-for-byte equivalence on the inner
53        // schema.
54        let t = fixture();
55        let canonical = encode_topology(&t);
56        let reply = TopologyReply {
57            topology_bytes: canonical.clone(),
58        };
59        // Same bytes both transports carry.
60        assert_eq!(reply.topology_bytes, canonical);
61        let decoded = decode_topology(&reply.topology_bytes)
62            .expect("decode")
63            .expect("v1 known");
64        assert_eq!(decoded, t);
65    }
66
67    #[test]
68    fn topology_unknown_version_drops_cleanly() {
69        let t = fixture();
70        let mut bytes = encode_topology(&t);
71        bytes[0] = 0x80;
72        let reply = TopologyReply {
73            topology_bytes: bytes,
74        };
75        let decoded = decode_topology(&reply.topology_bytes).expect("decode");
76        assert!(decoded.is_none());
77    }
78}