Skip to main content

connectrpc_reflection/generated/connect/
grpc.reflection.v1alpha.reflection.__connect.rs

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