Skip to main content

hyperlane_plugin_rpc/
const.rs

1/// JSON-RPC 2.0 protocol version literal.
2pub const JSONRPC_VERSION: &str = "2.0";
3
4/// Default HTTP endpoint path handled by [`crate::RpcHook`].
5pub const DEFAULT_RPC_ENDPOINT: &str = "/rpc";
6
7/// Default maximum request body size accepted by [`crate::RpcHook`] (1 MiB).
8pub const DEFAULT_RPC_MAX_BODY_SIZE: usize = 1024 * 1024;
9
10/// Default maximum number of items permitted in one JSON-RPC batch array.
11pub const DEFAULT_RPC_MAX_BATCH_SIZE: usize = 64;
12
13/// JSON-RPC 2.0 Parse Error code.
14pub const RPC_PARSE_ERROR: i64 = -32700;
15
16/// JSON-RPC 2.0 Invalid Request code.
17pub const RPC_INVALID_REQUEST: i64 = -32600;
18
19/// JSON-RPC 2.0 Method Not Found code.
20pub const RPC_METHOD_NOT_FOUND: i64 = -32601;
21
22/// JSON-RPC 2.0 Invalid Params code.
23pub const RPC_INVALID_PARAMS: i64 = -32602;
24
25/// JSON-RPC 2.0 Internal Error code.
26pub const RPC_INTERNAL_ERROR: i64 = -32603;
27
28/// Standard Parse Error message.
29pub(crate) const MSG_PARSE_ERROR: &str = "Parse error";
30
31/// Standard Invalid Request message.
32pub(crate) const MSG_INVALID_REQUEST: &str = "Invalid Request";
33
34/// Standard Method Not Found message.
35pub(crate) const MSG_METHOD_NOT_FOUND: &str = "Method not found";
36
37/// Standard Invalid Params message.
38pub(crate) const MSG_INVALID_PARAMS: &str = "Invalid params";
39
40/// Standard Internal Error message.
41pub(crate) const MSG_INTERNAL_ERROR: &str = "Internal error";
42
43/// Prebuilt JSON-RPC 2.0 Parse Error response bytes avoiding per-error serialization.
44pub(crate) const PREBUILT_PARSE_ERROR: &[u8] =
45    br#"{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error"},"id":null}"#;
46
47/// Prebuilt JSON-RPC 2.0 Invalid Request response bytes avoiding per-error serialization.
48pub(crate) const PREBUILT_INVALID_REQUEST: &[u8] =
49    br#"{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid Request"},"id":null}"#;
50
51/// Prebuilt JSON-RPC 2.0 batch-limit-exceeded error response bytes.
52pub(crate) const PREBUILT_BATCH_TOO_LARGE: &[u8] = br#"{"jsonrpc":"2.0","error":{"code":-32600,"message":"Batch size exceeds configured limit"},"id":null}"#;
53
54/// Initial buffer capacity in bytes when serializing a single JSON-RPC 2.0 response.
55pub(crate) const RPC_SINGLE_RESPONSE_CAP: usize = 128;
56
57/// JSON-RPC 2.0 request field name `"jsonrpc"`.
58pub(crate) const FIELD_JSONRPC: &str = "jsonrpc";
59
60/// JSON-RPC 2.0 request field name `"method"`.
61pub(crate) const FIELD_METHOD: &str = "method";
62
63/// JSON-RPC 2.0 request field name `"params"`.
64pub(crate) const FIELD_PARAMS: &str = "params";
65
66/// JSON-RPC 2.0 request field name `"id"`.
67pub(crate) const FIELD_ID: &str = "id";
68
69/// Serde visitor expectation message for JSON-RPC field keys.
70pub(crate) const EXPECT_FIELD_KEY: &str = "JSON-RPC field key";
71
72/// Serde visitor expectation message for lenient JSON strings.
73pub(crate) const EXPECT_LENIENT_STR: &str = "JSON value";
74
75/// Serde visitor expectation message for JSON-RPC correlation identifiers.
76pub(crate) const EXPECT_RPC_ID: &str = "JSON-RPC id";
77
78/// Serde visitor expectation message for JSON-RPC request or batch elements.
79pub(crate) const EXPECT_BATCH_ITEM: &str = "JSON-RPC request item";
80
81/// Static JSON prefix for compact JSON-RPC 2.0 response objects.
82pub(crate) const RPC_JSON_PREFIX: &[u8] = br#"{"jsonrpc":"2.0","id":"#;
83
84/// Static JSON field separator before the `"result"` payload.
85pub(crate) const RPC_JSON_RESULT_KEY: &[u8] = br#","result":"#;
86
87/// Static JSON field separator before the `"error"` payload.
88pub(crate) const RPC_JSON_ERROR_KEY: &[u8] = br#","error":"#;
89
90/// Pre-serialized JSON error object for `Invalid Request` (`-32600`).
91pub(crate) const STATIC_ERR_INVALID_REQUEST: &[u8] =
92    br#"{"code":-32600,"message":"Invalid Request"}"#;
93
94/// Pre-serialized JSON error object for `Method not found` (`-32601`).
95pub(crate) const STATIC_ERR_METHOD_NOT_FOUND: &[u8] =
96    br#"{"code":-32601,"message":"Method not found"}"#;
97
98/// Static JSON literal for `null`.
99pub(crate) const JSON_NULL: &[u8] = b"null";
100
101/// Static JSON literal for `true`.
102pub(crate) const JSON_TRUE: &[u8] = b"true";
103
104/// Static JSON literal for `false`.
105pub(crate) const JSON_FALSE: &[u8] = b"false";
106
107/// HTTP/1.1 `200 OK` JSON response prefix up to the `content-length` value.
108pub(crate) const WIRE_HTTP11_200_JSON_PREFIX: &[u8] =
109    b"HTTP/1.1 200 OK\r\ncontent-type: application/json\r\nconnection: keep-alive\r\ncontent-length: ";
110
111/// HTTP/1.1 header block terminator (`\r\n\r\n`).
112pub(crate) const WIRE_HEADER_END: &[u8] = b"\r\n\r\n";
113
114/// Stack buffer capacity in bytes for zero-allocation HTTP/1.1 JSON-RPC wire responses.
115pub(crate) const RPC_WIRE_STACK_CAP: usize = 1024;
116
117/// Maximum JSON payload length eligible for stack-buffered single HTTP/1.1 framing.
118pub(crate) const RPC_PAYLOAD_STACK_CAP: usize = 512;
119
120/// Multiplicative 64-bit mixing constant for zero-allocation [`FxHasher`].
121pub(crate) const FX_HASH_K: u64 = 0x517c_c1b7_2722_0a95;
122
123/// Two-digit ASCII decimal lookup pairs for `00..=99`.
124pub(crate) const DEC_DIGITS_LUT: &[u8; 200] = b"00010203040506070809\
12510111213141516171819\
12620212223242526272829\
12730313233343536373839\
12840414243444546474849\
12950515253545556575859\
13060616263646566676869\
13170717273747576777879\
13280818283848586878889\
13390919293949596979899";
134
135/// ASCII opening brace byte (`'{'`).
136pub(crate) const BYTE_LBRACE: u8 = b'{';
137
138/// ASCII closing brace byte (`'}'`).
139pub(crate) const BYTE_RBRACE: u8 = b'}';
140
141/// ASCII opening bracket byte (`'['`).
142pub(crate) const BYTE_LBRACKET: u8 = b'[';
143
144/// ASCII closing bracket byte (`']'`).
145pub(crate) const BYTE_RBRACKET: u8 = b']';
146
147/// ASCII comma byte (`','`).
148pub(crate) const BYTE_COMMA: u8 = b',';
149
150/// ASCII double quote byte (`'"'`).
151pub(crate) const BYTE_QUOTE: u8 = b'"';
152
153/// ASCII backslash byte (`'\\'`).
154pub(crate) const BYTE_BACKSLASH: u8 = b'\\';
155
156/// ASCII hyphen byte (`'-'`).
157pub(crate) const BYTE_DASH: u8 = b'-';
158
159/// ASCII zero digit byte (`'0'`).
160pub(crate) const BYTE_ZERO: u8 = b'0';
161
162/// ASCII space byte.
163pub(crate) const BYTE_SPACE: u8 = b' ';
164
165/// ASCII horizontal tab byte.
166pub(crate) const BYTE_TAB: u8 = b'\t';
167
168/// ASCII carriage return byte.
169pub(crate) const BYTE_CR: u8 = b'\r';
170
171/// ASCII line feed byte.
172pub(crate) const BYTE_LF: u8 = b'\n';