Skip to main content

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