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