fidl_examples_keyvaluestore_baseline/
fidl_examples_keyvaluestore_baseline.rs1#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_examples_keyvaluestore_baseline__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct StoreMarker;
16
17impl fidl::endpoints::ProtocolMarker for StoreMarker {
18 type Proxy = StoreProxy;
19 type RequestStream = StoreRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = StoreSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "examples.keyvaluestore.baseline.Store";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for StoreMarker {}
26pub type StoreWriteItemResult = Result<(), WriteError>;
27
28pub trait StoreProxyInterface: Send + Sync {
29 type WriteItemResponseFut: std::future::Future<Output = Result<StoreWriteItemResult, fidl::Error>>
30 + Send;
31 fn r#write_item(&self, attempt: &Item) -> Self::WriteItemResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct StoreSynchronousProxy {
36 client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for StoreSynchronousProxy {
41 type Proxy = StoreProxy;
42 type Protocol = StoreMarker;
43
44 fn from_channel(inner: fidl::Channel) -> Self {
45 Self::new(inner)
46 }
47
48 fn into_channel(self) -> fidl::Channel {
49 self.client.into_channel()
50 }
51
52 fn as_channel(&self) -> &fidl::Channel {
53 self.client.as_channel()
54 }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl StoreSynchronousProxy {
59 pub fn new(channel: fidl::Channel) -> Self {
60 let protocol_name = <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
61 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
62 }
63
64 pub fn into_channel(self) -> fidl::Channel {
65 self.client.into_channel()
66 }
67
68 pub fn wait_for_event(
71 &self,
72 deadline: zx::MonotonicInstant,
73 ) -> Result<StoreEvent, fidl::Error> {
74 StoreEvent::decode(self.client.wait_for_event(deadline)?)
75 }
76
77 pub fn r#write_item(
79 &self,
80 mut attempt: &Item,
81 ___deadline: zx::MonotonicInstant,
82 ) -> Result<StoreWriteItemResult, fidl::Error> {
83 let _response = self.client.send_query::<
84 StoreWriteItemRequest,
85 fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, WriteError>,
86 >(
87 (attempt,),
88 0x29623dc6b3a4bf63,
89 fidl::encoding::DynamicFlags::FLEXIBLE,
90 ___deadline,
91 )?
92 .into_result::<StoreMarker>("write_item")?;
93 Ok(_response.map(|x| x))
94 }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl From<StoreSynchronousProxy> for zx::Handle {
99 fn from(value: StoreSynchronousProxy) -> Self {
100 value.into_channel().into()
101 }
102}
103
104#[cfg(target_os = "fuchsia")]
105impl From<fidl::Channel> for StoreSynchronousProxy {
106 fn from(value: fidl::Channel) -> Self {
107 Self::new(value)
108 }
109}
110
111#[cfg(target_os = "fuchsia")]
112impl fidl::endpoints::FromClient for StoreSynchronousProxy {
113 type Protocol = StoreMarker;
114
115 fn from_client(value: fidl::endpoints::ClientEnd<StoreMarker>) -> Self {
116 Self::new(value.into_channel())
117 }
118}
119
120#[derive(Debug, Clone)]
121pub struct StoreProxy {
122 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
123}
124
125impl fidl::endpoints::Proxy for StoreProxy {
126 type Protocol = StoreMarker;
127
128 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
129 Self::new(inner)
130 }
131
132 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
133 self.client.into_channel().map_err(|client| Self { client })
134 }
135
136 fn as_channel(&self) -> &::fidl::AsyncChannel {
137 self.client.as_channel()
138 }
139}
140
141impl StoreProxy {
142 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
144 let protocol_name = <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
145 Self { client: fidl::client::Client::new(channel, protocol_name) }
146 }
147
148 pub fn take_event_stream(&self) -> StoreEventStream {
154 StoreEventStream { event_receiver: self.client.take_event_receiver() }
155 }
156
157 pub fn r#write_item(
159 &self,
160 mut attempt: &Item,
161 ) -> fidl::client::QueryResponseFut<
162 StoreWriteItemResult,
163 fidl::encoding::DefaultFuchsiaResourceDialect,
164 > {
165 StoreProxyInterface::r#write_item(self, attempt)
166 }
167}
168
169impl StoreProxyInterface for StoreProxy {
170 type WriteItemResponseFut = fidl::client::QueryResponseFut<
171 StoreWriteItemResult,
172 fidl::encoding::DefaultFuchsiaResourceDialect,
173 >;
174 fn r#write_item(&self, mut attempt: &Item) -> Self::WriteItemResponseFut {
175 fn _decode(
176 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
177 ) -> Result<StoreWriteItemResult, fidl::Error> {
178 let _response = fidl::client::decode_transaction_body::<
179 fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, WriteError>,
180 fidl::encoding::DefaultFuchsiaResourceDialect,
181 0x29623dc6b3a4bf63,
182 >(_buf?)?
183 .into_result::<StoreMarker>("write_item")?;
184 Ok(_response.map(|x| x))
185 }
186 self.client.send_query_and_decode::<StoreWriteItemRequest, StoreWriteItemResult>(
187 (attempt,),
188 0x29623dc6b3a4bf63,
189 fidl::encoding::DynamicFlags::FLEXIBLE,
190 _decode,
191 )
192 }
193}
194
195pub struct StoreEventStream {
196 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
197}
198
199impl std::marker::Unpin for StoreEventStream {}
200
201impl futures::stream::FusedStream for StoreEventStream {
202 fn is_terminated(&self) -> bool {
203 self.event_receiver.is_terminated()
204 }
205}
206
207impl futures::Stream for StoreEventStream {
208 type Item = Result<StoreEvent, fidl::Error>;
209
210 fn poll_next(
211 mut self: std::pin::Pin<&mut Self>,
212 cx: &mut std::task::Context<'_>,
213 ) -> std::task::Poll<Option<Self::Item>> {
214 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
215 &mut self.event_receiver,
216 cx
217 )?) {
218 Some(buf) => std::task::Poll::Ready(Some(StoreEvent::decode(buf))),
219 None => std::task::Poll::Ready(None),
220 }
221 }
222}
223
224#[derive(Debug)]
225pub enum StoreEvent {
226 #[non_exhaustive]
227 _UnknownEvent {
228 ordinal: u64,
230 },
231}
232
233impl StoreEvent {
234 fn decode(
236 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
237 ) -> Result<StoreEvent, fidl::Error> {
238 let (bytes, _handles) = buf.split_mut();
239 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
240 debug_assert_eq!(tx_header.tx_id, 0);
241 match tx_header.ordinal {
242 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
243 Ok(StoreEvent::_UnknownEvent { ordinal: tx_header.ordinal })
244 }
245 _ => Err(fidl::Error::UnknownOrdinal {
246 ordinal: tx_header.ordinal,
247 protocol_name: <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
248 }),
249 }
250 }
251}
252
253pub struct StoreRequestStream {
255 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
256 is_terminated: bool,
257}
258
259impl std::marker::Unpin for StoreRequestStream {}
260
261impl futures::stream::FusedStream for StoreRequestStream {
262 fn is_terminated(&self) -> bool {
263 self.is_terminated
264 }
265}
266
267impl fidl::endpoints::RequestStream for StoreRequestStream {
268 type Protocol = StoreMarker;
269 type ControlHandle = StoreControlHandle;
270
271 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
272 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
273 }
274
275 fn control_handle(&self) -> Self::ControlHandle {
276 StoreControlHandle { inner: self.inner.clone() }
277 }
278
279 fn into_inner(
280 self,
281 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
282 {
283 (self.inner, self.is_terminated)
284 }
285
286 fn from_inner(
287 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
288 is_terminated: bool,
289 ) -> Self {
290 Self { inner, is_terminated }
291 }
292}
293
294impl futures::Stream for StoreRequestStream {
295 type Item = Result<StoreRequest, fidl::Error>;
296
297 fn poll_next(
298 mut self: std::pin::Pin<&mut Self>,
299 cx: &mut std::task::Context<'_>,
300 ) -> std::task::Poll<Option<Self::Item>> {
301 let this = &mut *self;
302 if this.inner.check_shutdown(cx) {
303 this.is_terminated = true;
304 return std::task::Poll::Ready(None);
305 }
306 if this.is_terminated {
307 panic!("polled StoreRequestStream after completion");
308 }
309 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
310 |bytes, handles| {
311 match this.inner.channel().read_etc(cx, bytes, handles) {
312 std::task::Poll::Ready(Ok(())) => {}
313 std::task::Poll::Pending => return std::task::Poll::Pending,
314 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
315 this.is_terminated = true;
316 return std::task::Poll::Ready(None);
317 }
318 std::task::Poll::Ready(Err(e)) => {
319 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
320 e.into(),
321 ))))
322 }
323 }
324
325 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
327
328 std::task::Poll::Ready(Some(match header.ordinal {
329 0x29623dc6b3a4bf63 => {
330 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
331 let mut req = fidl::new_empty!(
332 StoreWriteItemRequest,
333 fidl::encoding::DefaultFuchsiaResourceDialect
334 );
335 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StoreWriteItemRequest>(&header, _body_bytes, handles, &mut req)?;
336 let control_handle = StoreControlHandle { inner: this.inner.clone() };
337 Ok(StoreRequest::WriteItem {
338 attempt: req.attempt,
339
340 responder: StoreWriteItemResponder {
341 control_handle: std::mem::ManuallyDrop::new(control_handle),
342 tx_id: header.tx_id,
343 },
344 })
345 }
346 _ if header.tx_id == 0
347 && header
348 .dynamic_flags()
349 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
350 {
351 Ok(StoreRequest::_UnknownMethod {
352 ordinal: header.ordinal,
353 control_handle: StoreControlHandle { inner: this.inner.clone() },
354 method_type: fidl::MethodType::OneWay,
355 })
356 }
357 _ if header
358 .dynamic_flags()
359 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
360 {
361 this.inner.send_framework_err(
362 fidl::encoding::FrameworkErr::UnknownMethod,
363 header.tx_id,
364 header.ordinal,
365 header.dynamic_flags(),
366 (bytes, handles),
367 )?;
368 Ok(StoreRequest::_UnknownMethod {
369 ordinal: header.ordinal,
370 control_handle: StoreControlHandle { inner: this.inner.clone() },
371 method_type: fidl::MethodType::TwoWay,
372 })
373 }
374 _ => Err(fidl::Error::UnknownOrdinal {
375 ordinal: header.ordinal,
376 protocol_name: <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
377 }),
378 }))
379 },
380 )
381 }
382}
383
384#[derive(Debug)]
386pub enum StoreRequest {
387 WriteItem { attempt: Item, responder: StoreWriteItemResponder },
389 #[non_exhaustive]
391 _UnknownMethod {
392 ordinal: u64,
394 control_handle: StoreControlHandle,
395 method_type: fidl::MethodType,
396 },
397}
398
399impl StoreRequest {
400 #[allow(irrefutable_let_patterns)]
401 pub fn into_write_item(self) -> Option<(Item, StoreWriteItemResponder)> {
402 if let StoreRequest::WriteItem { attempt, responder } = self {
403 Some((attempt, responder))
404 } else {
405 None
406 }
407 }
408
409 pub fn method_name(&self) -> &'static str {
411 match *self {
412 StoreRequest::WriteItem { .. } => "write_item",
413 StoreRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
414 "unknown one-way method"
415 }
416 StoreRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
417 "unknown two-way method"
418 }
419 }
420 }
421}
422
423#[derive(Debug, Clone)]
424pub struct StoreControlHandle {
425 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
426}
427
428impl fidl::endpoints::ControlHandle for StoreControlHandle {
429 fn shutdown(&self) {
430 self.inner.shutdown()
431 }
432 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
433 self.inner.shutdown_with_epitaph(status)
434 }
435
436 fn is_closed(&self) -> bool {
437 self.inner.channel().is_closed()
438 }
439 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
440 self.inner.channel().on_closed()
441 }
442
443 #[cfg(target_os = "fuchsia")]
444 fn signal_peer(
445 &self,
446 clear_mask: zx::Signals,
447 set_mask: zx::Signals,
448 ) -> Result<(), zx_status::Status> {
449 use fidl::Peered;
450 self.inner.channel().signal_peer(clear_mask, set_mask)
451 }
452}
453
454impl StoreControlHandle {}
455
456#[must_use = "FIDL methods require a response to be sent"]
457#[derive(Debug)]
458pub struct StoreWriteItemResponder {
459 control_handle: std::mem::ManuallyDrop<StoreControlHandle>,
460 tx_id: u32,
461}
462
463impl std::ops::Drop for StoreWriteItemResponder {
467 fn drop(&mut self) {
468 self.control_handle.shutdown();
469 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
471 }
472}
473
474impl fidl::endpoints::Responder for StoreWriteItemResponder {
475 type ControlHandle = StoreControlHandle;
476
477 fn control_handle(&self) -> &StoreControlHandle {
478 &self.control_handle
479 }
480
481 fn drop_without_shutdown(mut self) {
482 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
484 std::mem::forget(self);
486 }
487}
488
489impl StoreWriteItemResponder {
490 pub fn send(self, mut result: Result<(), WriteError>) -> Result<(), fidl::Error> {
494 let _result = self.send_raw(result);
495 if _result.is_err() {
496 self.control_handle.shutdown();
497 }
498 self.drop_without_shutdown();
499 _result
500 }
501
502 pub fn send_no_shutdown_on_err(
504 self,
505 mut result: Result<(), WriteError>,
506 ) -> Result<(), fidl::Error> {
507 let _result = self.send_raw(result);
508 self.drop_without_shutdown();
509 _result
510 }
511
512 fn send_raw(&self, mut result: Result<(), WriteError>) -> Result<(), fidl::Error> {
513 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
514 fidl::encoding::EmptyStruct,
515 WriteError,
516 >>(
517 fidl::encoding::FlexibleResult::new(result),
518 self.tx_id,
519 0x29623dc6b3a4bf63,
520 fidl::encoding::DynamicFlags::FLEXIBLE,
521 )
522 }
523}
524
525mod internal {
526 use super::*;
527}