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