hyperlane_plugin_grpc/struct.rs
1use super::*;
2
3/// Structured gRPC error carrying a canonical [`GrpcStatus`] and message.
4#[derive(Clone, Data, Debug, Eq, PartialEq)]
5pub struct GrpcError {
6 /// Canonical gRPC status code.
7 #[get(type(copy))]
8 pub(crate) status: GrpcStatus,
9 /// Human-readable error message (percent-encoded on the wire).
10 pub(crate) message: String,
11}
12
13/// Decoded 5-byte length-prefixed gRPC message frame.
14#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
15pub struct GrpcFrame {
16 /// Whether the wire frame had its compression flag set (`1`).
17 #[get(type(copy))]
18 pub(crate) compressed: bool,
19 /// Uncompressed message payload bytes.
20 pub(crate) payload: Vec<u8>,
21}
22
23/// Configuration governing gRPC message size limits and response compression.
24#[derive(Clone, Data, Debug, Eq, PartialEq)]
25pub struct GrpcConfig {
26 /// Maximum encoded and decoded gRPC message size in bytes.
27 #[get(type(copy))]
28 pub(crate) max_message_size: usize,
29 /// Compression algorithm applied to outgoing response frames (`Compress::Unknown` = identity).
30 #[get(type(copy))]
31 pub(crate) compression: Compress,
32}
33
34/// Thread-safe registry mapping `/package.Service/Method` paths to unary async handlers.
35#[derive(Clone)]
36pub struct GrpcRouter {
37 /// Small linear method cache used when `methods.len() <= GRPC_SMALL_METHODS_LIMIT` to bypass hashing.
38 pub(crate) small_methods: Vec<(String, GrpcHandler)>,
39 /// Registered unary handlers keyed by full gRPC path with `XxHash3_64`.
40 pub(crate) methods: HashMapXxHash3_64<String, GrpcHandler>,
41 /// Registered interceptors invoked before each gRPC call.
42 pub(crate) interceptors: Vec<Arc<dyn GrpcInterceptor>>,
43}
44
45/// Process-wide [`GrpcPlugin`] registry holding [`GrpcConfig`] and [`GrpcRouter`].
46#[derive(Clone)]
47pub struct GrpcPlugin {
48 /// Active gRPC configuration.
49 pub(crate) config: GrpcConfig,
50 /// Registered gRPC service router.
51 pub(crate) router: GrpcRouter,
52}
53
54/// Opt-in [`ServerHook`] dispatching gRPC `POST` requests with `Content-Type: application/grpc*`.
55#[derive(Clone, Copy, Debug, Default)]
56#[hyperlane::request_middleware(-65)]
57pub struct GrpcHook;