polyester/gen/connect/orderbook.v1.rs
1// @generated by connectrpc-codegen. DO NOT EDIT.
2
3///Shorthand for `OwnedView<GetOrderBookRequestView<'static>>`.
4pub type OwnedGetOrderBookRequestView = ::buffa::view::OwnedView<
5 crate::proto::orderbook::v1::__buffa::view::GetOrderBookRequestView<'static>,
6>;
7///Shorthand for `OwnedView<GetOrderBookResponseView<'static>>`.
8pub type OwnedGetOrderBookResponseView = ::buffa::view::OwnedView<
9 crate::proto::orderbook::v1::__buffa::view::GetOrderBookResponseView<'static>,
10>;
11impl ::connectrpc::Encodable<crate::proto::orderbook::v1::GetOrderBookResponse>
12for crate::proto::orderbook::v1::__buffa::view::GetOrderBookResponseView<'_> {
13 fn encode(
14 &self,
15 codec: ::connectrpc::CodecFormat,
16 ) -> ::std::result::Result<::buffa::bytes::Bytes, ::connectrpc::ConnectError> {
17 ::connectrpc::__codegen::encode_view_body(self, codec)
18 }
19}
20impl ::connectrpc::Encodable<crate::proto::orderbook::v1::GetOrderBookResponse>
21for ::buffa::view::OwnedView<
22 crate::proto::orderbook::v1::__buffa::view::GetOrderBookResponseView<'static>,
23> {
24 fn encode(
25 &self,
26 codec: ::connectrpc::CodecFormat,
27 ) -> ::std::result::Result<::buffa::bytes::Bytes, ::connectrpc::ConnectError> {
28 ::connectrpc::__codegen::encode_view_body(self.reborrow(), codec)
29 }
30}
31/// Full service name for this service.
32pub const ORDERBOOK_SERVICE_SERVICE_NAME: &str = "orderbook.v1.OrderbookService";
33/// Static [`Spec`](::connectrpc::Spec) for the server-side `GetOrderBook` RPC.
34///
35/// The dispatcher surfaces this on
36/// [`RequestContext::spec`](::connectrpc::RequestContext::spec).
37pub const ORDERBOOK_SERVICE_GET_ORDER_BOOK_SPEC: ::connectrpc::Spec = ::connectrpc::Spec::server(
38 "/orderbook.v1.OrderbookService/GetOrderBook",
39 ::connectrpc::StreamType::Unary,
40 )
41 .with_idempotency_level(::connectrpc::IdempotencyLevel::Unknown);
42/// Server trait for OrderbookService.
43///
44/// # Implementing handlers
45///
46/// Implement methods with plain `async fn`; the returned future satisfies
47/// the `Send` bound automatically.
48///
49/// **Unary and server-streaming requests** arrive as
50/// [`ServiceRequest<'_, Req>`](::connectrpc::ServiceRequest): a zero-copy
51/// view of the request plus its body, valid for the duration of the call.
52/// Fields are read directly (`request.name` is a `&str` into the decoded
53/// buffer) and the borrow may be held across `.await` points. Anything
54/// that must outlive the call — `tokio::spawn`, channels, server state,
55/// or data captured by a returned response stream — takes owned data:
56/// call `request.to_owned_message()` (or copy the specific fields)
57/// first.
58///
59/// **Client-streaming and bidi requests** arrive as
60/// [`InboundStream<Req>`](::connectrpc::InboundStream) — a
61/// `ServiceStream` of [`StreamMessage`](::connectrpc::StreamMessage)s.
62/// Each item owns its decoded buffer and is `Send + 'static`, so items
63/// can be buffered or moved into spawned tasks; read fields zero-copy
64/// through the generated accessor methods (`item.name()`) or `.view()`,
65/// convert with `.to_owned_message()`, or yield an item back unchanged —
66/// `StreamMessage<M>` implements `Encodable<M>`.
67///
68/// Request types resolved through `extern_path` (e.g. well-known types
69/// from another crate) use the same wrappers; the crate that owns the
70/// type must be generated with buffa ≥ 0.8.0 and views enabled so the
71/// backing `HasMessageView` impl exists.
72///
73/// The `impl Encodable<Out>` return bound accepts the owned `Out`, the
74/// generated `OutView<'_>` / `OwnedOutView`,
75/// [`MaybeBorrowed`](::connectrpc::MaybeBorrowed), or
76/// [`PreEncoded`](::connectrpc::PreEncoded) for handlers that encode a
77/// non-`'static` view internally and pass the bytes across the handler
78/// boundary. View bodies are not emitted for output types mapped via
79/// `extern_path` (the impl would be an orphan); return owned for
80/// WKT/extern outputs.
81///
82/// Server-streaming and bidi-streaming methods return
83/// `ServiceStream<impl Encodable<Out> + Send + use<Self>>`. The
84/// `use<Self>` precise-capturing clause excludes `&self`'s lifetime and
85/// the request's lifetime (unary methods use `use<'a, Self>` and may
86/// borrow from `&self`), so stream items must be `'static` and cannot
87/// borrow from the request. To stream view-encoded data, encode each
88/// item inside the stream body and yield
89/// [`PreEncoded`](::connectrpc::PreEncoded) — see its `# Streaming
90/// example` doc.
91#[allow(clippy::type_complexity)]
92pub trait OrderbookService: Send + Sync + 'static {
93 /// Retrieve a spot order book depth snapshot for a symbol.
94 /// Supports selectable depth per side and returns best bid/ask levels.
95 ///
96 /// `'a` lets the response body borrow from `&self` (e.g. server-resident state).
97 ///
98 /// `request` is borrowed from the request body and is valid for the
99 /// duration of the call; message fields are read directly on it
100 /// (zero-copy). The response cannot borrow from `request` — use
101 /// `.to_owned_message()` (or copy the specific fields) for anything
102 /// returned, stored, or moved into `tokio::spawn`.
103 fn get_order_book<'a>(
104 &'a self,
105 ctx: ::connectrpc::RequestContext,
106 request: ::connectrpc::ServiceRequest<
107 '_,
108 crate::proto::orderbook::v1::GetOrderBookRequest,
109 >,
110 ) -> impl ::std::future::Future<
111 Output = ::connectrpc::ServiceResult<
112 impl ::connectrpc::Encodable<
113 crate::proto::orderbook::v1::GetOrderBookResponse,
114 > + Send + use<'a, Self>,
115 >,
116 > + Send;
117}
118/// Extension trait for registering a service implementation with a Router.
119///
120/// This trait is automatically implemented for all types that implement the service trait.
121/// Prefer [`Router::add_service`](::connectrpc::Router::add_service) for
122/// top-down registration; `register` remains available for compatibility
123/// and cases where the service-first call shape is more convenient.
124///
125/// # Example
126///
127/// ```rust,ignore
128/// use std::sync::Arc;
129///
130/// let service = Arc::new(MyServiceImpl);
131/// let router = service.register(Router::new());
132/// ```
133pub trait OrderbookServiceExt: OrderbookService {
134 /// Register this service implementation with a Router.
135 ///
136 /// Takes ownership of the `Arc<Self>` and returns a new Router with
137 /// this service's methods registered.
138 fn register(
139 self: ::std::sync::Arc<Self>,
140 router: ::connectrpc::Router,
141 ) -> ::connectrpc::Router;
142}
143impl<S: OrderbookService> OrderbookServiceExt for S {
144 fn register(
145 self: ::std::sync::Arc<Self>,
146 router: ::connectrpc::Router,
147 ) -> ::connectrpc::Router {
148 router
149 .route_view(
150 ORDERBOOK_SERVICE_SERVICE_NAME,
151 "GetOrderBook",
152 {
153 let svc = ::std::sync::Arc::clone(&self);
154 ::connectrpc::view_handler_fn(move |
155 ctx,
156 req: ::buffa::view::OwnedView<
157 crate::proto::orderbook::v1::__buffa::view::GetOrderBookRequestView<
158 'static,
159 >,
160 >,
161 format|
162 {
163 let svc = ::std::sync::Arc::clone(&svc);
164 async move {
165 let sreq = ::connectrpc::ServiceRequest::<
166 crate::proto::orderbook::v1::GetOrderBookRequest,
167 >::from_parts(req.reborrow(), req.bytes());
168 svc.get_order_book(ctx, sreq)
169 .await?
170 .encode::<
171 crate::proto::orderbook::v1::GetOrderBookResponse,
172 >(format)
173 }
174 })
175 },
176 )
177 .with_spec(ORDERBOOK_SERVICE_GET_ORDER_BOOK_SPEC)
178 }
179}
180/// Type-inference marker used by [`Router::add_service`](::connectrpc::Router::add_service).
181#[doc(hidden)]
182pub struct OrderbookServiceRegisterMarker;
183impl<S: OrderbookService> ::connectrpc::ServiceRegister<OrderbookServiceRegisterMarker>
184for ::std::sync::Arc<S> {
185 fn register_service(self, router: ::connectrpc::Router) -> ::connectrpc::Router {
186 <S as OrderbookServiceExt>::register(self, router)
187 }
188}
189/// Monomorphic dispatcher for `OrderbookService`.
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 = OrderbookServiceServer::new(MyImpl);
199/// let service = ConnectRpcService::new(server);
200/// // hand `service` to axum/hyper as a fallback_service
201/// ```
202pub struct OrderbookServiceServer<T> {
203 inner: ::std::sync::Arc<T>,
204}
205impl<T: OrderbookService> OrderbookServiceServer<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 OrderbookServiceServer<T> {
218 fn clone(&self) -> Self {
219 Self {
220 inner: ::std::sync::Arc::clone(&self.inner),
221 }
222 }
223}
224impl<T: OrderbookService> ::connectrpc::Dispatcher for OrderbookServiceServer<T> {
225 #[inline]
226 fn lookup(
227 &self,
228 path: &str,
229 ) -> Option<::connectrpc::dispatcher::codegen::MethodDescriptor> {
230 let method = path.strip_prefix("orderbook.v1.OrderbookService/")?;
231 match method {
232 "GetOrderBook" => {
233 Some(
234 ::connectrpc::dispatcher::codegen::MethodDescriptor::unary(false)
235 .with_spec(ORDERBOOK_SERVICE_GET_ORDER_BOOK_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("orderbook.v1.OrderbookService/") else {
249 return ::connectrpc::dispatcher::codegen::unimplemented_unary(path);
250 };
251 let _ = (&ctx, &request, &format);
252 match method {
253 "GetOrderBook" => {
254 let svc = ::std::sync::Arc::clone(&self.inner);
255 Box::pin(async move {
256 let body = ::connectrpc::dispatcher::codegen::request_proto_bytes::<
257 crate::proto::orderbook::v1::GetOrderBookRequest,
258 >(request.encoded()?, format)?;
259 let req: crate::proto::orderbook::v1::__buffa::view::GetOrderBookRequestView<
260 '_,
261 > = ::connectrpc::dispatcher::codegen::decode_borrowed_request_view(
262 &body,
263 )?;
264 let req = ::connectrpc::ServiceRequest::<
265 crate::proto::orderbook::v1::GetOrderBookRequest,
266 >::from_parts(&req, &body);
267 svc.get_order_book(ctx, req)
268 .await?
269 .encode::<
270 crate::proto::orderbook::v1::GetOrderBookResponse,
271 >(format)
272 })
273 }
274 _ => ::connectrpc::dispatcher::codegen::unimplemented_unary(path),
275 }
276 }
277 fn call_server_streaming(
278 &self,
279 path: &str,
280 ctx: ::connectrpc::RequestContext,
281 request: ::buffa::bytes::Bytes,
282 format: ::connectrpc::CodecFormat,
283 ) -> ::connectrpc::dispatcher::codegen::StreamingResult {
284 let Some(method) = path.strip_prefix("orderbook.v1.OrderbookService/") else {
285 return ::connectrpc::dispatcher::codegen::unimplemented_streaming(path);
286 };
287 let _ = (&ctx, &request, &format);
288 match method {
289 _ => ::connectrpc::dispatcher::codegen::unimplemented_streaming(path),
290 }
291 }
292 fn call_client_streaming(
293 &self,
294 path: &str,
295 ctx: ::connectrpc::RequestContext,
296 requests: ::connectrpc::dispatcher::codegen::RequestStream,
297 format: ::connectrpc::CodecFormat,
298 ) -> ::connectrpc::dispatcher::codegen::UnaryResult {
299 let Some(method) = path.strip_prefix("orderbook.v1.OrderbookService/") else {
300 return ::connectrpc::dispatcher::codegen::unimplemented_unary(path);
301 };
302 let _ = (&ctx, &requests, &format);
303 match method {
304 _ => ::connectrpc::dispatcher::codegen::unimplemented_unary(path),
305 }
306 }
307 fn call_bidi_streaming(
308 &self,
309 path: &str,
310 ctx: ::connectrpc::RequestContext,
311 requests: ::connectrpc::dispatcher::codegen::RequestStream,
312 format: ::connectrpc::CodecFormat,
313 ) -> ::connectrpc::dispatcher::codegen::StreamingResult {
314 let Some(method) = path.strip_prefix("orderbook.v1.OrderbookService/") else {
315 return ::connectrpc::dispatcher::codegen::unimplemented_streaming(path);
316 };
317 let _ = (&ctx, &requests, &format);
318 match method {
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/// # Working with the response
331///
332/// Unary calls return [`UnaryResponse<OwnedView<FooView>>`](::connectrpc::client::UnaryResponse).
333/// [`view()`](::connectrpc::client::UnaryResponse::view) borrows the response
334/// message, so field access is zero-copy:
335///
336/// ```rust,ignore
337/// let resp = client.get_order_book(request).await?;
338/// let name: &str = resp.view().name; // borrow into the response buffer
339/// ```
340///
341/// If you need the owned struct (e.g. to store or pass by value), use
342/// [`into_owned()`](::connectrpc::client::UnaryResponse::into_owned):
343///
344/// ```rust,ignore
345/// let owned = client.get_order_book(request).await?.into_owned();
346/// ```
347///
348/// [`into_view()`](::connectrpc::client::UnaryResponse::into_view) keeps the
349/// zero-copy decoded body (an `OwnedView`) without copying; field access on it
350/// goes through `.reborrow()`. Streaming responses yield one
351/// [`StreamMessage`](::connectrpc::StreamMessage) per received message from
352/// `.message().await` — read fields zero-copy through the generated accessor
353/// methods (`msg.name()`) or `.view()`, or convert with `.to_owned_message()`.
354#[derive(Clone)]
355pub struct OrderbookServiceClient<T> {
356 transport: T,
357 config: ::connectrpc::client::ClientConfig,
358}
359impl<T> OrderbookServiceClient<T>
360where
361 T: ::connectrpc::client::ClientTransport,
362 <T::ResponseBody as ::connectrpc::http_body::Body>::Error: ::std::fmt::Display,
363{
364 /// Create a new client with the given transport and configuration.
365 pub fn new(transport: T, config: ::connectrpc::client::ClientConfig) -> Self {
366 Self { transport, config }
367 }
368 /// Get the client configuration.
369 pub fn config(&self) -> &::connectrpc::client::ClientConfig {
370 &self.config
371 }
372 /// Get a mutable reference to the client configuration.
373 pub fn config_mut(&mut self) -> &mut ::connectrpc::client::ClientConfig {
374 &mut self.config
375 }
376 /// Call the GetOrderBook RPC. Sends a request to /orderbook.v1.OrderbookService/GetOrderBook.
377 pub async fn get_order_book(
378 &self,
379 request: crate::proto::orderbook::v1::GetOrderBookRequest,
380 ) -> Result<
381 ::connectrpc::client::UnaryResponse<
382 ::buffa::view::OwnedView<
383 crate::proto::orderbook::v1::__buffa::view::GetOrderBookResponseView<
384 'static,
385 >,
386 >,
387 >,
388 ::connectrpc::ConnectError,
389 > {
390 self.get_order_book_with_options(
391 request,
392 ::connectrpc::client::CallOptions::default(),
393 )
394 .await
395 }
396 /// Call the GetOrderBook RPC with explicit per-call options. Options override [`ClientConfig`](::connectrpc::client::ClientConfig) defaults.
397 pub async fn get_order_book_with_options(
398 &self,
399 request: crate::proto::orderbook::v1::GetOrderBookRequest,
400 options: ::connectrpc::client::CallOptions,
401 ) -> Result<
402 ::connectrpc::client::UnaryResponse<
403 ::buffa::view::OwnedView<
404 crate::proto::orderbook::v1::__buffa::view::GetOrderBookResponseView<
405 'static,
406 >,
407 >,
408 >,
409 ::connectrpc::ConnectError,
410 > {
411 ::connectrpc::client::call_unary(
412 &self.transport,
413 &self.config,
414 ORDERBOOK_SERVICE_SERVICE_NAME,
415 "GetOrderBook",
416 request,
417 options,
418 )
419 .await
420 }
421}