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