connectrpc_reflection/generated/connect/grpc.reflection.v1.reflection.__connect.rs
1///Shorthand for `OwnedView<ServerReflectionRequestView<'static>>`.
2pub type OwnedServerReflectionRequestView = ::buffa::view::OwnedView<
3 crate::proto::grpc::reflection::v1::__buffa::view::ServerReflectionRequestView<
4 'static,
5 >,
6>;
7///Shorthand for `OwnedView<ServerReflectionResponseView<'static>>`.
8pub type OwnedServerReflectionResponseView = ::buffa::view::OwnedView<
9 crate::proto::grpc::reflection::v1::__buffa::view::ServerReflectionResponseView<
10 'static,
11 >,
12>;
13impl ::connectrpc::Encodable<
14 crate::proto::grpc::reflection::v1::ServerReflectionResponse,
15>
16for crate::proto::grpc::reflection::v1::__buffa::view::ServerReflectionResponseView<'_> {
17 fn encode(
18 &self,
19 codec: ::connectrpc::CodecFormat,
20 ) -> ::std::result::Result<::buffa::bytes::Bytes, ::connectrpc::ConnectError> {
21 ::connectrpc::__codegen::encode_view_body(self, codec)
22 }
23}
24impl ::connectrpc::Encodable<
25 crate::proto::grpc::reflection::v1::ServerReflectionResponse,
26>
27for ::buffa::view::OwnedView<
28 crate::proto::grpc::reflection::v1::__buffa::view::ServerReflectionResponseView<
29 'static,
30 >,
31> {
32 fn encode(
33 &self,
34 codec: ::connectrpc::CodecFormat,
35 ) -> ::std::result::Result<::buffa::bytes::Bytes, ::connectrpc::ConnectError> {
36 ::connectrpc::__codegen::encode_view_body(self.reborrow(), codec)
37 }
38}
39/// Full service name for this service.
40pub const SERVER_REFLECTION_SERVICE_NAME: &str = "grpc.reflection.v1.ServerReflection";
41/// Static [`Spec`](::connectrpc::Spec) for the server-side `ServerReflectionInfo` RPC.
42///
43/// The dispatcher surfaces this on
44/// [`RequestContext::spec`](::connectrpc::RequestContext::spec).
45pub const SERVER_REFLECTION_SERVER_REFLECTION_INFO_SPEC: ::connectrpc::Spec = ::connectrpc::Spec::server(
46 "/grpc.reflection.v1.ServerReflection/ServerReflectionInfo",
47 ::connectrpc::StreamType::BidiStream,
48 )
49 .with_idempotency_level(::connectrpc::IdempotencyLevel::Unknown);
50/// Server trait for ServerReflection.
51///
52/// # Implementing handlers
53///
54/// Implement methods with plain `async fn`; the returned future satisfies
55/// the `Send` bound automatically.
56///
57/// **Unary and server-streaming requests** arrive as
58/// [`ServiceRequest<'_, Req>`](::connectrpc::ServiceRequest): a zero-copy
59/// view of the request plus its body, valid for the duration of the call.
60/// Fields are read directly (`request.name` is a `&str` into the decoded
61/// buffer) and the borrow may be held across `.await` points. Anything
62/// that must outlive the call — `tokio::spawn`, channels, server state,
63/// or data captured by a returned response stream — takes owned data:
64/// call `request.to_owned_message()` (or copy the specific fields)
65/// first.
66///
67/// **Client-streaming and bidi requests** arrive as
68/// `ServiceStream<`[`StreamMessage<Req>`](::connectrpc::StreamMessage)`>`.
69/// Each item owns its decoded buffer and is `Send + 'static`, so items
70/// can be buffered or moved into spawned tasks; read fields zero-copy
71/// through the generated accessor methods (`item.name()`) or `.view()`,
72/// convert with `.to_owned_message()`, or yield an item back unchanged —
73/// `StreamMessage<M>` implements `Encodable<M>`.
74///
75/// Request types resolved through `extern_path` (e.g. well-known types
76/// from another crate) use the same wrappers; the crate that owns the
77/// type must be generated with buffa ≥ 0.7.0 and views enabled so the
78/// backing `HasMessageView` impl exists.
79///
80/// The `impl Encodable<Out>` return bound accepts the owned `Out`, the
81/// generated `OutView<'_>` / `OwnedOutView`,
82/// [`MaybeBorrowed`](::connectrpc::MaybeBorrowed), or
83/// [`PreEncoded`](::connectrpc::PreEncoded) for handlers that encode a
84/// non-`'static` view internally and pass the bytes across the handler
85/// boundary. View bodies are not emitted for output types mapped via
86/// `extern_path` (the impl would be an orphan); return owned for
87/// WKT/extern outputs.
88///
89/// Server-streaming and bidi-streaming methods return
90/// `ServiceStream<impl Encodable<Out> + Send + use<Self>>`. The
91/// `use<Self>` precise-capturing clause excludes `&self`'s lifetime and
92/// the request's lifetime (unary methods use `use<'a, Self>` and may
93/// borrow from `&self`), so stream items must be `'static` and cannot
94/// borrow from the request. To stream view-encoded data, encode each
95/// item inside the stream body and yield
96/// [`PreEncoded`](::connectrpc::PreEncoded) — see its `# Streaming
97/// example` doc.
98#[allow(clippy::type_complexity)]
99pub trait ServerReflection: Send + Sync + 'static {
100 /// The reflection service is structured as a bidirectional stream, ensuring
101 /// all related requests go to a single server.
102 ///
103 /// Each `requests` item is a [`StreamMessage`](::connectrpc::StreamMessage):
104 /// it owns its buffer, is `Send + 'static`, and exposes zero-copy
105 /// accessor methods (`item.name()`), `.view()`, and
106 /// `.to_owned_message()`.
107 fn server_reflection_info(
108 &self,
109 ctx: ::connectrpc::RequestContext,
110 requests: ::connectrpc::ServiceStream<
111 ::connectrpc::StreamMessage<
112 crate::proto::grpc::reflection::v1::ServerReflectionRequest,
113 >,
114 >,
115 ) -> impl ::std::future::Future<
116 Output = ::connectrpc::ServiceResult<
117 ::connectrpc::ServiceStream<
118 impl ::connectrpc::Encodable<
119 crate::proto::grpc::reflection::v1::ServerReflectionResponse,
120 > + Send + use<Self>,
121 >,
122 >,
123 > + Send;
124}
125/// Extension trait for registering a service implementation with a Router.
126///
127/// This trait is automatically implemented for all types that implement the service trait.
128///
129/// # Example
130///
131/// ```rust,ignore
132/// use std::sync::Arc;
133///
134/// let service = Arc::new(MyServiceImpl);
135/// let router = service.register(Router::new());
136/// ```
137pub trait ServerReflectionExt: ServerReflection {
138 /// Register this service implementation with a Router.
139 ///
140 /// Takes ownership of the `Arc<Self>` and returns a new Router with
141 /// this service's methods registered.
142 fn register(
143 self: ::std::sync::Arc<Self>,
144 router: ::connectrpc::Router,
145 ) -> ::connectrpc::Router;
146}
147impl<S: ServerReflection> ServerReflectionExt for S {
148 fn register(
149 self: ::std::sync::Arc<Self>,
150 router: ::connectrpc::Router,
151 ) -> ::connectrpc::Router {
152 router
153 .route_view_bidi_stream::<
154 _,
155 _,
156 crate::proto::grpc::reflection::v1::ServerReflectionResponse,
157 >(
158 SERVER_REFLECTION_SERVICE_NAME,
159 "ServerReflectionInfo",
160 ::connectrpc::view_bidi_streaming_handler_fn({
161 let svc = ::std::sync::Arc::clone(&self);
162 move |ctx, req| {
163 let svc = ::std::sync::Arc::clone(&svc);
164 async move {
165 let req = ::connectrpc::dispatcher::codegen::into_stream_messages::<
166 crate::proto::grpc::reflection::v1::ServerReflectionRequest,
167 >(req);
168 svc.server_reflection_info(ctx, req).await
169 }
170 }
171 }),
172 )
173 .with_spec(SERVER_REFLECTION_SERVER_REFLECTION_INFO_SPEC)
174 }
175}
176/// Monomorphic dispatcher for `ServerReflection`.
177///
178/// Unlike `.register(Router)` which type-erases each method into an `Arc<dyn ErasedHandler>` stored in a `HashMap`, this struct dispatches via a compile-time `match` on method name: no vtable, no hash lookup.
179///
180/// # Example
181///
182/// ```rust,ignore
183/// use connectrpc::ConnectRpcService;
184///
185/// let server = ServerReflectionServer::new(MyImpl);
186/// let service = ConnectRpcService::new(server);
187/// // hand `service` to axum/hyper as a fallback_service
188/// ```
189pub struct ServerReflectionServer<T> {
190 inner: ::std::sync::Arc<T>,
191}
192impl<T: ServerReflection> ServerReflectionServer<T> {
193 /// Wrap a service implementation in a monomorphic dispatcher.
194 pub fn new(service: T) -> Self {
195 Self {
196 inner: ::std::sync::Arc::new(service),
197 }
198 }
199 /// Wrap an already-`Arc`'d service implementation.
200 pub fn from_arc(inner: ::std::sync::Arc<T>) -> Self {
201 Self { inner }
202 }
203}
204impl<T> Clone for ServerReflectionServer<T> {
205 fn clone(&self) -> Self {
206 Self {
207 inner: ::std::sync::Arc::clone(&self.inner),
208 }
209 }
210}
211impl<T: ServerReflection> ::connectrpc::Dispatcher for ServerReflectionServer<T> {
212 #[inline]
213 fn lookup(
214 &self,
215 path: &str,
216 ) -> Option<::connectrpc::dispatcher::codegen::MethodDescriptor> {
217 let method = path.strip_prefix("grpc.reflection.v1.ServerReflection/")?;
218 match method {
219 "ServerReflectionInfo" => {
220 Some(
221 ::connectrpc::dispatcher::codegen::MethodDescriptor::bidi_streaming()
222 .with_spec(SERVER_REFLECTION_SERVER_REFLECTION_INFO_SPEC),
223 )
224 }
225 _ => None,
226 }
227 }
228 fn call_unary(
229 &self,
230 path: &str,
231 ctx: ::connectrpc::RequestContext,
232 request: ::connectrpc::Payload,
233 format: ::connectrpc::CodecFormat,
234 ) -> ::connectrpc::dispatcher::codegen::UnaryResult {
235 let Some(method) = path.strip_prefix("grpc.reflection.v1.ServerReflection/")
236 else {
237 return ::connectrpc::dispatcher::codegen::unimplemented_unary(path);
238 };
239 let _ = (&ctx, &request, &format);
240 match method {
241 _ => ::connectrpc::dispatcher::codegen::unimplemented_unary(path),
242 }
243 }
244 fn call_server_streaming(
245 &self,
246 path: &str,
247 ctx: ::connectrpc::RequestContext,
248 request: ::buffa::bytes::Bytes,
249 format: ::connectrpc::CodecFormat,
250 ) -> ::connectrpc::dispatcher::codegen::StreamingResult {
251 let Some(method) = path.strip_prefix("grpc.reflection.v1.ServerReflection/")
252 else {
253 return ::connectrpc::dispatcher::codegen::unimplemented_streaming(path);
254 };
255 let _ = (&ctx, &request, &format);
256 match method {
257 _ => ::connectrpc::dispatcher::codegen::unimplemented_streaming(path),
258 }
259 }
260 fn call_client_streaming(
261 &self,
262 path: &str,
263 ctx: ::connectrpc::RequestContext,
264 requests: ::connectrpc::dispatcher::codegen::RequestStream,
265 format: ::connectrpc::CodecFormat,
266 ) -> ::connectrpc::dispatcher::codegen::UnaryResult {
267 let Some(method) = path.strip_prefix("grpc.reflection.v1.ServerReflection/")
268 else {
269 return ::connectrpc::dispatcher::codegen::unimplemented_unary(path);
270 };
271 let _ = (&ctx, &requests, &format);
272 match method {
273 _ => ::connectrpc::dispatcher::codegen::unimplemented_unary(path),
274 }
275 }
276 fn call_bidi_streaming(
277 &self,
278 path: &str,
279 ctx: ::connectrpc::RequestContext,
280 requests: ::connectrpc::dispatcher::codegen::RequestStream,
281 format: ::connectrpc::CodecFormat,
282 ) -> ::connectrpc::dispatcher::codegen::StreamingResult {
283 let Some(method) = path.strip_prefix("grpc.reflection.v1.ServerReflection/")
284 else {
285 return ::connectrpc::dispatcher::codegen::unimplemented_streaming(path);
286 };
287 let _ = (&ctx, &requests, &format);
288 match method {
289 "ServerReflectionInfo" => {
290 let svc = ::std::sync::Arc::clone(&self.inner);
291 Box::pin(async move {
292 let req_stream = ::connectrpc::dispatcher::codegen::decode_message_request_stream::<
293 crate::proto::grpc::reflection::v1::ServerReflectionRequest,
294 >(requests, format);
295 let resp = svc.server_reflection_info(ctx, req_stream).await?;
296 Ok(
297 resp
298 .map_body(|s| ::connectrpc::dispatcher::codegen::encode_response_stream::<
299 crate::proto::grpc::reflection::v1::ServerReflectionResponse,
300 _,
301 _,
302 >(s, format)),
303 )
304 })
305 }
306 _ => ::connectrpc::dispatcher::codegen::unimplemented_streaming(path),
307 }
308 }
309}
310/// Client for this service.
311///
312/// Generic over `T: ClientTransport`. For **gRPC** (HTTP/2), use
313/// `Http2Connection` — it has honest `poll_ready` and composes with
314/// `tower::balance` for multi-connection load balancing. For **Connect
315/// over HTTP/1.1** (or unknown protocol), use `HttpClient`.
316///
317/// # Example (gRPC / HTTP/2)
318///
319/// ```rust,ignore
320/// use connectrpc::client::{Http2Connection, ClientConfig};
321/// use connectrpc::Protocol;
322///
323/// let uri: http::Uri = "http://localhost:8080".parse()?;
324/// let conn = Http2Connection::connect_plaintext(uri.clone()).await?.shared(1024);
325/// let config = ClientConfig::new(uri).with_protocol(Protocol::Grpc);
326///
327/// let client = ServerReflectionClient::new(conn, config);
328/// let response = client.server_reflection_info(request).await?;
329/// ```
330///
331/// # Example (Connect / HTTP/1.1 or ALPN)
332///
333/// ```rust,ignore
334/// use connectrpc::client::{HttpClient, ClientConfig};
335///
336/// let http = HttpClient::plaintext(); // cleartext http:// only
337/// let config = ClientConfig::new("http://localhost:8080".parse()?);
338///
339/// let client = ServerReflectionClient::new(http, config);
340/// let response = client.server_reflection_info(request).await?;
341/// ```
342///
343/// # Working with the response
344///
345/// Unary calls return [`UnaryResponse<OwnedView<FooView>>`](::connectrpc::client::UnaryResponse).
346/// [`view()`](::connectrpc::client::UnaryResponse::view) borrows the response
347/// message, so field access is zero-copy:
348///
349/// ```rust,ignore
350/// let resp = client.server_reflection_info(request).await?;
351/// let name: &str = resp.view().name; // borrow into the response buffer
352/// ```
353///
354/// If you need the owned struct (e.g. to store or pass by value), use
355/// [`into_owned()`](::connectrpc::client::UnaryResponse::into_owned):
356///
357/// ```rust,ignore
358/// let owned = client.server_reflection_info(request).await?.into_owned();
359/// ```
360///
361/// [`into_view()`](::connectrpc::client::UnaryResponse::into_view) keeps the
362/// zero-copy decoded body (an `OwnedView`) without copying; field access on it
363/// goes through `.reborrow()`. Streaming responses yield one `OwnedView` per
364/// received message from `.message().await` — bind `msg.reborrow()` for field
365/// access, or convert with `.to_owned_message()`.
366#[cfg(feature = "client")]
367#[derive(Clone)]
368pub struct ServerReflectionClient<T> {
369 transport: T,
370 config: ::connectrpc::client::ClientConfig,
371}
372#[cfg(feature = "client")]
373impl<T> ServerReflectionClient<T>
374where
375 T: ::connectrpc::client::ClientTransport,
376 <T::ResponseBody as ::http_body::Body>::Error: ::std::fmt::Display,
377{
378 /// Create a new client with the given transport and configuration.
379 pub fn new(transport: T, config: ::connectrpc::client::ClientConfig) -> Self {
380 Self { transport, config }
381 }
382 /// Get the client configuration.
383 pub fn config(&self) -> &::connectrpc::client::ClientConfig {
384 &self.config
385 }
386 /// Get a mutable reference to the client configuration.
387 pub fn config_mut(&mut self) -> &mut ::connectrpc::client::ClientConfig {
388 &mut self.config
389 }
390 /// Call the ServerReflectionInfo RPC. Sends a request to /grpc.reflection.v1.ServerReflection/ServerReflectionInfo.
391 pub async fn server_reflection_info(
392 &self,
393 ) -> Result<
394 ::connectrpc::client::BidiStream<
395 T::ResponseBody,
396 crate::proto::grpc::reflection::v1::ServerReflectionRequest,
397 crate::proto::grpc::reflection::v1::__buffa::view::ServerReflectionResponseView<
398 'static,
399 >,
400 >,
401 ::connectrpc::ConnectError,
402 > {
403 self.server_reflection_info_with_options(
404 ::connectrpc::client::CallOptions::default(),
405 )
406 .await
407 }
408 /// Call the ServerReflectionInfo RPC with explicit per-call options. Options override [`ClientConfig`](::connectrpc::client::ClientConfig) defaults.
409 pub async fn server_reflection_info_with_options(
410 &self,
411 options: ::connectrpc::client::CallOptions,
412 ) -> Result<
413 ::connectrpc::client::BidiStream<
414 T::ResponseBody,
415 crate::proto::grpc::reflection::v1::ServerReflectionRequest,
416 crate::proto::grpc::reflection::v1::__buffa::view::ServerReflectionResponseView<
417 'static,
418 >,
419 >,
420 ::connectrpc::ConnectError,
421 > {
422 ::connectrpc::client::call_bidi_stream(
423 &self.transport,
424 &self.config,
425 SERVER_REFLECTION_SERVICE_NAME,
426 "ServerReflectionInfo",
427 options,
428 )
429 .await
430 }
431}