1#![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_addreaditem_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.addreaditem.Store";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for StoreMarker {}
26pub type StoreWriteItemResult = Result<(), WriteError>;
27pub type StoreReadItemResult = Result<(String, Vec<u8>), ReadError>;
28
29pub trait StoreProxyInterface: Send + Sync {
30 type WriteItemResponseFut: std::future::Future<Output = Result<StoreWriteItemResult, fidl::Error>>
31 + Send;
32 fn r#write_item(&self, attempt: &Item) -> Self::WriteItemResponseFut;
33 type ReadItemResponseFut: std::future::Future<Output = Result<StoreReadItemResult, fidl::Error>>
34 + Send;
35 fn r#read_item(&self, key: &str) -> Self::ReadItemResponseFut;
36}
37#[derive(Debug)]
38#[cfg(target_os = "fuchsia")]
39pub struct StoreSynchronousProxy {
40 client: fidl::client::sync::Client,
41}
42
43#[cfg(target_os = "fuchsia")]
44impl fidl::endpoints::SynchronousProxy for StoreSynchronousProxy {
45 type Proxy = StoreProxy;
46 type Protocol = StoreMarker;
47
48 fn from_channel(inner: fidl::Channel) -> Self {
49 Self::new(inner)
50 }
51
52 fn into_channel(self) -> fidl::Channel {
53 self.client.into_channel()
54 }
55
56 fn as_channel(&self) -> &fidl::Channel {
57 self.client.as_channel()
58 }
59}
60
61#[cfg(target_os = "fuchsia")]
62impl StoreSynchronousProxy {
63 pub fn new(channel: fidl::Channel) -> Self {
64 let protocol_name = <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
65 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
66 }
67
68 pub fn into_channel(self) -> fidl::Channel {
69 self.client.into_channel()
70 }
71
72 pub fn wait_for_event(
75 &self,
76 deadline: zx::MonotonicInstant,
77 ) -> Result<StoreEvent, fidl::Error> {
78 StoreEvent::decode(self.client.wait_for_event(deadline)?)
79 }
80
81 pub fn r#write_item(
83 &self,
84 mut attempt: &Item,
85 ___deadline: zx::MonotonicInstant,
86 ) -> Result<StoreWriteItemResult, fidl::Error> {
87 let _response = self.client.send_query::<
88 StoreWriteItemRequest,
89 fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, WriteError>,
90 >(
91 (attempt,),
92 0x4dd6bb122b2022e9,
93 fidl::encoding::DynamicFlags::FLEXIBLE,
94 ___deadline,
95 )?
96 .into_result::<StoreMarker>("write_item")?;
97 Ok(_response.map(|x| x))
98 }
99
100 pub fn r#read_item(
102 &self,
103 mut key: &str,
104 ___deadline: zx::MonotonicInstant,
105 ) -> Result<StoreReadItemResult, fidl::Error> {
106 let _response = self.client.send_query::<
107 StoreReadItemRequest,
108 fidl::encoding::FlexibleResultType<Item, ReadError>,
109 >(
110 (key,),
111 0x67a246d566d1139c,
112 fidl::encoding::DynamicFlags::FLEXIBLE,
113 ___deadline,
114 )?
115 .into_result::<StoreMarker>("read_item")?;
116 Ok(_response.map(|x| (x.key, x.value)))
117 }
118}
119
120#[cfg(target_os = "fuchsia")]
121impl From<StoreSynchronousProxy> for zx::Handle {
122 fn from(value: StoreSynchronousProxy) -> Self {
123 value.into_channel().into()
124 }
125}
126
127#[cfg(target_os = "fuchsia")]
128impl From<fidl::Channel> for StoreSynchronousProxy {
129 fn from(value: fidl::Channel) -> Self {
130 Self::new(value)
131 }
132}
133
134#[derive(Debug, Clone)]
135pub struct StoreProxy {
136 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
137}
138
139impl fidl::endpoints::Proxy for StoreProxy {
140 type Protocol = StoreMarker;
141
142 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
143 Self::new(inner)
144 }
145
146 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
147 self.client.into_channel().map_err(|client| Self { client })
148 }
149
150 fn as_channel(&self) -> &::fidl::AsyncChannel {
151 self.client.as_channel()
152 }
153}
154
155impl StoreProxy {
156 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
158 let protocol_name = <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
159 Self { client: fidl::client::Client::new(channel, protocol_name) }
160 }
161
162 pub fn take_event_stream(&self) -> StoreEventStream {
168 StoreEventStream { event_receiver: self.client.take_event_receiver() }
169 }
170
171 pub fn r#write_item(
173 &self,
174 mut attempt: &Item,
175 ) -> fidl::client::QueryResponseFut<
176 StoreWriteItemResult,
177 fidl::encoding::DefaultFuchsiaResourceDialect,
178 > {
179 StoreProxyInterface::r#write_item(self, attempt)
180 }
181
182 pub fn r#read_item(
184 &self,
185 mut key: &str,
186 ) -> fidl::client::QueryResponseFut<
187 StoreReadItemResult,
188 fidl::encoding::DefaultFuchsiaResourceDialect,
189 > {
190 StoreProxyInterface::r#read_item(self, key)
191 }
192}
193
194impl StoreProxyInterface for StoreProxy {
195 type WriteItemResponseFut = fidl::client::QueryResponseFut<
196 StoreWriteItemResult,
197 fidl::encoding::DefaultFuchsiaResourceDialect,
198 >;
199 fn r#write_item(&self, mut attempt: &Item) -> Self::WriteItemResponseFut {
200 fn _decode(
201 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
202 ) -> Result<StoreWriteItemResult, fidl::Error> {
203 let _response = fidl::client::decode_transaction_body::<
204 fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, WriteError>,
205 fidl::encoding::DefaultFuchsiaResourceDialect,
206 0x4dd6bb122b2022e9,
207 >(_buf?)?
208 .into_result::<StoreMarker>("write_item")?;
209 Ok(_response.map(|x| x))
210 }
211 self.client.send_query_and_decode::<StoreWriteItemRequest, StoreWriteItemResult>(
212 (attempt,),
213 0x4dd6bb122b2022e9,
214 fidl::encoding::DynamicFlags::FLEXIBLE,
215 _decode,
216 )
217 }
218
219 type ReadItemResponseFut = fidl::client::QueryResponseFut<
220 StoreReadItemResult,
221 fidl::encoding::DefaultFuchsiaResourceDialect,
222 >;
223 fn r#read_item(&self, mut key: &str) -> Self::ReadItemResponseFut {
224 fn _decode(
225 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
226 ) -> Result<StoreReadItemResult, fidl::Error> {
227 let _response = fidl::client::decode_transaction_body::<
228 fidl::encoding::FlexibleResultType<Item, ReadError>,
229 fidl::encoding::DefaultFuchsiaResourceDialect,
230 0x67a246d566d1139c,
231 >(_buf?)?
232 .into_result::<StoreMarker>("read_item")?;
233 Ok(_response.map(|x| (x.key, x.value)))
234 }
235 self.client.send_query_and_decode::<StoreReadItemRequest, StoreReadItemResult>(
236 (key,),
237 0x67a246d566d1139c,
238 fidl::encoding::DynamicFlags::FLEXIBLE,
239 _decode,
240 )
241 }
242}
243
244pub struct StoreEventStream {
245 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
246}
247
248impl std::marker::Unpin for StoreEventStream {}
249
250impl futures::stream::FusedStream for StoreEventStream {
251 fn is_terminated(&self) -> bool {
252 self.event_receiver.is_terminated()
253 }
254}
255
256impl futures::Stream for StoreEventStream {
257 type Item = Result<StoreEvent, fidl::Error>;
258
259 fn poll_next(
260 mut self: std::pin::Pin<&mut Self>,
261 cx: &mut std::task::Context<'_>,
262 ) -> std::task::Poll<Option<Self::Item>> {
263 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
264 &mut self.event_receiver,
265 cx
266 )?) {
267 Some(buf) => std::task::Poll::Ready(Some(StoreEvent::decode(buf))),
268 None => std::task::Poll::Ready(None),
269 }
270 }
271}
272
273#[derive(Debug)]
274pub enum StoreEvent {
275 #[non_exhaustive]
276 _UnknownEvent {
277 ordinal: u64,
279 },
280}
281
282impl StoreEvent {
283 fn decode(
285 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
286 ) -> Result<StoreEvent, fidl::Error> {
287 let (bytes, _handles) = buf.split_mut();
288 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
289 debug_assert_eq!(tx_header.tx_id, 0);
290 match tx_header.ordinal {
291 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
292 Ok(StoreEvent::_UnknownEvent { ordinal: tx_header.ordinal })
293 }
294 _ => Err(fidl::Error::UnknownOrdinal {
295 ordinal: tx_header.ordinal,
296 protocol_name: <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
297 }),
298 }
299 }
300}
301
302pub struct StoreRequestStream {
304 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
305 is_terminated: bool,
306}
307
308impl std::marker::Unpin for StoreRequestStream {}
309
310impl futures::stream::FusedStream for StoreRequestStream {
311 fn is_terminated(&self) -> bool {
312 self.is_terminated
313 }
314}
315
316impl fidl::endpoints::RequestStream for StoreRequestStream {
317 type Protocol = StoreMarker;
318 type ControlHandle = StoreControlHandle;
319
320 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
321 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
322 }
323
324 fn control_handle(&self) -> Self::ControlHandle {
325 StoreControlHandle { inner: self.inner.clone() }
326 }
327
328 fn into_inner(
329 self,
330 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
331 {
332 (self.inner, self.is_terminated)
333 }
334
335 fn from_inner(
336 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
337 is_terminated: bool,
338 ) -> Self {
339 Self { inner, is_terminated }
340 }
341}
342
343impl futures::Stream for StoreRequestStream {
344 type Item = Result<StoreRequest, fidl::Error>;
345
346 fn poll_next(
347 mut self: std::pin::Pin<&mut Self>,
348 cx: &mut std::task::Context<'_>,
349 ) -> std::task::Poll<Option<Self::Item>> {
350 let this = &mut *self;
351 if this.inner.check_shutdown(cx) {
352 this.is_terminated = true;
353 return std::task::Poll::Ready(None);
354 }
355 if this.is_terminated {
356 panic!("polled StoreRequestStream after completion");
357 }
358 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
359 |bytes, handles| {
360 match this.inner.channel().read_etc(cx, bytes, handles) {
361 std::task::Poll::Ready(Ok(())) => {}
362 std::task::Poll::Pending => return std::task::Poll::Pending,
363 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
364 this.is_terminated = true;
365 return std::task::Poll::Ready(None);
366 }
367 std::task::Poll::Ready(Err(e)) => {
368 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
369 e.into(),
370 ))))
371 }
372 }
373
374 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
376
377 std::task::Poll::Ready(Some(match header.ordinal {
378 0x4dd6bb122b2022e9 => {
379 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
380 let mut req = fidl::new_empty!(
381 StoreWriteItemRequest,
382 fidl::encoding::DefaultFuchsiaResourceDialect
383 );
384 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StoreWriteItemRequest>(&header, _body_bytes, handles, &mut req)?;
385 let control_handle = StoreControlHandle { inner: this.inner.clone() };
386 Ok(StoreRequest::WriteItem {
387 attempt: req.attempt,
388
389 responder: StoreWriteItemResponder {
390 control_handle: std::mem::ManuallyDrop::new(control_handle),
391 tx_id: header.tx_id,
392 },
393 })
394 }
395 0x67a246d566d1139c => {
396 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
397 let mut req = fidl::new_empty!(
398 StoreReadItemRequest,
399 fidl::encoding::DefaultFuchsiaResourceDialect
400 );
401 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StoreReadItemRequest>(&header, _body_bytes, handles, &mut req)?;
402 let control_handle = StoreControlHandle { inner: this.inner.clone() };
403 Ok(StoreRequest::ReadItem {
404 key: req.key,
405
406 responder: StoreReadItemResponder {
407 control_handle: std::mem::ManuallyDrop::new(control_handle),
408 tx_id: header.tx_id,
409 },
410 })
411 }
412 _ if header.tx_id == 0
413 && header
414 .dynamic_flags()
415 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
416 {
417 Ok(StoreRequest::_UnknownMethod {
418 ordinal: header.ordinal,
419 control_handle: StoreControlHandle { inner: this.inner.clone() },
420 method_type: fidl::MethodType::OneWay,
421 })
422 }
423 _ if header
424 .dynamic_flags()
425 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
426 {
427 this.inner.send_framework_err(
428 fidl::encoding::FrameworkErr::UnknownMethod,
429 header.tx_id,
430 header.ordinal,
431 header.dynamic_flags(),
432 (bytes, handles),
433 )?;
434 Ok(StoreRequest::_UnknownMethod {
435 ordinal: header.ordinal,
436 control_handle: StoreControlHandle { inner: this.inner.clone() },
437 method_type: fidl::MethodType::TwoWay,
438 })
439 }
440 _ => Err(fidl::Error::UnknownOrdinal {
441 ordinal: header.ordinal,
442 protocol_name: <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
443 }),
444 }))
445 },
446 )
447 }
448}
449
450#[derive(Debug)]
452pub enum StoreRequest {
453 WriteItem { attempt: Item, responder: StoreWriteItemResponder },
455 ReadItem { key: String, responder: StoreReadItemResponder },
457 #[non_exhaustive]
459 _UnknownMethod {
460 ordinal: u64,
462 control_handle: StoreControlHandle,
463 method_type: fidl::MethodType,
464 },
465}
466
467impl StoreRequest {
468 #[allow(irrefutable_let_patterns)]
469 pub fn into_write_item(self) -> Option<(Item, StoreWriteItemResponder)> {
470 if let StoreRequest::WriteItem { attempt, responder } = self {
471 Some((attempt, responder))
472 } else {
473 None
474 }
475 }
476
477 #[allow(irrefutable_let_patterns)]
478 pub fn into_read_item(self) -> Option<(String, StoreReadItemResponder)> {
479 if let StoreRequest::ReadItem { key, responder } = self {
480 Some((key, responder))
481 } else {
482 None
483 }
484 }
485
486 pub fn method_name(&self) -> &'static str {
488 match *self {
489 StoreRequest::WriteItem { .. } => "write_item",
490 StoreRequest::ReadItem { .. } => "read_item",
491 StoreRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
492 "unknown one-way method"
493 }
494 StoreRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
495 "unknown two-way method"
496 }
497 }
498 }
499}
500
501#[derive(Debug, Clone)]
502pub struct StoreControlHandle {
503 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
504}
505
506impl fidl::endpoints::ControlHandle for StoreControlHandle {
507 fn shutdown(&self) {
508 self.inner.shutdown()
509 }
510 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
511 self.inner.shutdown_with_epitaph(status)
512 }
513
514 fn is_closed(&self) -> bool {
515 self.inner.channel().is_closed()
516 }
517 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
518 self.inner.channel().on_closed()
519 }
520
521 #[cfg(target_os = "fuchsia")]
522 fn signal_peer(
523 &self,
524 clear_mask: zx::Signals,
525 set_mask: zx::Signals,
526 ) -> Result<(), zx_status::Status> {
527 use fidl::Peered;
528 self.inner.channel().signal_peer(clear_mask, set_mask)
529 }
530}
531
532impl StoreControlHandle {}
533
534#[must_use = "FIDL methods require a response to be sent"]
535#[derive(Debug)]
536pub struct StoreWriteItemResponder {
537 control_handle: std::mem::ManuallyDrop<StoreControlHandle>,
538 tx_id: u32,
539}
540
541impl std::ops::Drop for StoreWriteItemResponder {
545 fn drop(&mut self) {
546 self.control_handle.shutdown();
547 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
549 }
550}
551
552impl fidl::endpoints::Responder for StoreWriteItemResponder {
553 type ControlHandle = StoreControlHandle;
554
555 fn control_handle(&self) -> &StoreControlHandle {
556 &self.control_handle
557 }
558
559 fn drop_without_shutdown(mut self) {
560 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
562 std::mem::forget(self);
564 }
565}
566
567impl StoreWriteItemResponder {
568 pub fn send(self, mut result: Result<(), WriteError>) -> Result<(), fidl::Error> {
572 let _result = self.send_raw(result);
573 if _result.is_err() {
574 self.control_handle.shutdown();
575 }
576 self.drop_without_shutdown();
577 _result
578 }
579
580 pub fn send_no_shutdown_on_err(
582 self,
583 mut result: Result<(), WriteError>,
584 ) -> Result<(), fidl::Error> {
585 let _result = self.send_raw(result);
586 self.drop_without_shutdown();
587 _result
588 }
589
590 fn send_raw(&self, mut result: Result<(), WriteError>) -> Result<(), fidl::Error> {
591 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
592 fidl::encoding::EmptyStruct,
593 WriteError,
594 >>(
595 fidl::encoding::FlexibleResult::new(result),
596 self.tx_id,
597 0x4dd6bb122b2022e9,
598 fidl::encoding::DynamicFlags::FLEXIBLE,
599 )
600 }
601}
602
603#[must_use = "FIDL methods require a response to be sent"]
604#[derive(Debug)]
605pub struct StoreReadItemResponder {
606 control_handle: std::mem::ManuallyDrop<StoreControlHandle>,
607 tx_id: u32,
608}
609
610impl std::ops::Drop for StoreReadItemResponder {
614 fn drop(&mut self) {
615 self.control_handle.shutdown();
616 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
618 }
619}
620
621impl fidl::endpoints::Responder for StoreReadItemResponder {
622 type ControlHandle = StoreControlHandle;
623
624 fn control_handle(&self) -> &StoreControlHandle {
625 &self.control_handle
626 }
627
628 fn drop_without_shutdown(mut self) {
629 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
631 std::mem::forget(self);
633 }
634}
635
636impl StoreReadItemResponder {
637 pub fn send(self, mut result: Result<(&str, &[u8]), ReadError>) -> Result<(), fidl::Error> {
641 let _result = self.send_raw(result);
642 if _result.is_err() {
643 self.control_handle.shutdown();
644 }
645 self.drop_without_shutdown();
646 _result
647 }
648
649 pub fn send_no_shutdown_on_err(
651 self,
652 mut result: Result<(&str, &[u8]), ReadError>,
653 ) -> Result<(), fidl::Error> {
654 let _result = self.send_raw(result);
655 self.drop_without_shutdown();
656 _result
657 }
658
659 fn send_raw(&self, mut result: Result<(&str, &[u8]), ReadError>) -> Result<(), fidl::Error> {
660 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<Item, ReadError>>(
661 fidl::encoding::FlexibleResult::new(result),
662 self.tx_id,
663 0x67a246d566d1139c,
664 fidl::encoding::DynamicFlags::FLEXIBLE,
665 )
666 }
667}
668
669mod internal {
670 use super::*;
671}