fidl_examples_keyvaluestore_baseline_common/
fidl_examples_keyvaluestore_baseline_common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11/// An enumeration of things that may go wrong when trying to write a value to our store.
12#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13pub enum WriteError {
14    Unknown,
15    InvalidKey,
16    InvalidValue,
17    AlreadyExists,
18    #[doc(hidden)]
19    __SourceBreaking {
20        unknown_ordinal: u32,
21    },
22}
23
24/// Pattern that matches an unknown `WriteError` member.
25#[macro_export]
26macro_rules! WriteErrorUnknown {
27    () => {
28        _
29    };
30}
31
32impl WriteError {
33    #[inline]
34    pub fn from_primitive(prim: u32) -> Option<Self> {
35        match prim {
36            0 => Some(Self::Unknown),
37            1 => Some(Self::InvalidKey),
38            2 => Some(Self::InvalidValue),
39            3 => Some(Self::AlreadyExists),
40            _ => None,
41        }
42    }
43
44    #[inline]
45    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
46        match prim {
47            0 => Self::Unknown,
48            1 => Self::InvalidKey,
49            2 => Self::InvalidValue,
50            3 => Self::AlreadyExists,
51            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
52        }
53    }
54
55    #[inline]
56    pub fn unknown() -> Self {
57        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
58    }
59
60    #[inline]
61    pub const fn into_primitive(self) -> u32 {
62        match self {
63            Self::Unknown => 0,
64            Self::InvalidKey => 1,
65            Self::InvalidValue => 2,
66            Self::AlreadyExists => 3,
67            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
68        }
69    }
70
71    #[inline]
72    pub fn is_unknown(&self) -> bool {
73        match self {
74            Self::__SourceBreaking { unknown_ordinal: _ } => true,
75            _ => false,
76        }
77    }
78}
79
80/// An item in the store. The key must match the regex `^[A-z][A-z0-9_\.\/]{2,62}[A-z0-9]$`. That
81/// is, it must start with a letter, end with a letter or number, contain only letters, numbers,
82/// periods, and slashes, and be between 4 and 64 characters long.
83#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
84pub struct Item {
85    pub key: String,
86    pub value: Vec<u8>,
87}
88
89impl fidl::Persistable for Item {}
90
91#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
92pub struct StoreWriteItemRequest {
93    pub attempt: Item,
94}
95
96impl fidl::Persistable for StoreWriteItemRequest {}
97
98mod internal {
99    use super::*;
100    unsafe impl fidl::encoding::TypeMarker for WriteError {
101        type Owned = Self;
102
103        #[inline(always)]
104        fn inline_align(_context: fidl::encoding::Context) -> usize {
105            std::mem::align_of::<u32>()
106        }
107
108        #[inline(always)]
109        fn inline_size(_context: fidl::encoding::Context) -> usize {
110            std::mem::size_of::<u32>()
111        }
112
113        #[inline(always)]
114        fn encode_is_copy() -> bool {
115            false
116        }
117
118        #[inline(always)]
119        fn decode_is_copy() -> bool {
120            false
121        }
122    }
123
124    impl fidl::encoding::ValueTypeMarker for WriteError {
125        type Borrowed<'a> = Self;
126        #[inline(always)]
127        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
128            *value
129        }
130    }
131
132    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for WriteError {
133        #[inline]
134        unsafe fn encode(
135            self,
136            encoder: &mut fidl::encoding::Encoder<'_, D>,
137            offset: usize,
138            _depth: fidl::encoding::Depth,
139        ) -> fidl::Result<()> {
140            encoder.debug_check_bounds::<Self>(offset);
141            encoder.write_num(self.into_primitive(), offset);
142            Ok(())
143        }
144    }
145
146    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WriteError {
147        #[inline(always)]
148        fn new_empty() -> Self {
149            Self::unknown()
150        }
151
152        #[inline]
153        unsafe fn decode(
154            &mut self,
155            decoder: &mut fidl::encoding::Decoder<'_, D>,
156            offset: usize,
157            _depth: fidl::encoding::Depth,
158        ) -> fidl::Result<()> {
159            decoder.debug_check_bounds::<Self>(offset);
160            let prim = decoder.read_num::<u32>(offset);
161
162            *self = Self::from_primitive_allow_unknown(prim);
163            Ok(())
164        }
165    }
166
167    impl fidl::encoding::ValueTypeMarker for Item {
168        type Borrowed<'a> = &'a Self;
169        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
170            value
171        }
172    }
173
174    unsafe impl fidl::encoding::TypeMarker for Item {
175        type Owned = Self;
176
177        #[inline(always)]
178        fn inline_align(_context: fidl::encoding::Context) -> usize {
179            8
180        }
181
182        #[inline(always)]
183        fn inline_size(_context: fidl::encoding::Context) -> usize {
184            32
185        }
186    }
187
188    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Item, D> for &Item {
189        #[inline]
190        unsafe fn encode(
191            self,
192            encoder: &mut fidl::encoding::Encoder<'_, D>,
193            offset: usize,
194            _depth: fidl::encoding::Depth,
195        ) -> fidl::Result<()> {
196            encoder.debug_check_bounds::<Item>(offset);
197            // Delegate to tuple encoding.
198            fidl::encoding::Encode::<Item, D>::encode(
199                (
200                    <fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow(
201                        &self.key,
202                    ),
203                    <fidl::encoding::Vector<u8, 64000> as fidl::encoding::ValueTypeMarker>::borrow(
204                        &self.value,
205                    ),
206                ),
207                encoder,
208                offset,
209                _depth,
210            )
211        }
212    }
213    unsafe impl<
214            D: fidl::encoding::ResourceDialect,
215            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<128>, D>,
216            T1: fidl::encoding::Encode<fidl::encoding::Vector<u8, 64000>, D>,
217        > fidl::encoding::Encode<Item, D> for (T0, T1)
218    {
219        #[inline]
220        unsafe fn encode(
221            self,
222            encoder: &mut fidl::encoding::Encoder<'_, D>,
223            offset: usize,
224            depth: fidl::encoding::Depth,
225        ) -> fidl::Result<()> {
226            encoder.debug_check_bounds::<Item>(offset);
227            // Zero out padding regions. There's no need to apply masks
228            // because the unmasked parts will be overwritten by fields.
229            // Write the fields.
230            self.0.encode(encoder, offset + 0, depth)?;
231            self.1.encode(encoder, offset + 16, depth)?;
232            Ok(())
233        }
234    }
235
236    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Item {
237        #[inline(always)]
238        fn new_empty() -> Self {
239            Self {
240                key: fidl::new_empty!(fidl::encoding::BoundedString<128>, D),
241                value: fidl::new_empty!(fidl::encoding::Vector<u8, 64000>, D),
242            }
243        }
244
245        #[inline]
246        unsafe fn decode(
247            &mut self,
248            decoder: &mut fidl::encoding::Decoder<'_, D>,
249            offset: usize,
250            _depth: fidl::encoding::Depth,
251        ) -> fidl::Result<()> {
252            decoder.debug_check_bounds::<Self>(offset);
253            // Verify that padding bytes are zero.
254            fidl::decode!(
255                fidl::encoding::BoundedString<128>,
256                D,
257                &mut self.key,
258                decoder,
259                offset + 0,
260                _depth
261            )?;
262            fidl::decode!(fidl::encoding::Vector<u8, 64000>, D, &mut self.value, decoder, offset + 16, _depth)?;
263            Ok(())
264        }
265    }
266
267    impl fidl::encoding::ValueTypeMarker for StoreWriteItemRequest {
268        type Borrowed<'a> = &'a Self;
269        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
270            value
271        }
272    }
273
274    unsafe impl fidl::encoding::TypeMarker for StoreWriteItemRequest {
275        type Owned = Self;
276
277        #[inline(always)]
278        fn inline_align(_context: fidl::encoding::Context) -> usize {
279            8
280        }
281
282        #[inline(always)]
283        fn inline_size(_context: fidl::encoding::Context) -> usize {
284            32
285        }
286    }
287
288    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<StoreWriteItemRequest, D>
289        for &StoreWriteItemRequest
290    {
291        #[inline]
292        unsafe fn encode(
293            self,
294            encoder: &mut fidl::encoding::Encoder<'_, D>,
295            offset: usize,
296            _depth: fidl::encoding::Depth,
297        ) -> fidl::Result<()> {
298            encoder.debug_check_bounds::<StoreWriteItemRequest>(offset);
299            // Delegate to tuple encoding.
300            fidl::encoding::Encode::<StoreWriteItemRequest, D>::encode(
301                (<Item as fidl::encoding::ValueTypeMarker>::borrow(&self.attempt),),
302                encoder,
303                offset,
304                _depth,
305            )
306        }
307    }
308    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Item, D>>
309        fidl::encoding::Encode<StoreWriteItemRequest, D> for (T0,)
310    {
311        #[inline]
312        unsafe fn encode(
313            self,
314            encoder: &mut fidl::encoding::Encoder<'_, D>,
315            offset: usize,
316            depth: fidl::encoding::Depth,
317        ) -> fidl::Result<()> {
318            encoder.debug_check_bounds::<StoreWriteItemRequest>(offset);
319            // Zero out padding regions. There's no need to apply masks
320            // because the unmasked parts will be overwritten by fields.
321            // Write the fields.
322            self.0.encode(encoder, offset + 0, depth)?;
323            Ok(())
324        }
325    }
326
327    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StoreWriteItemRequest {
328        #[inline(always)]
329        fn new_empty() -> Self {
330            Self { attempt: fidl::new_empty!(Item, D) }
331        }
332
333        #[inline]
334        unsafe fn decode(
335            &mut self,
336            decoder: &mut fidl::encoding::Decoder<'_, D>,
337            offset: usize,
338            _depth: fidl::encoding::Depth,
339        ) -> fidl::Result<()> {
340            decoder.debug_check_bounds::<Self>(offset);
341            // Verify that padding bytes are zero.
342            fidl::decode!(Item, D, &mut self.attempt, decoder, offset + 0, _depth)?;
343            Ok(())
344        }
345    }
346}