hyperlane-plugin-grpc 23.0.0

A gRPC over HTTP/2 server plugin for the Hyperlane framework with length-prefixed framing, bounded decompression, gRPC status codes, timeout parsing, service routing, and an opt-in ServerHook.
Documentation
/// Canonical gRPC `Content-Type` header value.
pub const GRPC_CONTENT_TYPE: &str = "application/grpc";

/// Response header carrying the numeric gRPC status code.
pub const GRPC_STATUS_HEADER: &str = "grpc-status";

/// Response header carrying the percent-encoded gRPC error message.
pub const GRPC_MESSAGE_HEADER: &str = "grpc-message";

/// Request/response header identifying the gRPC payload compression coding.
pub const GRPC_ENCODING_HEADER: &str = "grpc-encoding";

/// Request header carrying the client-supplied RPC timeout budget.
pub const GRPC_TIMEOUT_HEADER: &str = "grpc-timeout";

/// Default maximum decoded gRPC message size (4 MiB).
pub const DEFAULT_GRPC_MAX_MESSAGE_SIZE: usize = 4 * 1024 * 1024;

/// Length of the 5-byte gRPC Length-Prefixed-Message header.
pub const GRPC_FRAME_HEADER_LEN: usize = 5;

/// Default decompression scratch buffer size.
pub(crate) const GRPC_DECOMPRESS_BUF_SIZE: usize = 4096;

/// Fast-path stack buffer capacity for direct HTTP/1.1 gRPC wire assembly of small messages.
pub(crate) const GRPC_WIRE_FAST_STACK_CAP: usize = 512;

/// Stack buffer capacity for direct HTTP/1.1 gRPC wire assembly without heap allocation.
pub(crate) const GRPC_WIRE_STACK_CAP: usize = 4096;

/// Maximum registered method count scanned linearly in [`GrpcRouter`] before hashing.
pub(crate) const GRPC_SMALL_METHODS_LIMIT: usize = 4;

/// SWAR high-bit mask for testing 8 ASCII bytes simultaneously.
pub(crate) const SWAR_HIGH_BITS: u64 = 0x8080_8080_8080_8080;

/// SWAR broadcast of `0x20` (ASCII space) for `< 0x20` range check.
pub(crate) const SWAR_SPACE_BROADCAST: u64 = 0x2020_2020_2020_2020;

/// SWAR broadcast of `0x01` for `0x7f` and byte-equality tests.
pub(crate) const SWAR_ONES_BROADCAST: u64 = 0x0101_0101_0101_0101;

/// SWAR broadcast of `b'%'` (`0x25`) for percent-sign detection.
pub(crate) const SWAR_PERCENT_BROADCAST: u64 = 0x2525_2525_2525_2525;

/// Stack buffer capacity for formatting `usize` content-length values.
pub(crate) const GRPC_LEN_STACK_BUF: usize = 20;

/// Prebuilt HTTP/1.1 gRPC response wire prefix up to the `grpc-status` code.
pub(crate) const GRPC_WIRE_PREFIX: &[u8] =
    b"HTTP/1.1 200 OK\r\nconnection: keep-alive\r\ncontent-type: application/grpc\r\ngrpc-status: ";

/// Prebuilt HTTP/1.1 header segment introducing `content-length`.
pub(crate) const GRPC_WIRE_CL: &[u8] = b"\r\ncontent-length: ";

/// HTTP/1.1 double-CRLF header terminator preceding the framed gRPC payload.
pub(crate) const GRPC_WIRE_END: &[u8] = b"\r\n\r\n";

/// Uppercase hexadecimal digits for RFC 3986 percent-encoding of `grpc-message`.
pub(crate) const GRPC_HEX_UPPER: &[u8; 16] = b"0123456789ABCDEF";

/// Pre-formatted numeric strings for canonical gRPC status codes `0..=16`.
pub(crate) const GRPC_STATUS_CODE_STRS: [&str; 17] = [
    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
];

/// Identity encoding token indicating uncompressed gRPC frames.
pub(crate) const GRPC_IDENTITY_ENCODING: &str = "identity";

/// Error text when a gRPC payload is truncated before the 5-byte frame header.
pub(crate) const ERR_GRPC_TRUNCATED_HEADER: &str = "Truncated gRPC frame header";

/// Error text when a gRPC payload has an invalid compression flag (`> 1`).
pub(crate) const ERR_GRPC_INVALID_FLAG: &str = "Invalid gRPC compression flag";

/// Error text when a gRPC payload declares a length exceeding the configured cap.
pub(crate) const ERR_GRPC_MSG_TOO_LARGE: &str = "gRPC message exceeds max_message_size";

/// Error text when a gRPC payload ends before the declared frame length.
pub(crate) const ERR_GRPC_TRUNCATED_BODY: &str = "Truncated gRPC frame payload";

/// Error text when a frame is flagged compressed without a supported `grpc-encoding`.
pub(crate) const ERR_GRPC_UNSUPPORTED_ENCODING: &str = "Unsupported or missing grpc-encoding";

/// Error text when a gRPC method path is not registered in [`GrpcRouter`].
pub(crate) const ERR_GRPC_UNIMPLEMENTED: &str = "gRPC method not implemented";

/// Error text when a gRPC handler exceeds the caller's `grpc-timeout` deadline.
pub(crate) const ERR_GRPC_DEADLINE_EXCEEDED: &str = "gRPC deadline exceeded";

/// ASCII digit zero byte (`0`).
pub(crate) const ASCII_ZERO: u8 = b'0';

/// ASCII percent byte (`%`).
pub(crate) const ASCII_PERCENT: u8 = b'%';

/// ASCII plus byte (`+`).
pub(crate) const ASCII_PLUS: u8 = b'+';

/// ASCII semicolon byte (`;`).
pub(crate) const ASCII_SEMICOLON: u8 = b';';

/// gRPC timeout unit byte for hours (`H`).
pub(crate) const TIMEOUT_UNIT_HOURS: u8 = b'H';

/// gRPC timeout unit byte for minutes (`M`).
pub(crate) const TIMEOUT_UNIT_MINUTES: u8 = b'M';

/// gRPC timeout unit byte for seconds (`S`).
pub(crate) const TIMEOUT_UNIT_SECONDS: u8 = b'S';

/// gRPC timeout unit byte for milliseconds (`m`).
pub(crate) const TIMEOUT_UNIT_MILLIS: u8 = b'm';

/// gRPC timeout unit byte for microseconds (`u`).
pub(crate) const TIMEOUT_UNIT_MICROS: u8 = b'u';

/// gRPC timeout unit byte for nanoseconds (`n`).
pub(crate) const TIMEOUT_UNIT_NANOS: u8 = b'n';