fidl_fuchsia_net_http_common/
fidl_fuchsia_net_http_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/// Friendly alias for a vector of bytes containing a header name.
12pub type HeaderName = Vec<u8>;
13
14/// Friendly alias for a vector of bytes containing a header value.
15pub type HeaderValue = Vec<u8>;
16
17pub type Method = String;
18
19/// An error occurred during the HTTP transaction.
20#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
21#[repr(u32)]
22pub enum Error {
23    /// Some other problem occurred that cannot be classified using one of the
24    /// more specific statuses. Retry is optional.
25    Internal = 1,
26    /// An HTTP parse error.
27    UnableToParse = 2,
28    /// Indicates a channel (client or body sender) is closed.
29    ChannelClosed = 3,
30    /// Error occurred while connecting.
31    Connect = 4,
32    /// The deadline specified in Request has passed
33    DeadlineExceeded = 5,
34}
35
36impl Error {
37    #[inline]
38    pub fn from_primitive(prim: u32) -> Option<Self> {
39        match prim {
40            1 => Some(Self::Internal),
41            2 => Some(Self::UnableToParse),
42            3 => Some(Self::ChannelClosed),
43            4 => Some(Self::Connect),
44            5 => Some(Self::DeadlineExceeded),
45            _ => None,
46        }
47    }
48
49    #[inline]
50    pub const fn into_primitive(self) -> u32 {
51        self as u32
52    }
53
54    #[deprecated = "Strict enums should not use `is_unknown`"]
55    #[inline]
56    pub fn is_unknown(&self) -> bool {
57        false
58    }
59}
60
61/// An HTTP header field.
62#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
63pub struct Header {
64    /// The name of the header field.
65    pub name: Vec<u8>,
66    /// The value of the header field.
67    pub value: Vec<u8>,
68}
69
70impl fidl::Persistable for Header {}
71
72/// A description of the redirect the server requested.
73///
74/// The semantics of an HTTP redirect vary according to the status code use to
75/// generate the redirect. This structure ensures that the loader and its client
76/// agree on the interpretation of the redirect response from the server.
77#[derive(Clone, Debug, Default, PartialEq)]
78pub struct RedirectTarget {
79    /// The HTTP method the server suggested for the redirect.
80    pub method: Option<String>,
81    /// The URL the server suggested for the redirect.
82    pub url: Option<String>,
83    /// The referrer the server suggested for the redirect.
84    pub referrer: Option<String>,
85    #[doc(hidden)]
86    pub __source_breaking: fidl::marker::SourceBreaking,
87}
88
89impl fidl::Persistable for RedirectTarget {}
90
91mod internal {
92    use super::*;
93    unsafe impl fidl::encoding::TypeMarker for Error {
94        type Owned = Self;
95
96        #[inline(always)]
97        fn inline_align(_context: fidl::encoding::Context) -> usize {
98            std::mem::align_of::<u32>()
99        }
100
101        #[inline(always)]
102        fn inline_size(_context: fidl::encoding::Context) -> usize {
103            std::mem::size_of::<u32>()
104        }
105
106        #[inline(always)]
107        fn encode_is_copy() -> bool {
108            true
109        }
110
111        #[inline(always)]
112        fn decode_is_copy() -> bool {
113            false
114        }
115    }
116
117    impl fidl::encoding::ValueTypeMarker for Error {
118        type Borrowed<'a> = Self;
119        #[inline(always)]
120        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
121            *value
122        }
123    }
124
125    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
126        #[inline]
127        unsafe fn encode(
128            self,
129            encoder: &mut fidl::encoding::Encoder<'_, D>,
130            offset: usize,
131            _depth: fidl::encoding::Depth,
132        ) -> fidl::Result<()> {
133            encoder.debug_check_bounds::<Self>(offset);
134            encoder.write_num(self.into_primitive(), offset);
135            Ok(())
136        }
137    }
138
139    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
140        #[inline(always)]
141        fn new_empty() -> Self {
142            Self::Internal
143        }
144
145        #[inline]
146        unsafe fn decode(
147            &mut self,
148            decoder: &mut fidl::encoding::Decoder<'_, D>,
149            offset: usize,
150            _depth: fidl::encoding::Depth,
151        ) -> fidl::Result<()> {
152            decoder.debug_check_bounds::<Self>(offset);
153            let prim = decoder.read_num::<u32>(offset);
154
155            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
156            Ok(())
157        }
158    }
159
160    impl fidl::encoding::ValueTypeMarker for Header {
161        type Borrowed<'a> = &'a Self;
162        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
163            value
164        }
165    }
166
167    unsafe impl fidl::encoding::TypeMarker for Header {
168        type Owned = Self;
169
170        #[inline(always)]
171        fn inline_align(_context: fidl::encoding::Context) -> usize {
172            8
173        }
174
175        #[inline(always)]
176        fn inline_size(_context: fidl::encoding::Context) -> usize {
177            32
178        }
179    }
180
181    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Header, D> for &Header {
182        #[inline]
183        unsafe fn encode(
184            self,
185            encoder: &mut fidl::encoding::Encoder<'_, D>,
186            offset: usize,
187            _depth: fidl::encoding::Depth,
188        ) -> fidl::Result<()> {
189            encoder.debug_check_bounds::<Header>(offset);
190            // Delegate to tuple encoding.
191            fidl::encoding::Encode::<Header, D>::encode(
192                (
193                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.name),
194                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.value),
195                ),
196                encoder, offset, _depth
197            )
198        }
199    }
200    unsafe impl<
201            D: fidl::encoding::ResourceDialect,
202            T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<u8>, D>,
203            T1: fidl::encoding::Encode<fidl::encoding::UnboundedVector<u8>, D>,
204        > fidl::encoding::Encode<Header, D> for (T0, T1)
205    {
206        #[inline]
207        unsafe fn encode(
208            self,
209            encoder: &mut fidl::encoding::Encoder<'_, D>,
210            offset: usize,
211            depth: fidl::encoding::Depth,
212        ) -> fidl::Result<()> {
213            encoder.debug_check_bounds::<Header>(offset);
214            // Zero out padding regions. There's no need to apply masks
215            // because the unmasked parts will be overwritten by fields.
216            // Write the fields.
217            self.0.encode(encoder, offset + 0, depth)?;
218            self.1.encode(encoder, offset + 16, depth)?;
219            Ok(())
220        }
221    }
222
223    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Header {
224        #[inline(always)]
225        fn new_empty() -> Self {
226            Self {
227                name: fidl::new_empty!(fidl::encoding::UnboundedVector<u8>, D),
228                value: fidl::new_empty!(fidl::encoding::UnboundedVector<u8>, D),
229            }
230        }
231
232        #[inline]
233        unsafe fn decode(
234            &mut self,
235            decoder: &mut fidl::encoding::Decoder<'_, D>,
236            offset: usize,
237            _depth: fidl::encoding::Depth,
238        ) -> fidl::Result<()> {
239            decoder.debug_check_bounds::<Self>(offset);
240            // Verify that padding bytes are zero.
241            fidl::decode!(
242                fidl::encoding::UnboundedVector<u8>,
243                D,
244                &mut self.name,
245                decoder,
246                offset + 0,
247                _depth
248            )?;
249            fidl::decode!(
250                fidl::encoding::UnboundedVector<u8>,
251                D,
252                &mut self.value,
253                decoder,
254                offset + 16,
255                _depth
256            )?;
257            Ok(())
258        }
259    }
260
261    impl RedirectTarget {
262        #[inline(always)]
263        fn max_ordinal_present(&self) -> u64 {
264            if let Some(_) = self.referrer {
265                return 3;
266            }
267            if let Some(_) = self.url {
268                return 2;
269            }
270            if let Some(_) = self.method {
271                return 1;
272            }
273            0
274        }
275    }
276
277    impl fidl::encoding::ValueTypeMarker for RedirectTarget {
278        type Borrowed<'a> = &'a Self;
279        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
280            value
281        }
282    }
283
284    unsafe impl fidl::encoding::TypeMarker for RedirectTarget {
285        type Owned = Self;
286
287        #[inline(always)]
288        fn inline_align(_context: fidl::encoding::Context) -> usize {
289            8
290        }
291
292        #[inline(always)]
293        fn inline_size(_context: fidl::encoding::Context) -> usize {
294            16
295        }
296    }
297
298    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<RedirectTarget, D>
299        for &RedirectTarget
300    {
301        unsafe fn encode(
302            self,
303            encoder: &mut fidl::encoding::Encoder<'_, D>,
304            offset: usize,
305            mut depth: fidl::encoding::Depth,
306        ) -> fidl::Result<()> {
307            encoder.debug_check_bounds::<RedirectTarget>(offset);
308            // Vector header
309            let max_ordinal: u64 = self.max_ordinal_present();
310            encoder.write_num(max_ordinal, offset);
311            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
312            // Calling encoder.out_of_line_offset(0) is not allowed.
313            if max_ordinal == 0 {
314                return Ok(());
315            }
316            depth.increment()?;
317            let envelope_size = 8;
318            let bytes_len = max_ordinal as usize * envelope_size;
319            #[allow(unused_variables)]
320            let offset = encoder.out_of_line_offset(bytes_len);
321            let mut _prev_end_offset: usize = 0;
322            if 1 > max_ordinal {
323                return Ok(());
324            }
325
326            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
327            // are envelope_size bytes.
328            let cur_offset: usize = (1 - 1) * envelope_size;
329
330            // Zero reserved fields.
331            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
332
333            // Safety:
334            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
335            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
336            //   envelope_size bytes, there is always sufficient room.
337            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::BoundedString<1024>, D>(
338            self.method.as_ref().map(<fidl::encoding::BoundedString<1024> as fidl::encoding::ValueTypeMarker>::borrow),
339            encoder, offset + cur_offset, depth
340        )?;
341
342            _prev_end_offset = cur_offset + envelope_size;
343            if 2 > max_ordinal {
344                return Ok(());
345            }
346
347            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
348            // are envelope_size bytes.
349            let cur_offset: usize = (2 - 1) * envelope_size;
350
351            // Zero reserved fields.
352            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
353
354            // Safety:
355            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
356            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
357            //   envelope_size bytes, there is always sufficient room.
358            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::BoundedString<4096>, D>(
359            self.url.as_ref().map(<fidl::encoding::BoundedString<4096> as fidl::encoding::ValueTypeMarker>::borrow),
360            encoder, offset + cur_offset, depth
361        )?;
362
363            _prev_end_offset = cur_offset + envelope_size;
364            if 3 > max_ordinal {
365                return Ok(());
366            }
367
368            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
369            // are envelope_size bytes.
370            let cur_offset: usize = (3 - 1) * envelope_size;
371
372            // Zero reserved fields.
373            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
374
375            // Safety:
376            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
377            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
378            //   envelope_size bytes, there is always sufficient room.
379            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::BoundedString<4096>, D>(
380            self.referrer.as_ref().map(<fidl::encoding::BoundedString<4096> as fidl::encoding::ValueTypeMarker>::borrow),
381            encoder, offset + cur_offset, depth
382        )?;
383
384            _prev_end_offset = cur_offset + envelope_size;
385
386            Ok(())
387        }
388    }
389
390    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for RedirectTarget {
391        #[inline(always)]
392        fn new_empty() -> Self {
393            Self::default()
394        }
395
396        unsafe fn decode(
397            &mut self,
398            decoder: &mut fidl::encoding::Decoder<'_, D>,
399            offset: usize,
400            mut depth: fidl::encoding::Depth,
401        ) -> fidl::Result<()> {
402            decoder.debug_check_bounds::<Self>(offset);
403            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
404                None => return Err(fidl::Error::NotNullable),
405                Some(len) => len,
406            };
407            // Calling decoder.out_of_line_offset(0) is not allowed.
408            if len == 0 {
409                return Ok(());
410            };
411            depth.increment()?;
412            let envelope_size = 8;
413            let bytes_len = len * envelope_size;
414            let offset = decoder.out_of_line_offset(bytes_len)?;
415            // Decode the envelope for each type.
416            let mut _next_ordinal_to_read = 0;
417            let mut next_offset = offset;
418            let end_offset = offset + bytes_len;
419            _next_ordinal_to_read += 1;
420            if next_offset >= end_offset {
421                return Ok(());
422            }
423
424            // Decode unknown envelopes for gaps in ordinals.
425            while _next_ordinal_to_read < 1 {
426                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
427                _next_ordinal_to_read += 1;
428                next_offset += envelope_size;
429            }
430
431            let next_out_of_line = decoder.next_out_of_line();
432            let handles_before = decoder.remaining_handles();
433            if let Some((inlined, num_bytes, num_handles)) =
434                fidl::encoding::decode_envelope_header(decoder, next_offset)?
435            {
436                let member_inline_size = <fidl::encoding::BoundedString<1024> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
437                if inlined != (member_inline_size <= 4) {
438                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
439                }
440                let inner_offset;
441                let mut inner_depth = depth.clone();
442                if inlined {
443                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
444                    inner_offset = next_offset;
445                } else {
446                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
447                    inner_depth.increment()?;
448                }
449                let val_ref = self.method.get_or_insert_with(|| {
450                    fidl::new_empty!(fidl::encoding::BoundedString<1024>, D)
451                });
452                fidl::decode!(
453                    fidl::encoding::BoundedString<1024>,
454                    D,
455                    val_ref,
456                    decoder,
457                    inner_offset,
458                    inner_depth
459                )?;
460                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
461                {
462                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
463                }
464                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
465                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
466                }
467            }
468
469            next_offset += envelope_size;
470            _next_ordinal_to_read += 1;
471            if next_offset >= end_offset {
472                return Ok(());
473            }
474
475            // Decode unknown envelopes for gaps in ordinals.
476            while _next_ordinal_to_read < 2 {
477                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
478                _next_ordinal_to_read += 1;
479                next_offset += envelope_size;
480            }
481
482            let next_out_of_line = decoder.next_out_of_line();
483            let handles_before = decoder.remaining_handles();
484            if let Some((inlined, num_bytes, num_handles)) =
485                fidl::encoding::decode_envelope_header(decoder, next_offset)?
486            {
487                let member_inline_size = <fidl::encoding::BoundedString<4096> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
488                if inlined != (member_inline_size <= 4) {
489                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
490                }
491                let inner_offset;
492                let mut inner_depth = depth.clone();
493                if inlined {
494                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
495                    inner_offset = next_offset;
496                } else {
497                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
498                    inner_depth.increment()?;
499                }
500                let val_ref = self.url.get_or_insert_with(|| {
501                    fidl::new_empty!(fidl::encoding::BoundedString<4096>, D)
502                });
503                fidl::decode!(
504                    fidl::encoding::BoundedString<4096>,
505                    D,
506                    val_ref,
507                    decoder,
508                    inner_offset,
509                    inner_depth
510                )?;
511                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
512                {
513                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
514                }
515                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
516                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
517                }
518            }
519
520            next_offset += envelope_size;
521            _next_ordinal_to_read += 1;
522            if next_offset >= end_offset {
523                return Ok(());
524            }
525
526            // Decode unknown envelopes for gaps in ordinals.
527            while _next_ordinal_to_read < 3 {
528                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
529                _next_ordinal_to_read += 1;
530                next_offset += envelope_size;
531            }
532
533            let next_out_of_line = decoder.next_out_of_line();
534            let handles_before = decoder.remaining_handles();
535            if let Some((inlined, num_bytes, num_handles)) =
536                fidl::encoding::decode_envelope_header(decoder, next_offset)?
537            {
538                let member_inline_size = <fidl::encoding::BoundedString<4096> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
539                if inlined != (member_inline_size <= 4) {
540                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
541                }
542                let inner_offset;
543                let mut inner_depth = depth.clone();
544                if inlined {
545                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
546                    inner_offset = next_offset;
547                } else {
548                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
549                    inner_depth.increment()?;
550                }
551                let val_ref = self.referrer.get_or_insert_with(|| {
552                    fidl::new_empty!(fidl::encoding::BoundedString<4096>, D)
553                });
554                fidl::decode!(
555                    fidl::encoding::BoundedString<4096>,
556                    D,
557                    val_ref,
558                    decoder,
559                    inner_offset,
560                    inner_depth
561                )?;
562                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
563                {
564                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
565                }
566                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
567                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
568                }
569            }
570
571            next_offset += envelope_size;
572
573            // Decode the remaining unknown envelopes.
574            while next_offset < end_offset {
575                _next_ordinal_to_read += 1;
576                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
577                next_offset += envelope_size;
578            }
579
580            Ok(())
581        }
582    }
583}