fidl_fuchsia_hardware_google_nanohub/
fidl_fuchsia_hardware_google_nanohub.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::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_hardware_google_nanohub_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct DeviceDownloadFirmwareRequest {
16    pub firmware: fidl::Vmo,
17    pub offset: u64,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for DeviceDownloadFirmwareRequest
22{
23}
24
25#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
26pub struct DeviceMarker;
27
28impl fidl::endpoints::ProtocolMarker for DeviceMarker {
29    type Proxy = DeviceProxy;
30    type RequestStream = DeviceRequestStream;
31    #[cfg(target_os = "fuchsia")]
32    type SynchronousProxy = DeviceSynchronousProxy;
33
34    const DEBUG_NAME: &'static str = "fuchsia.hardware.google.nanohub.Device";
35}
36impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
37pub type DeviceDownloadFirmwareResult = Result<(), i32>;
38
39pub trait DeviceProxyInterface: Send + Sync {
40    type DownloadFirmwareResponseFut: std::future::Future<Output = Result<DeviceDownloadFirmwareResult, fidl::Error>>
41        + Send;
42    fn r#download_firmware(
43        &self,
44        firmware: fidl::Vmo,
45        offset: u64,
46    ) -> Self::DownloadFirmwareResponseFut;
47}
48#[derive(Debug)]
49#[cfg(target_os = "fuchsia")]
50pub struct DeviceSynchronousProxy {
51    client: fidl::client::sync::Client,
52}
53
54#[cfg(target_os = "fuchsia")]
55impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
56    type Proxy = DeviceProxy;
57    type Protocol = DeviceMarker;
58
59    fn from_channel(inner: fidl::Channel) -> Self {
60        Self::new(inner)
61    }
62
63    fn into_channel(self) -> fidl::Channel {
64        self.client.into_channel()
65    }
66
67    fn as_channel(&self) -> &fidl::Channel {
68        self.client.as_channel()
69    }
70}
71
72#[cfg(target_os = "fuchsia")]
73impl DeviceSynchronousProxy {
74    pub fn new(channel: fidl::Channel) -> Self {
75        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
76        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
77    }
78
79    pub fn into_channel(self) -> fidl::Channel {
80        self.client.into_channel()
81    }
82
83    /// Waits until an event arrives and returns it. It is safe for other
84    /// threads to make concurrent requests while waiting for an event.
85    pub fn wait_for_event(
86        &self,
87        deadline: zx::MonotonicInstant,
88    ) -> Result<DeviceEvent, fidl::Error> {
89        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
90    }
91
92    /// Request to sent to nanohub to load the firmware.
93    pub fn r#download_firmware(
94        &self,
95        mut firmware: fidl::Vmo,
96        mut offset: u64,
97        ___deadline: zx::MonotonicInstant,
98    ) -> Result<DeviceDownloadFirmwareResult, fidl::Error> {
99        let _response = self.client.send_query::<
100            DeviceDownloadFirmwareRequest,
101            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
102        >(
103            (firmware, offset,),
104            0x7bba8137e24661e5,
105            fidl::encoding::DynamicFlags::empty(),
106            ___deadline,
107        )?;
108        Ok(_response.map(|x| x))
109    }
110}
111
112#[cfg(target_os = "fuchsia")]
113impl From<DeviceSynchronousProxy> for zx::Handle {
114    fn from(value: DeviceSynchronousProxy) -> Self {
115        value.into_channel().into()
116    }
117}
118
119#[cfg(target_os = "fuchsia")]
120impl From<fidl::Channel> for DeviceSynchronousProxy {
121    fn from(value: fidl::Channel) -> Self {
122        Self::new(value)
123    }
124}
125
126#[derive(Debug, Clone)]
127pub struct DeviceProxy {
128    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
129}
130
131impl fidl::endpoints::Proxy for DeviceProxy {
132    type Protocol = DeviceMarker;
133
134    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
135        Self::new(inner)
136    }
137
138    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
139        self.client.into_channel().map_err(|client| Self { client })
140    }
141
142    fn as_channel(&self) -> &::fidl::AsyncChannel {
143        self.client.as_channel()
144    }
145}
146
147impl DeviceProxy {
148    /// Create a new Proxy for fuchsia.hardware.google.nanohub/Device.
149    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
150        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
151        Self { client: fidl::client::Client::new(channel, protocol_name) }
152    }
153
154    /// Get a Stream of events from the remote end of the protocol.
155    ///
156    /// # Panics
157    ///
158    /// Panics if the event stream was already taken.
159    pub fn take_event_stream(&self) -> DeviceEventStream {
160        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
161    }
162
163    /// Request to sent to nanohub to load the firmware.
164    pub fn r#download_firmware(
165        &self,
166        mut firmware: fidl::Vmo,
167        mut offset: u64,
168    ) -> fidl::client::QueryResponseFut<
169        DeviceDownloadFirmwareResult,
170        fidl::encoding::DefaultFuchsiaResourceDialect,
171    > {
172        DeviceProxyInterface::r#download_firmware(self, firmware, offset)
173    }
174}
175
176impl DeviceProxyInterface for DeviceProxy {
177    type DownloadFirmwareResponseFut = fidl::client::QueryResponseFut<
178        DeviceDownloadFirmwareResult,
179        fidl::encoding::DefaultFuchsiaResourceDialect,
180    >;
181    fn r#download_firmware(
182        &self,
183        mut firmware: fidl::Vmo,
184        mut offset: u64,
185    ) -> Self::DownloadFirmwareResponseFut {
186        fn _decode(
187            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
188        ) -> Result<DeviceDownloadFirmwareResult, fidl::Error> {
189            let _response = fidl::client::decode_transaction_body::<
190                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
191                fidl::encoding::DefaultFuchsiaResourceDialect,
192                0x7bba8137e24661e5,
193            >(_buf?)?;
194            Ok(_response.map(|x| x))
195        }
196        self.client
197            .send_query_and_decode::<DeviceDownloadFirmwareRequest, DeviceDownloadFirmwareResult>(
198                (firmware, offset),
199                0x7bba8137e24661e5,
200                fidl::encoding::DynamicFlags::empty(),
201                _decode,
202            )
203    }
204}
205
206pub struct DeviceEventStream {
207    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
208}
209
210impl std::marker::Unpin for DeviceEventStream {}
211
212impl futures::stream::FusedStream for DeviceEventStream {
213    fn is_terminated(&self) -> bool {
214        self.event_receiver.is_terminated()
215    }
216}
217
218impl futures::Stream for DeviceEventStream {
219    type Item = Result<DeviceEvent, fidl::Error>;
220
221    fn poll_next(
222        mut self: std::pin::Pin<&mut Self>,
223        cx: &mut std::task::Context<'_>,
224    ) -> std::task::Poll<Option<Self::Item>> {
225        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
226            &mut self.event_receiver,
227            cx
228        )?) {
229            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
230            None => std::task::Poll::Ready(None),
231        }
232    }
233}
234
235#[derive(Debug)]
236pub enum DeviceEvent {
237    #[non_exhaustive]
238    _UnknownEvent {
239        /// Ordinal of the event that was sent.
240        ordinal: u64,
241    },
242}
243
244impl DeviceEvent {
245    /// Decodes a message buffer as a [`DeviceEvent`].
246    fn decode(
247        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
248    ) -> Result<DeviceEvent, fidl::Error> {
249        let (bytes, _handles) = buf.split_mut();
250        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
251        debug_assert_eq!(tx_header.tx_id, 0);
252        match tx_header.ordinal {
253            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
254                Ok(DeviceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
255            }
256            _ => Err(fidl::Error::UnknownOrdinal {
257                ordinal: tx_header.ordinal,
258                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
259            }),
260        }
261    }
262}
263
264/// A Stream of incoming requests for fuchsia.hardware.google.nanohub/Device.
265pub struct DeviceRequestStream {
266    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
267    is_terminated: bool,
268}
269
270impl std::marker::Unpin for DeviceRequestStream {}
271
272impl futures::stream::FusedStream for DeviceRequestStream {
273    fn is_terminated(&self) -> bool {
274        self.is_terminated
275    }
276}
277
278impl fidl::endpoints::RequestStream for DeviceRequestStream {
279    type Protocol = DeviceMarker;
280    type ControlHandle = DeviceControlHandle;
281
282    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
283        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
284    }
285
286    fn control_handle(&self) -> Self::ControlHandle {
287        DeviceControlHandle { inner: self.inner.clone() }
288    }
289
290    fn into_inner(
291        self,
292    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
293    {
294        (self.inner, self.is_terminated)
295    }
296
297    fn from_inner(
298        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
299        is_terminated: bool,
300    ) -> Self {
301        Self { inner, is_terminated }
302    }
303}
304
305impl futures::Stream for DeviceRequestStream {
306    type Item = Result<DeviceRequest, fidl::Error>;
307
308    fn poll_next(
309        mut self: std::pin::Pin<&mut Self>,
310        cx: &mut std::task::Context<'_>,
311    ) -> std::task::Poll<Option<Self::Item>> {
312        let this = &mut *self;
313        if this.inner.check_shutdown(cx) {
314            this.is_terminated = true;
315            return std::task::Poll::Ready(None);
316        }
317        if this.is_terminated {
318            panic!("polled DeviceRequestStream after completion");
319        }
320        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
321            |bytes, handles| {
322                match this.inner.channel().read_etc(cx, bytes, handles) {
323                    std::task::Poll::Ready(Ok(())) => {}
324                    std::task::Poll::Pending => return std::task::Poll::Pending,
325                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
326                        this.is_terminated = true;
327                        return std::task::Poll::Ready(None);
328                    }
329                    std::task::Poll::Ready(Err(e)) => {
330                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
331                            e.into(),
332                        ))))
333                    }
334                }
335
336                // A message has been received from the channel
337                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
338
339                std::task::Poll::Ready(Some(match header.ordinal {
340                    0x7bba8137e24661e5 => {
341                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
342                        let mut req = fidl::new_empty!(
343                            DeviceDownloadFirmwareRequest,
344                            fidl::encoding::DefaultFuchsiaResourceDialect
345                        );
346                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceDownloadFirmwareRequest>(&header, _body_bytes, handles, &mut req)?;
347                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
348                        Ok(DeviceRequest::DownloadFirmware {
349                            firmware: req.firmware,
350                            offset: req.offset,
351
352                            responder: DeviceDownloadFirmwareResponder {
353                                control_handle: std::mem::ManuallyDrop::new(control_handle),
354                                tx_id: header.tx_id,
355                            },
356                        })
357                    }
358                    _ if header.tx_id == 0
359                        && header
360                            .dynamic_flags()
361                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
362                    {
363                        Ok(DeviceRequest::_UnknownMethod {
364                            ordinal: header.ordinal,
365                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
366                            method_type: fidl::MethodType::OneWay,
367                        })
368                    }
369                    _ if header
370                        .dynamic_flags()
371                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
372                    {
373                        this.inner.send_framework_err(
374                            fidl::encoding::FrameworkErr::UnknownMethod,
375                            header.tx_id,
376                            header.ordinal,
377                            header.dynamic_flags(),
378                            (bytes, handles),
379                        )?;
380                        Ok(DeviceRequest::_UnknownMethod {
381                            ordinal: header.ordinal,
382                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
383                            method_type: fidl::MethodType::TwoWay,
384                        })
385                    }
386                    _ => Err(fidl::Error::UnknownOrdinal {
387                        ordinal: header.ordinal,
388                        protocol_name:
389                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
390                    }),
391                }))
392            },
393        )
394    }
395}
396
397/// Client is expected to pass the vmo handle to nanohub when issuing a DownloadFirmware request.
398#[derive(Debug)]
399pub enum DeviceRequest {
400    /// Request to sent to nanohub to load the firmware.
401    DownloadFirmware {
402        firmware: fidl::Vmo,
403        offset: u64,
404        responder: DeviceDownloadFirmwareResponder,
405    },
406    /// An interaction was received which does not match any known method.
407    #[non_exhaustive]
408    _UnknownMethod {
409        /// Ordinal of the method that was called.
410        ordinal: u64,
411        control_handle: DeviceControlHandle,
412        method_type: fidl::MethodType,
413    },
414}
415
416impl DeviceRequest {
417    #[allow(irrefutable_let_patterns)]
418    pub fn into_download_firmware(
419        self,
420    ) -> Option<(fidl::Vmo, u64, DeviceDownloadFirmwareResponder)> {
421        if let DeviceRequest::DownloadFirmware { firmware, offset, responder } = self {
422            Some((firmware, offset, responder))
423        } else {
424            None
425        }
426    }
427
428    /// Name of the method defined in FIDL
429    pub fn method_name(&self) -> &'static str {
430        match *self {
431            DeviceRequest::DownloadFirmware { .. } => "download_firmware",
432            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
433                "unknown one-way method"
434            }
435            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
436                "unknown two-way method"
437            }
438        }
439    }
440}
441
442#[derive(Debug, Clone)]
443pub struct DeviceControlHandle {
444    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
445}
446
447impl fidl::endpoints::ControlHandle for DeviceControlHandle {
448    fn shutdown(&self) {
449        self.inner.shutdown()
450    }
451    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
452        self.inner.shutdown_with_epitaph(status)
453    }
454
455    fn is_closed(&self) -> bool {
456        self.inner.channel().is_closed()
457    }
458    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
459        self.inner.channel().on_closed()
460    }
461
462    #[cfg(target_os = "fuchsia")]
463    fn signal_peer(
464        &self,
465        clear_mask: zx::Signals,
466        set_mask: zx::Signals,
467    ) -> Result<(), zx_status::Status> {
468        use fidl::Peered;
469        self.inner.channel().signal_peer(clear_mask, set_mask)
470    }
471}
472
473impl DeviceControlHandle {}
474
475#[must_use = "FIDL methods require a response to be sent"]
476#[derive(Debug)]
477pub struct DeviceDownloadFirmwareResponder {
478    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
479    tx_id: u32,
480}
481
482/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
483/// if the responder is dropped without sending a response, so that the client
484/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
485impl std::ops::Drop for DeviceDownloadFirmwareResponder {
486    fn drop(&mut self) {
487        self.control_handle.shutdown();
488        // Safety: drops once, never accessed again
489        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
490    }
491}
492
493impl fidl::endpoints::Responder for DeviceDownloadFirmwareResponder {
494    type ControlHandle = DeviceControlHandle;
495
496    fn control_handle(&self) -> &DeviceControlHandle {
497        &self.control_handle
498    }
499
500    fn drop_without_shutdown(mut self) {
501        // Safety: drops once, never accessed again due to mem::forget
502        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
503        // Prevent Drop from running (which would shut down the channel)
504        std::mem::forget(self);
505    }
506}
507
508impl DeviceDownloadFirmwareResponder {
509    /// Sends a response to the FIDL transaction.
510    ///
511    /// Sets the channel to shutdown if an error occurs.
512    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
513        let _result = self.send_raw(result);
514        if _result.is_err() {
515            self.control_handle.shutdown();
516        }
517        self.drop_without_shutdown();
518        _result
519    }
520
521    /// Similar to "send" but does not shutdown the channel if an error occurs.
522    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
523        let _result = self.send_raw(result);
524        self.drop_without_shutdown();
525        _result
526    }
527
528    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
529        self.control_handle
530            .inner
531            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
532                result,
533                self.tx_id,
534                0x7bba8137e24661e5,
535                fidl::encoding::DynamicFlags::empty(),
536            )
537    }
538}
539
540#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
541pub struct ServiceMarker;
542
543#[cfg(target_os = "fuchsia")]
544impl fidl::endpoints::ServiceMarker for ServiceMarker {
545    type Proxy = ServiceProxy;
546    type Request = ServiceRequest;
547    const SERVICE_NAME: &'static str = "fuchsia.hardware.google.nanohub.Service";
548}
549
550/// A request for one of the member protocols of Service.
551///
552#[cfg(target_os = "fuchsia")]
553pub enum ServiceRequest {
554    Nanohub(DeviceRequestStream),
555}
556
557#[cfg(target_os = "fuchsia")]
558impl fidl::endpoints::ServiceRequest for ServiceRequest {
559    type Service = ServiceMarker;
560
561    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
562        match name {
563            "nanohub" => Self::Nanohub(
564                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
565            ),
566            _ => panic!("no such member protocol name for service Service"),
567        }
568    }
569
570    fn member_names() -> &'static [&'static str] {
571        &["nanohub"]
572    }
573}
574#[cfg(target_os = "fuchsia")]
575pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
576
577#[cfg(target_os = "fuchsia")]
578impl fidl::endpoints::ServiceProxy for ServiceProxy {
579    type Service = ServiceMarker;
580
581    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
582        Self(opener)
583    }
584}
585
586#[cfg(target_os = "fuchsia")]
587impl ServiceProxy {
588    pub fn connect_to_nanohub(&self) -> Result<DeviceProxy, fidl::Error> {
589        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
590        self.connect_channel_to_nanohub(server_end)?;
591        Ok(proxy)
592    }
593
594    /// Like `connect_to_nanohub`, but returns a sync proxy.
595    /// See [`Self::connect_to_nanohub`] for more details.
596    pub fn connect_to_nanohub_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
597        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
598        self.connect_channel_to_nanohub(server_end)?;
599        Ok(proxy)
600    }
601
602    /// Like `connect_to_nanohub`, but accepts a server end.
603    /// See [`Self::connect_to_nanohub`] for more details.
604    pub fn connect_channel_to_nanohub(
605        &self,
606        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
607    ) -> Result<(), fidl::Error> {
608        self.0.open_member("nanohub", server_end.into_channel())
609    }
610
611    pub fn instance_name(&self) -> &str {
612        self.0.instance_name()
613    }
614}
615
616mod internal {
617    use super::*;
618
619    impl fidl::encoding::ResourceTypeMarker for DeviceDownloadFirmwareRequest {
620        type Borrowed<'a> = &'a mut Self;
621        fn take_or_borrow<'a>(
622            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
623        ) -> Self::Borrowed<'a> {
624            value
625        }
626    }
627
628    unsafe impl fidl::encoding::TypeMarker for DeviceDownloadFirmwareRequest {
629        type Owned = Self;
630
631        #[inline(always)]
632        fn inline_align(_context: fidl::encoding::Context) -> usize {
633            8
634        }
635
636        #[inline(always)]
637        fn inline_size(_context: fidl::encoding::Context) -> usize {
638            16
639        }
640    }
641
642    unsafe impl
643        fidl::encoding::Encode<
644            DeviceDownloadFirmwareRequest,
645            fidl::encoding::DefaultFuchsiaResourceDialect,
646        > for &mut DeviceDownloadFirmwareRequest
647    {
648        #[inline]
649        unsafe fn encode(
650            self,
651            encoder: &mut fidl::encoding::Encoder<
652                '_,
653                fidl::encoding::DefaultFuchsiaResourceDialect,
654            >,
655            offset: usize,
656            _depth: fidl::encoding::Depth,
657        ) -> fidl::Result<()> {
658            encoder.debug_check_bounds::<DeviceDownloadFirmwareRequest>(offset);
659            // Delegate to tuple encoding.
660            fidl::encoding::Encode::<
661                DeviceDownloadFirmwareRequest,
662                fidl::encoding::DefaultFuchsiaResourceDialect,
663            >::encode(
664                (
665                    <fidl::encoding::HandleType<
666                        fidl::Vmo,
667                        { fidl::ObjectType::VMO.into_raw() },
668                        49271,
669                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
670                        &mut self.firmware
671                    ),
672                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.offset),
673                ),
674                encoder,
675                offset,
676                _depth,
677            )
678        }
679    }
680    unsafe impl<
681            T0: fidl::encoding::Encode<
682                fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49271>,
683                fidl::encoding::DefaultFuchsiaResourceDialect,
684            >,
685            T1: fidl::encoding::Encode<u64, fidl::encoding::DefaultFuchsiaResourceDialect>,
686        >
687        fidl::encoding::Encode<
688            DeviceDownloadFirmwareRequest,
689            fidl::encoding::DefaultFuchsiaResourceDialect,
690        > for (T0, T1)
691    {
692        #[inline]
693        unsafe fn encode(
694            self,
695            encoder: &mut fidl::encoding::Encoder<
696                '_,
697                fidl::encoding::DefaultFuchsiaResourceDialect,
698            >,
699            offset: usize,
700            depth: fidl::encoding::Depth,
701        ) -> fidl::Result<()> {
702            encoder.debug_check_bounds::<DeviceDownloadFirmwareRequest>(offset);
703            // Zero out padding regions. There's no need to apply masks
704            // because the unmasked parts will be overwritten by fields.
705            unsafe {
706                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
707                (ptr as *mut u64).write_unaligned(0);
708            }
709            // Write the fields.
710            self.0.encode(encoder, offset + 0, depth)?;
711            self.1.encode(encoder, offset + 8, depth)?;
712            Ok(())
713        }
714    }
715
716    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
717        for DeviceDownloadFirmwareRequest
718    {
719        #[inline(always)]
720        fn new_empty() -> Self {
721            Self {
722                firmware: fidl::new_empty!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49271>, fidl::encoding::DefaultFuchsiaResourceDialect),
723                offset: fidl::new_empty!(u64, fidl::encoding::DefaultFuchsiaResourceDialect),
724            }
725        }
726
727        #[inline]
728        unsafe fn decode(
729            &mut self,
730            decoder: &mut fidl::encoding::Decoder<
731                '_,
732                fidl::encoding::DefaultFuchsiaResourceDialect,
733            >,
734            offset: usize,
735            _depth: fidl::encoding::Depth,
736        ) -> fidl::Result<()> {
737            decoder.debug_check_bounds::<Self>(offset);
738            // Verify that padding bytes are zero.
739            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
740            let padval = unsafe { (ptr as *const u64).read_unaligned() };
741            let mask = 0xffffffff00000000u64;
742            let maskedval = padval & mask;
743            if maskedval != 0 {
744                return Err(fidl::Error::NonZeroPadding {
745                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
746                });
747            }
748            fidl::decode!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 49271>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.firmware, decoder, offset + 0, _depth)?;
749            fidl::decode!(
750                u64,
751                fidl::encoding::DefaultFuchsiaResourceDialect,
752                &mut self.offset,
753                decoder,
754                offset + 8,
755                _depth
756            )?;
757            Ok(())
758        }
759    }
760}