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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub enum WriteError {
16 Unknown,
17 InvalidKey,
18 InvalidValue,
19 AlreadyExists,
20 #[doc(hidden)]
21 __SourceBreaking {
22 unknown_ordinal: u32,
23 },
24}
25
26#[macro_export]
28macro_rules! WriteErrorUnknown {
29 () => {
30 _
31 };
32}
33
34impl WriteError {
35 #[inline]
36 pub fn from_primitive(prim: u32) -> Option<Self> {
37 match prim {
38 0 => Some(Self::Unknown),
39 1 => Some(Self::InvalidKey),
40 2 => Some(Self::InvalidValue),
41 3 => Some(Self::AlreadyExists),
42 _ => None,
43 }
44 }
45
46 #[inline]
47 pub fn from_primitive_allow_unknown(prim: u32) -> Self {
48 match prim {
49 0 => Self::Unknown,
50 1 => Self::InvalidKey,
51 2 => Self::InvalidValue,
52 3 => Self::AlreadyExists,
53 unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
54 }
55 }
56
57 #[inline]
58 pub fn unknown() -> Self {
59 Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
60 }
61
62 #[inline]
63 pub const fn into_primitive(self) -> u32 {
64 match self {
65 Self::Unknown => 0,
66 Self::InvalidKey => 1,
67 Self::InvalidValue => 2,
68 Self::AlreadyExists => 3,
69 Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
70 }
71 }
72
73 #[inline]
74 pub fn is_unknown(&self) -> bool {
75 match self {
76 Self::__SourceBreaking { unknown_ordinal: _ } => true,
77 _ => false,
78 }
79 }
80}
81
82#[derive(Clone, Debug, PartialEq)]
86pub struct Item {
87 pub key: String,
88 pub value: Option<Box<Value>>,
89}
90
91impl fidl::Persistable for Item {}
92
93#[derive(Clone, Debug, PartialEq)]
94pub struct StoreWriteItemRequest {
95 pub attempt: Item,
96}
97
98impl fidl::Persistable for StoreWriteItemRequest {}
99
100#[derive(Clone, Debug, Default, PartialEq)]
101pub struct NestedStore {
102 pub items: Option<Vec<Option<Box<Item>>>>,
103 #[doc(hidden)]
104 pub __source_breaking: fidl::marker::SourceBreaking,
105}
106
107impl fidl::Persistable for NestedStore {}
108
109#[derive(Clone, Debug, PartialEq)]
110pub enum Value {
111 Bytes(Vec<u8>),
112 Store(NestedStore),
113}
114
115impl Value {
116 #[inline]
117 pub fn ordinal(&self) -> u64 {
118 match *self {
119 Self::Bytes(_) => 1,
120 Self::Store(_) => 2,
121 }
122 }
123
124 #[deprecated = "Strict unions should not use `is_unknown`"]
125 #[inline]
126 pub fn is_unknown(&self) -> bool {
127 false
128 }
129}
130
131impl fidl::Persistable for Value {}
132
133#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
134pub struct StoreMarker;
135
136impl fidl::endpoints::ProtocolMarker for StoreMarker {
137 type Proxy = StoreProxy;
138 type RequestStream = StoreRequestStream;
139 #[cfg(target_os = "fuchsia")]
140 type SynchronousProxy = StoreSynchronousProxy;
141
142 const DEBUG_NAME: &'static str = "examples.keyvaluestore.supporttrees.Store";
143}
144impl fidl::endpoints::DiscoverableProtocolMarker for StoreMarker {}
145pub type StoreWriteItemResult = Result<(), WriteError>;
146
147pub trait StoreProxyInterface: Send + Sync {
148 type WriteItemResponseFut: std::future::Future<Output = Result<StoreWriteItemResult, fidl::Error>>
149 + Send;
150 fn r#write_item(&self, attempt: &Item) -> Self::WriteItemResponseFut;
151}
152#[derive(Debug)]
153#[cfg(target_os = "fuchsia")]
154pub struct StoreSynchronousProxy {
155 client: fidl::client::sync::Client,
156}
157
158#[cfg(target_os = "fuchsia")]
159impl fidl::endpoints::SynchronousProxy for StoreSynchronousProxy {
160 type Proxy = StoreProxy;
161 type Protocol = StoreMarker;
162
163 fn from_channel(inner: fidl::Channel) -> Self {
164 Self::new(inner)
165 }
166
167 fn into_channel(self) -> fidl::Channel {
168 self.client.into_channel()
169 }
170
171 fn as_channel(&self) -> &fidl::Channel {
172 self.client.as_channel()
173 }
174}
175
176#[cfg(target_os = "fuchsia")]
177impl StoreSynchronousProxy {
178 pub fn new(channel: fidl::Channel) -> Self {
179 let protocol_name = <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
180 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
181 }
182
183 pub fn into_channel(self) -> fidl::Channel {
184 self.client.into_channel()
185 }
186
187 pub fn wait_for_event(
190 &self,
191 deadline: zx::MonotonicInstant,
192 ) -> Result<StoreEvent, fidl::Error> {
193 StoreEvent::decode(self.client.wait_for_event(deadline)?)
194 }
195
196 pub fn r#write_item(
198 &self,
199 mut attempt: &Item,
200 ___deadline: zx::MonotonicInstant,
201 ) -> Result<StoreWriteItemResult, fidl::Error> {
202 let _response = self.client.send_query::<
203 StoreWriteItemRequest,
204 fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, WriteError>,
205 >(
206 (attempt,),
207 0x4a01d5d999e00aa2,
208 fidl::encoding::DynamicFlags::FLEXIBLE,
209 ___deadline,
210 )?
211 .into_result::<StoreMarker>("write_item")?;
212 Ok(_response.map(|x| x))
213 }
214}
215
216#[derive(Debug, Clone)]
217pub struct StoreProxy {
218 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
219}
220
221impl fidl::endpoints::Proxy for StoreProxy {
222 type Protocol = StoreMarker;
223
224 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
225 Self::new(inner)
226 }
227
228 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
229 self.client.into_channel().map_err(|client| Self { client })
230 }
231
232 fn as_channel(&self) -> &::fidl::AsyncChannel {
233 self.client.as_channel()
234 }
235}
236
237impl StoreProxy {
238 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
240 let protocol_name = <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
241 Self { client: fidl::client::Client::new(channel, protocol_name) }
242 }
243
244 pub fn take_event_stream(&self) -> StoreEventStream {
250 StoreEventStream { event_receiver: self.client.take_event_receiver() }
251 }
252
253 pub fn r#write_item(
255 &self,
256 mut attempt: &Item,
257 ) -> fidl::client::QueryResponseFut<
258 StoreWriteItemResult,
259 fidl::encoding::DefaultFuchsiaResourceDialect,
260 > {
261 StoreProxyInterface::r#write_item(self, attempt)
262 }
263}
264
265impl StoreProxyInterface for StoreProxy {
266 type WriteItemResponseFut = fidl::client::QueryResponseFut<
267 StoreWriteItemResult,
268 fidl::encoding::DefaultFuchsiaResourceDialect,
269 >;
270 fn r#write_item(&self, mut attempt: &Item) -> Self::WriteItemResponseFut {
271 fn _decode(
272 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
273 ) -> Result<StoreWriteItemResult, fidl::Error> {
274 let _response = fidl::client::decode_transaction_body::<
275 fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, WriteError>,
276 fidl::encoding::DefaultFuchsiaResourceDialect,
277 0x4a01d5d999e00aa2,
278 >(_buf?)?
279 .into_result::<StoreMarker>("write_item")?;
280 Ok(_response.map(|x| x))
281 }
282 self.client.send_query_and_decode::<StoreWriteItemRequest, StoreWriteItemResult>(
283 (attempt,),
284 0x4a01d5d999e00aa2,
285 fidl::encoding::DynamicFlags::FLEXIBLE,
286 _decode,
287 )
288 }
289}
290
291pub struct StoreEventStream {
292 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
293}
294
295impl std::marker::Unpin for StoreEventStream {}
296
297impl futures::stream::FusedStream for StoreEventStream {
298 fn is_terminated(&self) -> bool {
299 self.event_receiver.is_terminated()
300 }
301}
302
303impl futures::Stream for StoreEventStream {
304 type Item = Result<StoreEvent, fidl::Error>;
305
306 fn poll_next(
307 mut self: std::pin::Pin<&mut Self>,
308 cx: &mut std::task::Context<'_>,
309 ) -> std::task::Poll<Option<Self::Item>> {
310 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
311 &mut self.event_receiver,
312 cx
313 )?) {
314 Some(buf) => std::task::Poll::Ready(Some(StoreEvent::decode(buf))),
315 None => std::task::Poll::Ready(None),
316 }
317 }
318}
319
320#[derive(Debug)]
321pub enum StoreEvent {
322 #[non_exhaustive]
323 _UnknownEvent {
324 ordinal: u64,
326 },
327}
328
329impl StoreEvent {
330 fn decode(
332 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
333 ) -> Result<StoreEvent, fidl::Error> {
334 let (bytes, _handles) = buf.split_mut();
335 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
336 debug_assert_eq!(tx_header.tx_id, 0);
337 match tx_header.ordinal {
338 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
339 Ok(StoreEvent::_UnknownEvent { ordinal: tx_header.ordinal })
340 }
341 _ => Err(fidl::Error::UnknownOrdinal {
342 ordinal: tx_header.ordinal,
343 protocol_name: <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
344 }),
345 }
346 }
347}
348
349pub struct StoreRequestStream {
351 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
352 is_terminated: bool,
353}
354
355impl std::marker::Unpin for StoreRequestStream {}
356
357impl futures::stream::FusedStream for StoreRequestStream {
358 fn is_terminated(&self) -> bool {
359 self.is_terminated
360 }
361}
362
363impl fidl::endpoints::RequestStream for StoreRequestStream {
364 type Protocol = StoreMarker;
365 type ControlHandle = StoreControlHandle;
366
367 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
368 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
369 }
370
371 fn control_handle(&self) -> Self::ControlHandle {
372 StoreControlHandle { inner: self.inner.clone() }
373 }
374
375 fn into_inner(
376 self,
377 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
378 {
379 (self.inner, self.is_terminated)
380 }
381
382 fn from_inner(
383 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
384 is_terminated: bool,
385 ) -> Self {
386 Self { inner, is_terminated }
387 }
388}
389
390impl futures::Stream for StoreRequestStream {
391 type Item = Result<StoreRequest, fidl::Error>;
392
393 fn poll_next(
394 mut self: std::pin::Pin<&mut Self>,
395 cx: &mut std::task::Context<'_>,
396 ) -> std::task::Poll<Option<Self::Item>> {
397 let this = &mut *self;
398 if this.inner.check_shutdown(cx) {
399 this.is_terminated = true;
400 return std::task::Poll::Ready(None);
401 }
402 if this.is_terminated {
403 panic!("polled StoreRequestStream after completion");
404 }
405 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
406 |bytes, handles| {
407 match this.inner.channel().read_etc(cx, bytes, handles) {
408 std::task::Poll::Ready(Ok(())) => {}
409 std::task::Poll::Pending => return std::task::Poll::Pending,
410 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
411 this.is_terminated = true;
412 return std::task::Poll::Ready(None);
413 }
414 std::task::Poll::Ready(Err(e)) => {
415 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
416 e.into(),
417 ))))
418 }
419 }
420
421 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
423
424 std::task::Poll::Ready(Some(match header.ordinal {
425 0x4a01d5d999e00aa2 => {
426 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
427 let mut req = fidl::new_empty!(
428 StoreWriteItemRequest,
429 fidl::encoding::DefaultFuchsiaResourceDialect
430 );
431 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StoreWriteItemRequest>(&header, _body_bytes, handles, &mut req)?;
432 let control_handle = StoreControlHandle { inner: this.inner.clone() };
433 Ok(StoreRequest::WriteItem {
434 attempt: req.attempt,
435
436 responder: StoreWriteItemResponder {
437 control_handle: std::mem::ManuallyDrop::new(control_handle),
438 tx_id: header.tx_id,
439 },
440 })
441 }
442 _ if header.tx_id == 0
443 && header
444 .dynamic_flags()
445 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
446 {
447 Ok(StoreRequest::_UnknownMethod {
448 ordinal: header.ordinal,
449 control_handle: StoreControlHandle { inner: this.inner.clone() },
450 method_type: fidl::MethodType::OneWay,
451 })
452 }
453 _ if header
454 .dynamic_flags()
455 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
456 {
457 this.inner.send_framework_err(
458 fidl::encoding::FrameworkErr::UnknownMethod,
459 header.tx_id,
460 header.ordinal,
461 header.dynamic_flags(),
462 (bytes, handles),
463 )?;
464 Ok(StoreRequest::_UnknownMethod {
465 ordinal: header.ordinal,
466 control_handle: StoreControlHandle { inner: this.inner.clone() },
467 method_type: fidl::MethodType::TwoWay,
468 })
469 }
470 _ => Err(fidl::Error::UnknownOrdinal {
471 ordinal: header.ordinal,
472 protocol_name: <StoreMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
473 }),
474 }))
475 },
476 )
477 }
478}
479
480#[derive(Debug)]
482pub enum StoreRequest {
483 WriteItem { attempt: Item, responder: StoreWriteItemResponder },
485 #[non_exhaustive]
487 _UnknownMethod {
488 ordinal: u64,
490 control_handle: StoreControlHandle,
491 method_type: fidl::MethodType,
492 },
493}
494
495impl StoreRequest {
496 #[allow(irrefutable_let_patterns)]
497 pub fn into_write_item(self) -> Option<(Item, StoreWriteItemResponder)> {
498 if let StoreRequest::WriteItem { attempt, responder } = self {
499 Some((attempt, responder))
500 } else {
501 None
502 }
503 }
504
505 pub fn method_name(&self) -> &'static str {
507 match *self {
508 StoreRequest::WriteItem { .. } => "write_item",
509 StoreRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
510 "unknown one-way method"
511 }
512 StoreRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
513 "unknown two-way method"
514 }
515 }
516 }
517}
518
519#[derive(Debug, Clone)]
520pub struct StoreControlHandle {
521 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
522}
523
524impl fidl::endpoints::ControlHandle for StoreControlHandle {
525 fn shutdown(&self) {
526 self.inner.shutdown()
527 }
528 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
529 self.inner.shutdown_with_epitaph(status)
530 }
531
532 fn is_closed(&self) -> bool {
533 self.inner.channel().is_closed()
534 }
535 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
536 self.inner.channel().on_closed()
537 }
538
539 #[cfg(target_os = "fuchsia")]
540 fn signal_peer(
541 &self,
542 clear_mask: zx::Signals,
543 set_mask: zx::Signals,
544 ) -> Result<(), zx_status::Status> {
545 use fidl::Peered;
546 self.inner.channel().signal_peer(clear_mask, set_mask)
547 }
548}
549
550impl StoreControlHandle {}
551
552#[must_use = "FIDL methods require a response to be sent"]
553#[derive(Debug)]
554pub struct StoreWriteItemResponder {
555 control_handle: std::mem::ManuallyDrop<StoreControlHandle>,
556 tx_id: u32,
557}
558
559impl std::ops::Drop for StoreWriteItemResponder {
563 fn drop(&mut self) {
564 self.control_handle.shutdown();
565 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
567 }
568}
569
570impl fidl::endpoints::Responder for StoreWriteItemResponder {
571 type ControlHandle = StoreControlHandle;
572
573 fn control_handle(&self) -> &StoreControlHandle {
574 &self.control_handle
575 }
576
577 fn drop_without_shutdown(mut self) {
578 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
580 std::mem::forget(self);
582 }
583}
584
585impl StoreWriteItemResponder {
586 pub fn send(self, mut result: Result<(), WriteError>) -> Result<(), fidl::Error> {
590 let _result = self.send_raw(result);
591 if _result.is_err() {
592 self.control_handle.shutdown();
593 }
594 self.drop_without_shutdown();
595 _result
596 }
597
598 pub fn send_no_shutdown_on_err(
600 self,
601 mut result: Result<(), WriteError>,
602 ) -> Result<(), fidl::Error> {
603 let _result = self.send_raw(result);
604 self.drop_without_shutdown();
605 _result
606 }
607
608 fn send_raw(&self, mut result: Result<(), WriteError>) -> Result<(), fidl::Error> {
609 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
610 fidl::encoding::EmptyStruct,
611 WriteError,
612 >>(
613 fidl::encoding::FlexibleResult::new(result),
614 self.tx_id,
615 0x4a01d5d999e00aa2,
616 fidl::encoding::DynamicFlags::FLEXIBLE,
617 )
618 }
619}
620
621mod internal {
622 use super::*;
623 unsafe impl fidl::encoding::TypeMarker for WriteError {
624 type Owned = Self;
625
626 #[inline(always)]
627 fn inline_align(_context: fidl::encoding::Context) -> usize {
628 std::mem::align_of::<u32>()
629 }
630
631 #[inline(always)]
632 fn inline_size(_context: fidl::encoding::Context) -> usize {
633 std::mem::size_of::<u32>()
634 }
635
636 #[inline(always)]
637 fn encode_is_copy() -> bool {
638 false
639 }
640
641 #[inline(always)]
642 fn decode_is_copy() -> bool {
643 false
644 }
645 }
646
647 impl fidl::encoding::ValueTypeMarker for WriteError {
648 type Borrowed<'a> = Self;
649 #[inline(always)]
650 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
651 *value
652 }
653 }
654
655 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for WriteError {
656 #[inline]
657 unsafe fn encode(
658 self,
659 encoder: &mut fidl::encoding::Encoder<'_, D>,
660 offset: usize,
661 _depth: fidl::encoding::Depth,
662 ) -> fidl::Result<()> {
663 encoder.debug_check_bounds::<Self>(offset);
664 encoder.write_num(self.into_primitive(), offset);
665 Ok(())
666 }
667 }
668
669 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WriteError {
670 #[inline(always)]
671 fn new_empty() -> Self {
672 Self::unknown()
673 }
674
675 #[inline]
676 unsafe fn decode(
677 &mut self,
678 decoder: &mut fidl::encoding::Decoder<'_, D>,
679 offset: usize,
680 _depth: fidl::encoding::Depth,
681 ) -> fidl::Result<()> {
682 decoder.debug_check_bounds::<Self>(offset);
683 let prim = decoder.read_num::<u32>(offset);
684
685 *self = Self::from_primitive_allow_unknown(prim);
686 Ok(())
687 }
688 }
689
690 impl fidl::encoding::ValueTypeMarker for Item {
691 type Borrowed<'a> = &'a Self;
692 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
693 value
694 }
695 }
696
697 unsafe impl fidl::encoding::TypeMarker for Item {
698 type Owned = Self;
699
700 #[inline(always)]
701 fn inline_align(_context: fidl::encoding::Context) -> usize {
702 8
703 }
704
705 #[inline(always)]
706 fn inline_size(_context: fidl::encoding::Context) -> usize {
707 32
708 }
709 }
710
711 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Item, D> for &Item {
712 #[inline]
713 unsafe fn encode(
714 self,
715 encoder: &mut fidl::encoding::Encoder<'_, D>,
716 offset: usize,
717 _depth: fidl::encoding::Depth,
718 ) -> fidl::Result<()> {
719 encoder.debug_check_bounds::<Item>(offset);
720 fidl::encoding::Encode::<Item, D>::encode(
722 (
723 <fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow(&self.key),
724 <fidl::encoding::OptionalUnion<Value> as fidl::encoding::ValueTypeMarker>::borrow(&self.value),
725 ),
726 encoder, offset, _depth
727 )
728 }
729 }
730 unsafe impl<
731 D: fidl::encoding::ResourceDialect,
732 T0: fidl::encoding::Encode<fidl::encoding::BoundedString<128>, D>,
733 T1: fidl::encoding::Encode<fidl::encoding::OptionalUnion<Value>, D>,
734 > fidl::encoding::Encode<Item, D> for (T0, T1)
735 {
736 #[inline]
737 unsafe fn encode(
738 self,
739 encoder: &mut fidl::encoding::Encoder<'_, D>,
740 offset: usize,
741 depth: fidl::encoding::Depth,
742 ) -> fidl::Result<()> {
743 encoder.debug_check_bounds::<Item>(offset);
744 self.0.encode(encoder, offset + 0, depth)?;
748 self.1.encode(encoder, offset + 16, depth)?;
749 Ok(())
750 }
751 }
752
753 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Item {
754 #[inline(always)]
755 fn new_empty() -> Self {
756 Self {
757 key: fidl::new_empty!(fidl::encoding::BoundedString<128>, D),
758 value: fidl::new_empty!(fidl::encoding::OptionalUnion<Value>, D),
759 }
760 }
761
762 #[inline]
763 unsafe fn decode(
764 &mut self,
765 decoder: &mut fidl::encoding::Decoder<'_, D>,
766 offset: usize,
767 _depth: fidl::encoding::Depth,
768 ) -> fidl::Result<()> {
769 decoder.debug_check_bounds::<Self>(offset);
770 fidl::decode!(
772 fidl::encoding::BoundedString<128>,
773 D,
774 &mut self.key,
775 decoder,
776 offset + 0,
777 _depth
778 )?;
779 fidl::decode!(
780 fidl::encoding::OptionalUnion<Value>,
781 D,
782 &mut self.value,
783 decoder,
784 offset + 16,
785 _depth
786 )?;
787 Ok(())
788 }
789 }
790
791 impl fidl::encoding::ValueTypeMarker for StoreWriteItemRequest {
792 type Borrowed<'a> = &'a Self;
793 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
794 value
795 }
796 }
797
798 unsafe impl fidl::encoding::TypeMarker for StoreWriteItemRequest {
799 type Owned = Self;
800
801 #[inline(always)]
802 fn inline_align(_context: fidl::encoding::Context) -> usize {
803 8
804 }
805
806 #[inline(always)]
807 fn inline_size(_context: fidl::encoding::Context) -> usize {
808 32
809 }
810 }
811
812 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<StoreWriteItemRequest, D>
813 for &StoreWriteItemRequest
814 {
815 #[inline]
816 unsafe fn encode(
817 self,
818 encoder: &mut fidl::encoding::Encoder<'_, D>,
819 offset: usize,
820 _depth: fidl::encoding::Depth,
821 ) -> fidl::Result<()> {
822 encoder.debug_check_bounds::<StoreWriteItemRequest>(offset);
823 fidl::encoding::Encode::<StoreWriteItemRequest, D>::encode(
825 (<Item as fidl::encoding::ValueTypeMarker>::borrow(&self.attempt),),
826 encoder,
827 offset,
828 _depth,
829 )
830 }
831 }
832 unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Item, D>>
833 fidl::encoding::Encode<StoreWriteItemRequest, D> for (T0,)
834 {
835 #[inline]
836 unsafe fn encode(
837 self,
838 encoder: &mut fidl::encoding::Encoder<'_, D>,
839 offset: usize,
840 depth: fidl::encoding::Depth,
841 ) -> fidl::Result<()> {
842 encoder.debug_check_bounds::<StoreWriteItemRequest>(offset);
843 self.0.encode(encoder, offset + 0, depth)?;
847 Ok(())
848 }
849 }
850
851 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StoreWriteItemRequest {
852 #[inline(always)]
853 fn new_empty() -> Self {
854 Self { attempt: fidl::new_empty!(Item, D) }
855 }
856
857 #[inline]
858 unsafe fn decode(
859 &mut self,
860 decoder: &mut fidl::encoding::Decoder<'_, D>,
861 offset: usize,
862 _depth: fidl::encoding::Depth,
863 ) -> fidl::Result<()> {
864 decoder.debug_check_bounds::<Self>(offset);
865 fidl::decode!(Item, D, &mut self.attempt, decoder, offset + 0, _depth)?;
867 Ok(())
868 }
869 }
870
871 impl NestedStore {
872 #[inline(always)]
873 fn max_ordinal_present(&self) -> u64 {
874 if let Some(_) = self.items {
875 return 1;
876 }
877 0
878 }
879 }
880
881 impl fidl::encoding::ValueTypeMarker for NestedStore {
882 type Borrowed<'a> = &'a Self;
883 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
884 value
885 }
886 }
887
888 unsafe impl fidl::encoding::TypeMarker for NestedStore {
889 type Owned = Self;
890
891 #[inline(always)]
892 fn inline_align(_context: fidl::encoding::Context) -> usize {
893 8
894 }
895
896 #[inline(always)]
897 fn inline_size(_context: fidl::encoding::Context) -> usize {
898 16
899 }
900 }
901
902 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<NestedStore, D>
903 for &NestedStore
904 {
905 unsafe fn encode(
906 self,
907 encoder: &mut fidl::encoding::Encoder<'_, D>,
908 offset: usize,
909 mut depth: fidl::encoding::Depth,
910 ) -> fidl::Result<()> {
911 encoder.debug_check_bounds::<NestedStore>(offset);
912 let max_ordinal: u64 = self.max_ordinal_present();
914 encoder.write_num(max_ordinal, offset);
915 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
916 if max_ordinal == 0 {
918 return Ok(());
919 }
920 depth.increment()?;
921 let envelope_size = 8;
922 let bytes_len = max_ordinal as usize * envelope_size;
923 #[allow(unused_variables)]
924 let offset = encoder.out_of_line_offset(bytes_len);
925 let mut _prev_end_offset: usize = 0;
926 if 1 > max_ordinal {
927 return Ok(());
928 }
929
930 let cur_offset: usize = (1 - 1) * envelope_size;
933
934 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
936
937 fidl::encoding::encode_in_envelope_optional::<fidl::encoding::UnboundedVector<fidl::encoding::Boxed<Item>>, D>(
942 self.items.as_ref().map(<fidl::encoding::UnboundedVector<fidl::encoding::Boxed<Item>> as fidl::encoding::ValueTypeMarker>::borrow),
943 encoder, offset + cur_offset, depth
944 )?;
945
946 _prev_end_offset = cur_offset + envelope_size;
947
948 Ok(())
949 }
950 }
951
952 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for NestedStore {
953 #[inline(always)]
954 fn new_empty() -> Self {
955 Self::default()
956 }
957
958 unsafe fn decode(
959 &mut self,
960 decoder: &mut fidl::encoding::Decoder<'_, D>,
961 offset: usize,
962 mut depth: fidl::encoding::Depth,
963 ) -> fidl::Result<()> {
964 decoder.debug_check_bounds::<Self>(offset);
965 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
966 None => return Err(fidl::Error::NotNullable),
967 Some(len) => len,
968 };
969 if len == 0 {
971 return Ok(());
972 };
973 depth.increment()?;
974 let envelope_size = 8;
975 let bytes_len = len * envelope_size;
976 let offset = decoder.out_of_line_offset(bytes_len)?;
977 let mut _next_ordinal_to_read = 0;
979 let mut next_offset = offset;
980 let end_offset = offset + bytes_len;
981 _next_ordinal_to_read += 1;
982 if next_offset >= end_offset {
983 return Ok(());
984 }
985
986 while _next_ordinal_to_read < 1 {
988 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
989 _next_ordinal_to_read += 1;
990 next_offset += envelope_size;
991 }
992
993 let next_out_of_line = decoder.next_out_of_line();
994 let handles_before = decoder.remaining_handles();
995 if let Some((inlined, num_bytes, num_handles)) =
996 fidl::encoding::decode_envelope_header(decoder, next_offset)?
997 {
998 let member_inline_size = <fidl::encoding::UnboundedVector<
999 fidl::encoding::Boxed<Item>,
1000 > as fidl::encoding::TypeMarker>::inline_size(
1001 decoder.context
1002 );
1003 if inlined != (member_inline_size <= 4) {
1004 return Err(fidl::Error::InvalidInlineBitInEnvelope);
1005 }
1006 let inner_offset;
1007 let mut inner_depth = depth.clone();
1008 if inlined {
1009 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1010 inner_offset = next_offset;
1011 } else {
1012 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1013 inner_depth.increment()?;
1014 }
1015 let val_ref = self.items.get_or_insert_with(|| {
1016 fidl::new_empty!(
1017 fidl::encoding::UnboundedVector<fidl::encoding::Boxed<Item>>,
1018 D
1019 )
1020 });
1021 fidl::decode!(
1022 fidl::encoding::UnboundedVector<fidl::encoding::Boxed<Item>>,
1023 D,
1024 val_ref,
1025 decoder,
1026 inner_offset,
1027 inner_depth
1028 )?;
1029 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1030 {
1031 return Err(fidl::Error::InvalidNumBytesInEnvelope);
1032 }
1033 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1034 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1035 }
1036 }
1037
1038 next_offset += envelope_size;
1039
1040 while next_offset < end_offset {
1042 _next_ordinal_to_read += 1;
1043 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1044 next_offset += envelope_size;
1045 }
1046
1047 Ok(())
1048 }
1049 }
1050
1051 impl fidl::encoding::ValueTypeMarker for Value {
1052 type Borrowed<'a> = &'a Self;
1053 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1054 value
1055 }
1056 }
1057
1058 unsafe impl fidl::encoding::TypeMarker for Value {
1059 type Owned = Self;
1060
1061 #[inline(always)]
1062 fn inline_align(_context: fidl::encoding::Context) -> usize {
1063 8
1064 }
1065
1066 #[inline(always)]
1067 fn inline_size(_context: fidl::encoding::Context) -> usize {
1068 16
1069 }
1070 }
1071
1072 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Value, D> for &Value {
1073 #[inline]
1074 unsafe fn encode(
1075 self,
1076 encoder: &mut fidl::encoding::Encoder<'_, D>,
1077 offset: usize,
1078 _depth: fidl::encoding::Depth,
1079 ) -> fidl::Result<()> {
1080 encoder.debug_check_bounds::<Value>(offset);
1081 encoder.write_num::<u64>(self.ordinal(), offset);
1082 match self {
1083 Value::Bytes(ref val) => fidl::encoding::encode_in_envelope::<
1084 fidl::encoding::Vector<u8, 64000>,
1085 D,
1086 >(
1087 <fidl::encoding::Vector<u8, 64000> as fidl::encoding::ValueTypeMarker>::borrow(
1088 val,
1089 ),
1090 encoder,
1091 offset + 8,
1092 _depth,
1093 ),
1094 Value::Store(ref val) => fidl::encoding::encode_in_envelope::<NestedStore, D>(
1095 <NestedStore as fidl::encoding::ValueTypeMarker>::borrow(val),
1096 encoder,
1097 offset + 8,
1098 _depth,
1099 ),
1100 }
1101 }
1102 }
1103
1104 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Value {
1105 #[inline(always)]
1106 fn new_empty() -> Self {
1107 Self::Bytes(fidl::new_empty!(fidl::encoding::Vector<u8, 64000>, D))
1108 }
1109
1110 #[inline]
1111 unsafe fn decode(
1112 &mut self,
1113 decoder: &mut fidl::encoding::Decoder<'_, D>,
1114 offset: usize,
1115 mut depth: fidl::encoding::Depth,
1116 ) -> fidl::Result<()> {
1117 decoder.debug_check_bounds::<Self>(offset);
1118 #[allow(unused_variables)]
1119 let next_out_of_line = decoder.next_out_of_line();
1120 let handles_before = decoder.remaining_handles();
1121 let (ordinal, inlined, num_bytes, num_handles) =
1122 fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1123
1124 let member_inline_size = match ordinal {
1125 1 => {
1126 <fidl::encoding::Vector<u8, 64000> as fidl::encoding::TypeMarker>::inline_size(
1127 decoder.context,
1128 )
1129 }
1130 2 => <NestedStore as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1131 _ => return Err(fidl::Error::UnknownUnionTag),
1132 };
1133
1134 if inlined != (member_inline_size <= 4) {
1135 return Err(fidl::Error::InvalidInlineBitInEnvelope);
1136 }
1137 let _inner_offset;
1138 if inlined {
1139 decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1140 _inner_offset = offset + 8;
1141 } else {
1142 depth.increment()?;
1143 _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1144 }
1145 match ordinal {
1146 1 => {
1147 #[allow(irrefutable_let_patterns)]
1148 if let Value::Bytes(_) = self {
1149 } else {
1151 *self =
1153 Value::Bytes(fidl::new_empty!(fidl::encoding::Vector<u8, 64000>, D));
1154 }
1155 #[allow(irrefutable_let_patterns)]
1156 if let Value::Bytes(ref mut val) = self {
1157 fidl::decode!(fidl::encoding::Vector<u8, 64000>, D, val, decoder, _inner_offset, depth)?;
1158 } else {
1159 unreachable!()
1160 }
1161 }
1162 2 => {
1163 #[allow(irrefutable_let_patterns)]
1164 if let Value::Store(_) = self {
1165 } else {
1167 *self = Value::Store(fidl::new_empty!(NestedStore, D));
1169 }
1170 #[allow(irrefutable_let_patterns)]
1171 if let Value::Store(ref mut val) = self {
1172 fidl::decode!(NestedStore, D, val, decoder, _inner_offset, depth)?;
1173 } else {
1174 unreachable!()
1175 }
1176 }
1177 ordinal => panic!("unexpected ordinal {:?}", ordinal),
1178 }
1179 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1180 return Err(fidl::Error::InvalidNumBytesInEnvelope);
1181 }
1182 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1183 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1184 }
1185 Ok(())
1186 }
1187 }
1188}