Skip to main content

fidl_fuchsia_hardware_usb_function/
fidl_fuchsia_hardware_usb_function.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_usb_function_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct EndpointResource {
16    pub direction: fidl_fuchsia_hardware_usb_descriptor::EndpointDirection,
17    pub endpoint: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
18    /// Information about the endpoint (e.g. Bulk, Interrupt).
19    pub ep_info: fidl_fuchsia_hardware_usb_endpoint::EndpointInfo,
20    /// The maximum packet size the endpoint supports.
21    pub max_packet_size: u32,
22}
23
24impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for EndpointResource {}
25
26#[derive(Debug, PartialEq)]
27pub struct UsbFunctionAllocResourcesRequest {
28    pub interface_count: u8,
29    pub endpoints: Vec<EndpointResource>,
30    pub strings: Vec<String>,
31}
32
33impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
34    for UsbFunctionAllocResourcesRequest
35{
36}
37
38#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
39pub struct UsbFunctionConfigureRequest {
40    pub configuration: Vec<u8>,
41    pub iface: fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>,
42}
43
44impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
45    for UsbFunctionConfigureRequest
46{
47}
48
49#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
50pub struct UsbFunctionConnectToEndpointRequest {
51    pub ep_addr: u8,
52    pub ep: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
53}
54
55impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
56    for UsbFunctionConnectToEndpointRequest
57{
58}
59
60#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
61pub struct UsbFunctionMarker;
62
63impl fidl::endpoints::ProtocolMarker for UsbFunctionMarker {
64    type Proxy = UsbFunctionProxy;
65    type RequestStream = UsbFunctionRequestStream;
66    #[cfg(target_os = "fuchsia")]
67    type SynchronousProxy = UsbFunctionSynchronousProxy;
68
69    const DEBUG_NAME: &'static str = "fuchsia.hardware.usb.function.UsbFunction";
70}
71impl fidl::endpoints::DiscoverableProtocolMarker for UsbFunctionMarker {}
72pub type UsbFunctionConnectToEndpointResult = Result<(), i32>;
73pub type UsbFunctionConfigureResult = Result<(), i32>;
74pub type UsbFunctionDeconfigureResult = Result<(), i32>;
75pub type UsbFunctionAllocResourcesResult = Result<(Vec<u8>, Vec<u8>, Vec<u8>), i32>;
76pub type UsbFunctionEndpointSetStallResult = Result<(), i32>;
77pub type UsbFunctionEndpointClearStallResult = Result<(), i32>;
78pub type UsbFunctionConfigureEndpointResult = Result<(), i32>;
79pub type UsbFunctionDisableEndpointResult = Result<(), i32>;
80
81pub trait UsbFunctionProxyInterface: Send + Sync {
82    type ConnectToEndpointResponseFut: std::future::Future<Output = Result<UsbFunctionConnectToEndpointResult, fidl::Error>>
83        + Send;
84    fn r#connect_to_endpoint(
85        &self,
86        ep_addr: u8,
87        ep: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
88    ) -> Self::ConnectToEndpointResponseFut;
89    type ConfigureResponseFut: std::future::Future<Output = Result<UsbFunctionConfigureResult, fidl::Error>>
90        + Send;
91    fn r#configure(
92        &self,
93        configuration: &[u8],
94        iface: fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>,
95    ) -> Self::ConfigureResponseFut;
96    type DeconfigureResponseFut: std::future::Future<Output = Result<UsbFunctionDeconfigureResult, fidl::Error>>
97        + Send;
98    fn r#deconfigure(&self) -> Self::DeconfigureResponseFut;
99    type AllocResourcesResponseFut: std::future::Future<Output = Result<UsbFunctionAllocResourcesResult, fidl::Error>>
100        + Send;
101    fn r#alloc_resources(
102        &self,
103        interface_count: u8,
104        endpoints: Vec<EndpointResource>,
105        strings: &[String],
106    ) -> Self::AllocResourcesResponseFut;
107    type EndpointSetStallResponseFut: std::future::Future<Output = Result<UsbFunctionEndpointSetStallResult, fidl::Error>>
108        + Send;
109    fn r#endpoint_set_stall(&self, endpoint_address: u8) -> Self::EndpointSetStallResponseFut;
110    type EndpointClearStallResponseFut: std::future::Future<Output = Result<UsbFunctionEndpointClearStallResult, fidl::Error>>
111        + Send;
112    fn r#endpoint_clear_stall(&self, endpoint_address: u8) -> Self::EndpointClearStallResponseFut;
113    type ConfigureEndpointResponseFut: std::future::Future<Output = Result<UsbFunctionConfigureEndpointResult, fidl::Error>>
114        + Send;
115    fn r#configure_endpoint(
116        &self,
117        endpoint_address: u8,
118        endpoint_configuration: &EndpointConfiguration,
119    ) -> Self::ConfigureEndpointResponseFut;
120    type DisableEndpointResponseFut: std::future::Future<Output = Result<UsbFunctionDisableEndpointResult, fidl::Error>>
121        + Send;
122    fn r#disable_endpoint(&self, endpoint_address: u8) -> Self::DisableEndpointResponseFut;
123}
124#[derive(Debug)]
125#[cfg(target_os = "fuchsia")]
126pub struct UsbFunctionSynchronousProxy {
127    client: fidl::client::sync::Client,
128}
129
130#[cfg(target_os = "fuchsia")]
131impl fidl::endpoints::SynchronousProxy for UsbFunctionSynchronousProxy {
132    type Proxy = UsbFunctionProxy;
133    type Protocol = UsbFunctionMarker;
134
135    fn from_channel(inner: fidl::Channel) -> Self {
136        Self::new(inner)
137    }
138
139    fn into_channel(self) -> fidl::Channel {
140        self.client.into_channel()
141    }
142
143    fn as_channel(&self) -> &fidl::Channel {
144        self.client.as_channel()
145    }
146}
147
148#[cfg(target_os = "fuchsia")]
149impl UsbFunctionSynchronousProxy {
150    pub fn new(channel: fidl::Channel) -> Self {
151        Self { client: fidl::client::sync::Client::new(channel) }
152    }
153
154    pub fn into_channel(self) -> fidl::Channel {
155        self.client.into_channel()
156    }
157
158    /// Waits until an event arrives and returns it. It is safe for other
159    /// threads to make concurrent requests while waiting for an event.
160    pub fn wait_for_event(
161        &self,
162        deadline: zx::MonotonicInstant,
163    ) -> Result<UsbFunctionEvent, fidl::Error> {
164        UsbFunctionEvent::decode(self.client.wait_for_event::<UsbFunctionMarker>(deadline)?)
165    }
166
167    /// Connect to an allocated endpoint.
168    ///
169    /// This must be called after the endpoint has been allocated via [`AllocResources`]. If the
170    /// endpoint channel was not provided during `AllocResources`, this method must be called to
171    /// establish the endpoint channel before any data transfers can occur on the endpoint.
172    ///
173    /// If the endpoint channels were not provided in `AllocResources` and this is never called, the
174    /// protocol client cannot communicate with the endpoint (no channel is established). This does
175    /// not prevent control-plane callbacks (like `SetConfigured`) from being made.
176    ///
177    /// The endpoint connection persists across `Configure` and `Deconfigure` calls. If the protocol
178    /// server closes the connection (server end closes), it indicates that the endpoint is no
179    /// longer available (e.g. device disconnected or function removed). The protocol client should
180    /// clean up by closing its client end of the channel, cancelling any pending I/O operations,
181    /// and stopping any tasks using the endpoint. The protocol client is not required to call
182    /// `DisableEndpoint` or `Deconfigure` in this case (and such calls may fail if the interface is
183    /// being torn down).
184    ///
185    /// * error:
186    ///     * `ZX_ERR_NOT_FOUND` if endpoint address does not exist (e.g. not allocated).
187    ///     * `ZX_ERR_ALREADY_BOUND` if the endpoint is already bound to an active channel. To
188    ///       connect a new channel, the existing channel must be closed first. Note that channel
189    ///       closure detection is asynchronous; if the protocol client closes the existing channel
190    ///       and immediately calls `ConnectToEndpoint`, it may still fail with
191    ///       `ZX_ERR_ALREADY_BOUND` if the protocol server has not yet processed the closure.
192    pub fn r#connect_to_endpoint(
193        &self,
194        mut ep_addr: u8,
195        mut ep: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
196        ___deadline: zx::MonotonicInstant,
197    ) -> Result<UsbFunctionConnectToEndpointResult, fidl::Error> {
198        let _response = self.client.send_query::<
199            UsbFunctionConnectToEndpointRequest,
200            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
201            UsbFunctionMarker,
202        >(
203            (ep_addr, ep,),
204            0x11541c67eb1b7f8,
205            fidl::encoding::DynamicFlags::empty(),
206            ___deadline,
207        )?;
208        Ok(_response.map(|x| x))
209    }
210
211    /// Configure the function with the given descriptors.
212    ///
213    /// **Ordering**: This must be called after `AllocResources` has been called to allocate all
214    /// interfaces, endpoints, and strings referenced in the descriptors. Calling this when already
215    /// configured returns `ZX_ERR_ALREADY_BOUND`.
216    ///
217    /// This binds the [`UsbFunctionInterface`] callback channel (where the protocol client acts as
218    /// the server).
219    ///
220    /// `configuration` is a vector of concatenated USB descriptors in standard USB wire format
221    /// (Interface -> Endpoint -> Class/Vendor descriptors). A raw byte vector is used to allow
222    /// arbitrary class-specific and vendor-specific descriptors that cannot be statically defined
223    /// in FIDL.
224    ///
225    /// This byte vector is expected to contain one or more interface descriptors following the
226    /// USB specification.
227    ///
228    /// This descriptor block is cached by the peripheral controller and sent *as-is* to the host in
229    /// response to standard host `GET_DESCRIPTOR` (Configuration) requests.
230    ///
231    /// **Structure and Validation**:
232    /// - Must begin with an Interface or Interface Association descriptor.
233    /// - Standard descriptors (Interface, Endpoint) embedded in the vector must follow the standard
234    ///   USB specification descriptor layouts.
235    /// - All interface numbers and endpoint addresses must match the resources allocated in
236    ///   [`AllocResources`].
237    /// - The peripheral controller parses this vector linearly using descriptor length fields.
238    ///   Mismatched resource IDs or malformed layouts return `ZX_ERR_INVALID_ARGS`.
239    ///
240    /// `iface` is the client end of [`UsbFunctionInterface`] which the protocol server uses to send
241    /// events to the protocol client.
242    ///
243    /// The function remains configured until `Deconfigure` is called or the `iface` channel is
244    /// closed. If `iface` is closed, the function is automatically deconfigured, which stops the
245    /// peripheral controller and disconnects the device from the host.
246    ///
247    /// * error:
248    ///     * `ZX_ERR_INVALID_ARGS` if the configuration is invalid or references unallocated
249    ///       resources.
250    ///     * `ZX_ERR_ALREADY_BOUND` if the function interface is already bound.
251    ///     * `ZX_ERR_NO_MEMORY` if the protocol server fails to allocate memory to store the
252    ///       descriptors.
253    ///     * `ZX_ERR_BAD_STATE` if the peripheral device is stopping or tearing down.
254    pub fn r#configure(
255        &self,
256        mut configuration: &[u8],
257        mut iface: fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>,
258        ___deadline: zx::MonotonicInstant,
259    ) -> Result<UsbFunctionConfigureResult, fidl::Error> {
260        let _response = self.client.send_query::<
261            UsbFunctionConfigureRequest,
262            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
263            UsbFunctionMarker,
264        >(
265            (configuration, iface,),
266            0x42a444f4abf08b89,
267            fidl::encoding::DynamicFlags::empty(),
268            ___deadline,
269        )?;
270        Ok(_response.map(|x| x))
271    }
272
273    /// Deconfigure the function.
274    ///
275    /// **Ordering**: Can be called at any time. If the function is not configured, it trivially
276    /// succeeds.
277    ///
278    /// This is the opposite of `Configure`. The protocol server disables all physical endpoints
279    /// for this function, clears its stored descriptors, and unbinds the `iface` channel. If the
280    /// function was active, the peripheral controller may trigger a USB re-enumeration to reflect
281    /// the updated function configuration.
282    ///
283    /// This does *not* close the endpoint channels (they remain connected and can be reused if the
284    /// function is re-configured).
285    ///
286    /// * error:
287    ///     * `ZX_ERR_UNAVAILABLE` if a deconfiguration is already in progress.
288    pub fn r#deconfigure(
289        &self,
290        ___deadline: zx::MonotonicInstant,
291    ) -> Result<UsbFunctionDeconfigureResult, fidl::Error> {
292        let _response = self.client.send_query::<
293            fidl::encoding::EmptyPayload,
294            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
295            UsbFunctionMarker,
296        >(
297            (),
298            0x26ee8c8c826367b2,
299            fidl::encoding::DynamicFlags::empty(),
300            ___deadline,
301        )?;
302        Ok(_response.map(|x| x))
303    }
304
305    /// Allocate resources for the function.
306    ///
307    /// This method is atomic. If any resource allocation fails, all allocations made during this
308    /// call are rolled back.
309    ///
310    /// This must be called during driver initialization before `Configure`. Calling this after the
311    /// function has been configured returns `ZX_ERR_BAD_STATE`.
312    ///
313    /// `interface_count` informs how many interfaces to create. `interface_nums` returns a vector
314    /// of length `interface_count` containing the allocated interface numbers.
315    ///
316    /// `endpoints` is a vector of endpoints to allocate. The direction and endpoint server end are
317    /// provided. The protocol client can optionally provide endpoint channels in `endpoints`
318    /// to connect them immediately. If an endpoint channel is not provided, the protocol client
319    /// must call [`ConnectToEndpoint`] later to use it. `endpoint_addrs` returns a vector of the
320    /// same size containing the allocated endpoint addresses, where element `i` corresponds 1:1
321    /// to element `i` of `endpoints`. All endpoint channels provided here or connected later via
322    /// [`ConnectToEndpoint`] persist across [`Configure`] and [`Deconfigure`] calls.
323    ///
324    /// `strings` is a vector of strings to allocate. `string_indices` returns a vector of the
325    /// same size containing the allocated string indices, where element `i` corresponds 1:1 to
326    /// element `i` of `strings`.
327    ///
328    /// Returns the interface ids, endpoint ids, and string ids that were allocated. On error, no
329    /// resources are allocated.
330    ///
331    /// The allocated resource numbers and addresses remain allocated for the lifetime of the
332    /// connection to `UsbFunction`. They are *not* freed on `Deconfigure`.
333    ///
334    /// * error:
335    ///     * `ZX_ERR_BAD_STATE` if the function has already been configured.
336    ///     * `ZX_ERR_NO_RESOURCES` if any resource namespace numbers are exhausted.
337    ///     * `ZX_ERR_INVALID_ARGS` if the endpoint configuration contains invalid arguments.
338    pub fn r#alloc_resources(
339        &self,
340        mut interface_count: u8,
341        mut endpoints: Vec<EndpointResource>,
342        mut strings: &[String],
343        ___deadline: zx::MonotonicInstant,
344    ) -> Result<UsbFunctionAllocResourcesResult, fidl::Error> {
345        let _response = self.client.send_query::<
346            UsbFunctionAllocResourcesRequest,
347            fidl::encoding::ResultType<UsbFunctionAllocResourcesResponse, i32>,
348            UsbFunctionMarker,
349        >(
350            (interface_count, endpoints.as_mut(), strings,),
351            0x5ab7133ab195daa0,
352            fidl::encoding::DynamicFlags::empty(),
353            ___deadline,
354        )?;
355        Ok(_response.map(|x| (x.interface_nums, x.endpoint_addrs, x.string_indices)))
356    }
357
358    /// Stall the endpoint.
359    ///
360    /// The endpoint must have been allocated and configured.
361    ///
362    /// This method returns after the hardware confirms the stall condition is active. All pending
363    /// transfers queued on the endpoint are cancelled and completed with `ZX_ERR_IO_REFUSED` via
364    /// `OnCompletion`. While the endpoint is stalled, any new requests submitted via
365    /// `QueueRequests` must immediately fail and complete with `ZX_ERR_IO_REFUSED`.
366    ///
367    /// * error:
368    ///     * `ZX_ERR_BAD_STATE` if the function is not configured.
369    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
370    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
371    pub fn r#endpoint_set_stall(
372        &self,
373        mut endpoint_address: u8,
374        ___deadline: zx::MonotonicInstant,
375    ) -> Result<UsbFunctionEndpointSetStallResult, fidl::Error> {
376        let _response = self.client.send_query::<
377            UsbFunctionEndpointSetStallRequest,
378            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
379            UsbFunctionMarker,
380        >(
381            (endpoint_address,),
382            0x1f32c374dac955f1,
383            fidl::encoding::DynamicFlags::empty(),
384            ___deadline,
385        )?;
386        Ok(_response.map(|x| x))
387    }
388
389    /// Clear the endpoint's stalled state.
390    ///
391    /// The endpoint must have been allocated and configured.
392    ///
393    /// This method returns after the hardware confirms the stall has been cleared. As required by
394    /// USB 2.0 Section 9.4.5, clearing the halt feature also resets the endpoint's data toggle bit
395    /// to `DATA0` in hardware. The client must resubmit any cancelled transfers once the endpoint
396    /// is cleared. Any requests queued *after* this method returns are processed normally.
397    ///
398    /// * error:
399    ///     * `ZX_ERR_BAD_STATE` if the function is not configured.
400    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
401    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
402    pub fn r#endpoint_clear_stall(
403        &self,
404        mut endpoint_address: u8,
405        ___deadline: zx::MonotonicInstant,
406    ) -> Result<UsbFunctionEndpointClearStallResult, fidl::Error> {
407        let _response = self.client.send_query::<
408            UsbFunctionEndpointClearStallRequest,
409            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
410            UsbFunctionMarker,
411        >(
412            (endpoint_address,),
413            0x221d9488ac58aaba,
414            fidl::encoding::DynamicFlags::empty(),
415            ___deadline,
416        )?;
417        Ok(_response.map(|x| x))
418    }
419
420    /// Configure and enable an endpoint with the given configuration.
421    ///
422    /// Called by the function driver in response to `SetConfigured` (when `configured == true`) or
423    /// `SetInterface` requests to enable physical transfers on the endpoint. Calling this before
424    /// the function has been configured via `Configure` returns `ZX_ERR_BAD_STATE`. Clients should
425    /// wait for the `SetConfigured` or `SetInterface` request before configuring endpoints to
426    /// ensure the host is ready.
427    ///
428    /// The endpoint must have been allocated via `AllocResources`.
429    ///
430    /// Returns only after the physical endpoint has been configured by the DCI driver.
431    ///
432    /// See USB 2.0 Specification Section 9.6.6 (Endpoint Descriptor) for details on the standard
433    /// endpoint configuration fields mapped in `EndpointConfiguration`.
434    ///
435    /// * error:
436    ///     * `ZX_ERR_BAD_STATE` if the function is not configured.
437    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
438    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
439    ///     * `ZX_ERR_INVALID_ARGS` if the configuration is invalid.
440    pub fn r#configure_endpoint(
441        &self,
442        mut endpoint_address: u8,
443        mut endpoint_configuration: &EndpointConfiguration,
444        ___deadline: zx::MonotonicInstant,
445    ) -> Result<UsbFunctionConfigureEndpointResult, fidl::Error> {
446        let _response = self.client.send_query::<
447            UsbFunctionConfigureEndpointRequest,
448            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
449            UsbFunctionMarker,
450        >(
451            (endpoint_address, endpoint_configuration,),
452            0x314c9dc3c37ebb7c,
453            fidl::encoding::DynamicFlags::empty(),
454            ___deadline,
455        )?;
456        Ok(_response.map(|x| x))
457    }
458
459    /// Disable an endpoint.
460    ///
461    /// Called by the function driver in response to `SetConfigured` (when `configured == false`)
462    /// or `SetInterface` requests to disable physical transfers on the endpoint. Calling this when
463    /// the endpoint is already disabled is a no-op and returns `ZX_OK`. If called before the
464    /// function has been configured via `Configure`, it also trivially succeeds (`ZX_OK`), as the
465    /// endpoint is already unconfigured and disabled.
466    ///
467    /// The endpoint must have been allocated via `AllocResources`.
468    ///
469    /// Returns only after the physical endpoint has been disabled by the DCI driver.
470    ///
471    /// * error:
472    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
473    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
474    pub fn r#disable_endpoint(
475        &self,
476        mut endpoint_address: u8,
477        ___deadline: zx::MonotonicInstant,
478    ) -> Result<UsbFunctionDisableEndpointResult, fidl::Error> {
479        let _response = self.client.send_query::<
480            UsbFunctionDisableEndpointRequest,
481            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
482            UsbFunctionMarker,
483        >(
484            (endpoint_address,),
485            0x112a132561499b6e,
486            fidl::encoding::DynamicFlags::empty(),
487            ___deadline,
488        )?;
489        Ok(_response.map(|x| x))
490    }
491}
492
493#[cfg(target_os = "fuchsia")]
494impl From<UsbFunctionSynchronousProxy> for zx::NullableHandle {
495    fn from(value: UsbFunctionSynchronousProxy) -> Self {
496        value.into_channel().into()
497    }
498}
499
500#[cfg(target_os = "fuchsia")]
501impl From<fidl::Channel> for UsbFunctionSynchronousProxy {
502    fn from(value: fidl::Channel) -> Self {
503        Self::new(value)
504    }
505}
506
507#[cfg(target_os = "fuchsia")]
508impl fidl::endpoints::FromClient for UsbFunctionSynchronousProxy {
509    type Protocol = UsbFunctionMarker;
510
511    fn from_client(value: fidl::endpoints::ClientEnd<UsbFunctionMarker>) -> Self {
512        Self::new(value.into_channel())
513    }
514}
515
516#[derive(Debug, Clone)]
517pub struct UsbFunctionProxy {
518    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
519}
520
521impl fidl::endpoints::Proxy for UsbFunctionProxy {
522    type Protocol = UsbFunctionMarker;
523
524    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
525        Self::new(inner)
526    }
527
528    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
529        self.client.into_channel().map_err(|client| Self { client })
530    }
531
532    fn as_channel(&self) -> &::fidl::AsyncChannel {
533        self.client.as_channel()
534    }
535}
536
537impl UsbFunctionProxy {
538    /// Create a new Proxy for fuchsia.hardware.usb.function/UsbFunction.
539    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
540        let protocol_name = <UsbFunctionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
541        Self { client: fidl::client::Client::new(channel, protocol_name) }
542    }
543
544    /// Get a Stream of events from the remote end of the protocol.
545    ///
546    /// # Panics
547    ///
548    /// Panics if the event stream was already taken.
549    pub fn take_event_stream(&self) -> UsbFunctionEventStream {
550        UsbFunctionEventStream { event_receiver: self.client.take_event_receiver() }
551    }
552
553    /// Connect to an allocated endpoint.
554    ///
555    /// This must be called after the endpoint has been allocated via [`AllocResources`]. If the
556    /// endpoint channel was not provided during `AllocResources`, this method must be called to
557    /// establish the endpoint channel before any data transfers can occur on the endpoint.
558    ///
559    /// If the endpoint channels were not provided in `AllocResources` and this is never called, the
560    /// protocol client cannot communicate with the endpoint (no channel is established). This does
561    /// not prevent control-plane callbacks (like `SetConfigured`) from being made.
562    ///
563    /// The endpoint connection persists across `Configure` and `Deconfigure` calls. If the protocol
564    /// server closes the connection (server end closes), it indicates that the endpoint is no
565    /// longer available (e.g. device disconnected or function removed). The protocol client should
566    /// clean up by closing its client end of the channel, cancelling any pending I/O operations,
567    /// and stopping any tasks using the endpoint. The protocol client is not required to call
568    /// `DisableEndpoint` or `Deconfigure` in this case (and such calls may fail if the interface is
569    /// being torn down).
570    ///
571    /// * error:
572    ///     * `ZX_ERR_NOT_FOUND` if endpoint address does not exist (e.g. not allocated).
573    ///     * `ZX_ERR_ALREADY_BOUND` if the endpoint is already bound to an active channel. To
574    ///       connect a new channel, the existing channel must be closed first. Note that channel
575    ///       closure detection is asynchronous; if the protocol client closes the existing channel
576    ///       and immediately calls `ConnectToEndpoint`, it may still fail with
577    ///       `ZX_ERR_ALREADY_BOUND` if the protocol server has not yet processed the closure.
578    pub fn r#connect_to_endpoint(
579        &self,
580        mut ep_addr: u8,
581        mut ep: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
582    ) -> fidl::client::QueryResponseFut<
583        UsbFunctionConnectToEndpointResult,
584        fidl::encoding::DefaultFuchsiaResourceDialect,
585    > {
586        UsbFunctionProxyInterface::r#connect_to_endpoint(self, ep_addr, ep)
587    }
588
589    /// Configure the function with the given descriptors.
590    ///
591    /// **Ordering**: This must be called after `AllocResources` has been called to allocate all
592    /// interfaces, endpoints, and strings referenced in the descriptors. Calling this when already
593    /// configured returns `ZX_ERR_ALREADY_BOUND`.
594    ///
595    /// This binds the [`UsbFunctionInterface`] callback channel (where the protocol client acts as
596    /// the server).
597    ///
598    /// `configuration` is a vector of concatenated USB descriptors in standard USB wire format
599    /// (Interface -> Endpoint -> Class/Vendor descriptors). A raw byte vector is used to allow
600    /// arbitrary class-specific and vendor-specific descriptors that cannot be statically defined
601    /// in FIDL.
602    ///
603    /// This byte vector is expected to contain one or more interface descriptors following the
604    /// USB specification.
605    ///
606    /// This descriptor block is cached by the peripheral controller and sent *as-is* to the host in
607    /// response to standard host `GET_DESCRIPTOR` (Configuration) requests.
608    ///
609    /// **Structure and Validation**:
610    /// - Must begin with an Interface or Interface Association descriptor.
611    /// - Standard descriptors (Interface, Endpoint) embedded in the vector must follow the standard
612    ///   USB specification descriptor layouts.
613    /// - All interface numbers and endpoint addresses must match the resources allocated in
614    ///   [`AllocResources`].
615    /// - The peripheral controller parses this vector linearly using descriptor length fields.
616    ///   Mismatched resource IDs or malformed layouts return `ZX_ERR_INVALID_ARGS`.
617    ///
618    /// `iface` is the client end of [`UsbFunctionInterface`] which the protocol server uses to send
619    /// events to the protocol client.
620    ///
621    /// The function remains configured until `Deconfigure` is called or the `iface` channel is
622    /// closed. If `iface` is closed, the function is automatically deconfigured, which stops the
623    /// peripheral controller and disconnects the device from the host.
624    ///
625    /// * error:
626    ///     * `ZX_ERR_INVALID_ARGS` if the configuration is invalid or references unallocated
627    ///       resources.
628    ///     * `ZX_ERR_ALREADY_BOUND` if the function interface is already bound.
629    ///     * `ZX_ERR_NO_MEMORY` if the protocol server fails to allocate memory to store the
630    ///       descriptors.
631    ///     * `ZX_ERR_BAD_STATE` if the peripheral device is stopping or tearing down.
632    pub fn r#configure(
633        &self,
634        mut configuration: &[u8],
635        mut iface: fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>,
636    ) -> fidl::client::QueryResponseFut<
637        UsbFunctionConfigureResult,
638        fidl::encoding::DefaultFuchsiaResourceDialect,
639    > {
640        UsbFunctionProxyInterface::r#configure(self, configuration, iface)
641    }
642
643    /// Deconfigure the function.
644    ///
645    /// **Ordering**: Can be called at any time. If the function is not configured, it trivially
646    /// succeeds.
647    ///
648    /// This is the opposite of `Configure`. The protocol server disables all physical endpoints
649    /// for this function, clears its stored descriptors, and unbinds the `iface` channel. If the
650    /// function was active, the peripheral controller may trigger a USB re-enumeration to reflect
651    /// the updated function configuration.
652    ///
653    /// This does *not* close the endpoint channels (they remain connected and can be reused if the
654    /// function is re-configured).
655    ///
656    /// * error:
657    ///     * `ZX_ERR_UNAVAILABLE` if a deconfiguration is already in progress.
658    pub fn r#deconfigure(
659        &self,
660    ) -> fidl::client::QueryResponseFut<
661        UsbFunctionDeconfigureResult,
662        fidl::encoding::DefaultFuchsiaResourceDialect,
663    > {
664        UsbFunctionProxyInterface::r#deconfigure(self)
665    }
666
667    /// Allocate resources for the function.
668    ///
669    /// This method is atomic. If any resource allocation fails, all allocations made during this
670    /// call are rolled back.
671    ///
672    /// This must be called during driver initialization before `Configure`. Calling this after the
673    /// function has been configured returns `ZX_ERR_BAD_STATE`.
674    ///
675    /// `interface_count` informs how many interfaces to create. `interface_nums` returns a vector
676    /// of length `interface_count` containing the allocated interface numbers.
677    ///
678    /// `endpoints` is a vector of endpoints to allocate. The direction and endpoint server end are
679    /// provided. The protocol client can optionally provide endpoint channels in `endpoints`
680    /// to connect them immediately. If an endpoint channel is not provided, the protocol client
681    /// must call [`ConnectToEndpoint`] later to use it. `endpoint_addrs` returns a vector of the
682    /// same size containing the allocated endpoint addresses, where element `i` corresponds 1:1
683    /// to element `i` of `endpoints`. All endpoint channels provided here or connected later via
684    /// [`ConnectToEndpoint`] persist across [`Configure`] and [`Deconfigure`] calls.
685    ///
686    /// `strings` is a vector of strings to allocate. `string_indices` returns a vector of the
687    /// same size containing the allocated string indices, where element `i` corresponds 1:1 to
688    /// element `i` of `strings`.
689    ///
690    /// Returns the interface ids, endpoint ids, and string ids that were allocated. On error, no
691    /// resources are allocated.
692    ///
693    /// The allocated resource numbers and addresses remain allocated for the lifetime of the
694    /// connection to `UsbFunction`. They are *not* freed on `Deconfigure`.
695    ///
696    /// * error:
697    ///     * `ZX_ERR_BAD_STATE` if the function has already been configured.
698    ///     * `ZX_ERR_NO_RESOURCES` if any resource namespace numbers are exhausted.
699    ///     * `ZX_ERR_INVALID_ARGS` if the endpoint configuration contains invalid arguments.
700    pub fn r#alloc_resources(
701        &self,
702        mut interface_count: u8,
703        mut endpoints: Vec<EndpointResource>,
704        mut strings: &[String],
705    ) -> fidl::client::QueryResponseFut<
706        UsbFunctionAllocResourcesResult,
707        fidl::encoding::DefaultFuchsiaResourceDialect,
708    > {
709        UsbFunctionProxyInterface::r#alloc_resources(self, interface_count, endpoints, strings)
710    }
711
712    /// Stall the endpoint.
713    ///
714    /// The endpoint must have been allocated and configured.
715    ///
716    /// This method returns after the hardware confirms the stall condition is active. All pending
717    /// transfers queued on the endpoint are cancelled and completed with `ZX_ERR_IO_REFUSED` via
718    /// `OnCompletion`. While the endpoint is stalled, any new requests submitted via
719    /// `QueueRequests` must immediately fail and complete with `ZX_ERR_IO_REFUSED`.
720    ///
721    /// * error:
722    ///     * `ZX_ERR_BAD_STATE` if the function is not configured.
723    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
724    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
725    pub fn r#endpoint_set_stall(
726        &self,
727        mut endpoint_address: u8,
728    ) -> fidl::client::QueryResponseFut<
729        UsbFunctionEndpointSetStallResult,
730        fidl::encoding::DefaultFuchsiaResourceDialect,
731    > {
732        UsbFunctionProxyInterface::r#endpoint_set_stall(self, endpoint_address)
733    }
734
735    /// Clear the endpoint's stalled state.
736    ///
737    /// The endpoint must have been allocated and configured.
738    ///
739    /// This method returns after the hardware confirms the stall has been cleared. As required by
740    /// USB 2.0 Section 9.4.5, clearing the halt feature also resets the endpoint's data toggle bit
741    /// to `DATA0` in hardware. The client must resubmit any cancelled transfers once the endpoint
742    /// is cleared. Any requests queued *after* this method returns are processed normally.
743    ///
744    /// * error:
745    ///     * `ZX_ERR_BAD_STATE` if the function is not configured.
746    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
747    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
748    pub fn r#endpoint_clear_stall(
749        &self,
750        mut endpoint_address: u8,
751    ) -> fidl::client::QueryResponseFut<
752        UsbFunctionEndpointClearStallResult,
753        fidl::encoding::DefaultFuchsiaResourceDialect,
754    > {
755        UsbFunctionProxyInterface::r#endpoint_clear_stall(self, endpoint_address)
756    }
757
758    /// Configure and enable an endpoint with the given configuration.
759    ///
760    /// Called by the function driver in response to `SetConfigured` (when `configured == true`) or
761    /// `SetInterface` requests to enable physical transfers on the endpoint. Calling this before
762    /// the function has been configured via `Configure` returns `ZX_ERR_BAD_STATE`. Clients should
763    /// wait for the `SetConfigured` or `SetInterface` request before configuring endpoints to
764    /// ensure the host is ready.
765    ///
766    /// The endpoint must have been allocated via `AllocResources`.
767    ///
768    /// Returns only after the physical endpoint has been configured by the DCI driver.
769    ///
770    /// See USB 2.0 Specification Section 9.6.6 (Endpoint Descriptor) for details on the standard
771    /// endpoint configuration fields mapped in `EndpointConfiguration`.
772    ///
773    /// * error:
774    ///     * `ZX_ERR_BAD_STATE` if the function is not configured.
775    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
776    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
777    ///     * `ZX_ERR_INVALID_ARGS` if the configuration is invalid.
778    pub fn r#configure_endpoint(
779        &self,
780        mut endpoint_address: u8,
781        mut endpoint_configuration: &EndpointConfiguration,
782    ) -> fidl::client::QueryResponseFut<
783        UsbFunctionConfigureEndpointResult,
784        fidl::encoding::DefaultFuchsiaResourceDialect,
785    > {
786        UsbFunctionProxyInterface::r#configure_endpoint(
787            self,
788            endpoint_address,
789            endpoint_configuration,
790        )
791    }
792
793    /// Disable an endpoint.
794    ///
795    /// Called by the function driver in response to `SetConfigured` (when `configured == false`)
796    /// or `SetInterface` requests to disable physical transfers on the endpoint. Calling this when
797    /// the endpoint is already disabled is a no-op and returns `ZX_OK`. If called before the
798    /// function has been configured via `Configure`, it also trivially succeeds (`ZX_OK`), as the
799    /// endpoint is already unconfigured and disabled.
800    ///
801    /// The endpoint must have been allocated via `AllocResources`.
802    ///
803    /// Returns only after the physical endpoint has been disabled by the DCI driver.
804    ///
805    /// * error:
806    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
807    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
808    pub fn r#disable_endpoint(
809        &self,
810        mut endpoint_address: u8,
811    ) -> fidl::client::QueryResponseFut<
812        UsbFunctionDisableEndpointResult,
813        fidl::encoding::DefaultFuchsiaResourceDialect,
814    > {
815        UsbFunctionProxyInterface::r#disable_endpoint(self, endpoint_address)
816    }
817}
818
819impl UsbFunctionProxyInterface for UsbFunctionProxy {
820    type ConnectToEndpointResponseFut = fidl::client::QueryResponseFut<
821        UsbFunctionConnectToEndpointResult,
822        fidl::encoding::DefaultFuchsiaResourceDialect,
823    >;
824    fn r#connect_to_endpoint(
825        &self,
826        mut ep_addr: u8,
827        mut ep: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
828    ) -> Self::ConnectToEndpointResponseFut {
829        fn _decode(
830            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
831        ) -> Result<UsbFunctionConnectToEndpointResult, fidl::Error> {
832            let _response = fidl::client::decode_transaction_body::<
833                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
834                fidl::encoding::DefaultFuchsiaResourceDialect,
835                0x11541c67eb1b7f8,
836            >(_buf?)?;
837            Ok(_response.map(|x| x))
838        }
839        self.client.send_query_and_decode::<
840            UsbFunctionConnectToEndpointRequest,
841            UsbFunctionConnectToEndpointResult,
842        >(
843            (ep_addr, ep,),
844            0x11541c67eb1b7f8,
845            fidl::encoding::DynamicFlags::empty(),
846            _decode,
847        )
848    }
849
850    type ConfigureResponseFut = fidl::client::QueryResponseFut<
851        UsbFunctionConfigureResult,
852        fidl::encoding::DefaultFuchsiaResourceDialect,
853    >;
854    fn r#configure(
855        &self,
856        mut configuration: &[u8],
857        mut iface: fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>,
858    ) -> Self::ConfigureResponseFut {
859        fn _decode(
860            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
861        ) -> Result<UsbFunctionConfigureResult, fidl::Error> {
862            let _response = fidl::client::decode_transaction_body::<
863                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
864                fidl::encoding::DefaultFuchsiaResourceDialect,
865                0x42a444f4abf08b89,
866            >(_buf?)?;
867            Ok(_response.map(|x| x))
868        }
869        self.client
870            .send_query_and_decode::<UsbFunctionConfigureRequest, UsbFunctionConfigureResult>(
871                (configuration, iface),
872                0x42a444f4abf08b89,
873                fidl::encoding::DynamicFlags::empty(),
874                _decode,
875            )
876    }
877
878    type DeconfigureResponseFut = fidl::client::QueryResponseFut<
879        UsbFunctionDeconfigureResult,
880        fidl::encoding::DefaultFuchsiaResourceDialect,
881    >;
882    fn r#deconfigure(&self) -> Self::DeconfigureResponseFut {
883        fn _decode(
884            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
885        ) -> Result<UsbFunctionDeconfigureResult, fidl::Error> {
886            let _response = fidl::client::decode_transaction_body::<
887                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
888                fidl::encoding::DefaultFuchsiaResourceDialect,
889                0x26ee8c8c826367b2,
890            >(_buf?)?;
891            Ok(_response.map(|x| x))
892        }
893        self.client
894            .send_query_and_decode::<fidl::encoding::EmptyPayload, UsbFunctionDeconfigureResult>(
895                (),
896                0x26ee8c8c826367b2,
897                fidl::encoding::DynamicFlags::empty(),
898                _decode,
899            )
900    }
901
902    type AllocResourcesResponseFut = fidl::client::QueryResponseFut<
903        UsbFunctionAllocResourcesResult,
904        fidl::encoding::DefaultFuchsiaResourceDialect,
905    >;
906    fn r#alloc_resources(
907        &self,
908        mut interface_count: u8,
909        mut endpoints: Vec<EndpointResource>,
910        mut strings: &[String],
911    ) -> Self::AllocResourcesResponseFut {
912        fn _decode(
913            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
914        ) -> Result<UsbFunctionAllocResourcesResult, fidl::Error> {
915            let _response = fidl::client::decode_transaction_body::<
916                fidl::encoding::ResultType<UsbFunctionAllocResourcesResponse, i32>,
917                fidl::encoding::DefaultFuchsiaResourceDialect,
918                0x5ab7133ab195daa0,
919            >(_buf?)?;
920            Ok(_response.map(|x| (x.interface_nums, x.endpoint_addrs, x.string_indices)))
921        }
922        self.client.send_query_and_decode::<
923            UsbFunctionAllocResourcesRequest,
924            UsbFunctionAllocResourcesResult,
925        >(
926            (interface_count, endpoints.as_mut(), strings,),
927            0x5ab7133ab195daa0,
928            fidl::encoding::DynamicFlags::empty(),
929            _decode,
930        )
931    }
932
933    type EndpointSetStallResponseFut = fidl::client::QueryResponseFut<
934        UsbFunctionEndpointSetStallResult,
935        fidl::encoding::DefaultFuchsiaResourceDialect,
936    >;
937    fn r#endpoint_set_stall(&self, mut endpoint_address: u8) -> Self::EndpointSetStallResponseFut {
938        fn _decode(
939            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
940        ) -> Result<UsbFunctionEndpointSetStallResult, fidl::Error> {
941            let _response = fidl::client::decode_transaction_body::<
942                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
943                fidl::encoding::DefaultFuchsiaResourceDialect,
944                0x1f32c374dac955f1,
945            >(_buf?)?;
946            Ok(_response.map(|x| x))
947        }
948        self.client.send_query_and_decode::<
949            UsbFunctionEndpointSetStallRequest,
950            UsbFunctionEndpointSetStallResult,
951        >(
952            (endpoint_address,),
953            0x1f32c374dac955f1,
954            fidl::encoding::DynamicFlags::empty(),
955            _decode,
956        )
957    }
958
959    type EndpointClearStallResponseFut = fidl::client::QueryResponseFut<
960        UsbFunctionEndpointClearStallResult,
961        fidl::encoding::DefaultFuchsiaResourceDialect,
962    >;
963    fn r#endpoint_clear_stall(
964        &self,
965        mut endpoint_address: u8,
966    ) -> Self::EndpointClearStallResponseFut {
967        fn _decode(
968            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
969        ) -> Result<UsbFunctionEndpointClearStallResult, fidl::Error> {
970            let _response = fidl::client::decode_transaction_body::<
971                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
972                fidl::encoding::DefaultFuchsiaResourceDialect,
973                0x221d9488ac58aaba,
974            >(_buf?)?;
975            Ok(_response.map(|x| x))
976        }
977        self.client.send_query_and_decode::<
978            UsbFunctionEndpointClearStallRequest,
979            UsbFunctionEndpointClearStallResult,
980        >(
981            (endpoint_address,),
982            0x221d9488ac58aaba,
983            fidl::encoding::DynamicFlags::empty(),
984            _decode,
985        )
986    }
987
988    type ConfigureEndpointResponseFut = fidl::client::QueryResponseFut<
989        UsbFunctionConfigureEndpointResult,
990        fidl::encoding::DefaultFuchsiaResourceDialect,
991    >;
992    fn r#configure_endpoint(
993        &self,
994        mut endpoint_address: u8,
995        mut endpoint_configuration: &EndpointConfiguration,
996    ) -> Self::ConfigureEndpointResponseFut {
997        fn _decode(
998            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
999        ) -> Result<UsbFunctionConfigureEndpointResult, fidl::Error> {
1000            let _response = fidl::client::decode_transaction_body::<
1001                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1002                fidl::encoding::DefaultFuchsiaResourceDialect,
1003                0x314c9dc3c37ebb7c,
1004            >(_buf?)?;
1005            Ok(_response.map(|x| x))
1006        }
1007        self.client.send_query_and_decode::<
1008            UsbFunctionConfigureEndpointRequest,
1009            UsbFunctionConfigureEndpointResult,
1010        >(
1011            (endpoint_address, endpoint_configuration,),
1012            0x314c9dc3c37ebb7c,
1013            fidl::encoding::DynamicFlags::empty(),
1014            _decode,
1015        )
1016    }
1017
1018    type DisableEndpointResponseFut = fidl::client::QueryResponseFut<
1019        UsbFunctionDisableEndpointResult,
1020        fidl::encoding::DefaultFuchsiaResourceDialect,
1021    >;
1022    fn r#disable_endpoint(&self, mut endpoint_address: u8) -> Self::DisableEndpointResponseFut {
1023        fn _decode(
1024            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1025        ) -> Result<UsbFunctionDisableEndpointResult, fidl::Error> {
1026            let _response = fidl::client::decode_transaction_body::<
1027                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1028                fidl::encoding::DefaultFuchsiaResourceDialect,
1029                0x112a132561499b6e,
1030            >(_buf?)?;
1031            Ok(_response.map(|x| x))
1032        }
1033        self.client.send_query_and_decode::<
1034            UsbFunctionDisableEndpointRequest,
1035            UsbFunctionDisableEndpointResult,
1036        >(
1037            (endpoint_address,),
1038            0x112a132561499b6e,
1039            fidl::encoding::DynamicFlags::empty(),
1040            _decode,
1041        )
1042    }
1043}
1044
1045pub struct UsbFunctionEventStream {
1046    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1047}
1048
1049impl std::marker::Unpin for UsbFunctionEventStream {}
1050
1051impl futures::stream::FusedStream for UsbFunctionEventStream {
1052    fn is_terminated(&self) -> bool {
1053        self.event_receiver.is_terminated()
1054    }
1055}
1056
1057impl futures::Stream for UsbFunctionEventStream {
1058    type Item = Result<UsbFunctionEvent, fidl::Error>;
1059
1060    fn poll_next(
1061        mut self: std::pin::Pin<&mut Self>,
1062        cx: &mut std::task::Context<'_>,
1063    ) -> std::task::Poll<Option<Self::Item>> {
1064        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1065            &mut self.event_receiver,
1066            cx
1067        )?) {
1068            Some(buf) => std::task::Poll::Ready(Some(UsbFunctionEvent::decode(buf))),
1069            None => std::task::Poll::Ready(None),
1070        }
1071    }
1072}
1073
1074#[derive(Debug)]
1075pub enum UsbFunctionEvent {}
1076
1077impl UsbFunctionEvent {
1078    /// Decodes a message buffer as a [`UsbFunctionEvent`].
1079    fn decode(
1080        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1081    ) -> Result<UsbFunctionEvent, fidl::Error> {
1082        let (bytes, _handles) = buf.split_mut();
1083        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1084        debug_assert_eq!(tx_header.tx_id, 0);
1085        match tx_header.ordinal {
1086            _ => Err(fidl::Error::UnknownOrdinal {
1087                ordinal: tx_header.ordinal,
1088                protocol_name: <UsbFunctionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1089            }),
1090        }
1091    }
1092}
1093
1094/// A Stream of incoming requests for fuchsia.hardware.usb.function/UsbFunction.
1095pub struct UsbFunctionRequestStream {
1096    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1097    is_terminated: bool,
1098}
1099
1100impl std::marker::Unpin for UsbFunctionRequestStream {}
1101
1102impl futures::stream::FusedStream for UsbFunctionRequestStream {
1103    fn is_terminated(&self) -> bool {
1104        self.is_terminated
1105    }
1106}
1107
1108impl fidl::endpoints::RequestStream for UsbFunctionRequestStream {
1109    type Protocol = UsbFunctionMarker;
1110    type ControlHandle = UsbFunctionControlHandle;
1111
1112    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1113        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1114    }
1115
1116    fn control_handle(&self) -> Self::ControlHandle {
1117        UsbFunctionControlHandle { inner: self.inner.clone() }
1118    }
1119
1120    fn into_inner(
1121        self,
1122    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1123    {
1124        (self.inner, self.is_terminated)
1125    }
1126
1127    fn from_inner(
1128        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1129        is_terminated: bool,
1130    ) -> Self {
1131        Self { inner, is_terminated }
1132    }
1133}
1134
1135impl futures::Stream for UsbFunctionRequestStream {
1136    type Item = Result<UsbFunctionRequest, fidl::Error>;
1137
1138    fn poll_next(
1139        mut self: std::pin::Pin<&mut Self>,
1140        cx: &mut std::task::Context<'_>,
1141    ) -> std::task::Poll<Option<Self::Item>> {
1142        let this = &mut *self;
1143        if this.inner.check_shutdown(cx) {
1144            this.is_terminated = true;
1145            return std::task::Poll::Ready(None);
1146        }
1147        if this.is_terminated {
1148            panic!("polled UsbFunctionRequestStream after completion");
1149        }
1150        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1151            |bytes, handles| {
1152                match this.inner.channel().read_etc(cx, bytes, handles) {
1153                    std::task::Poll::Ready(Ok(())) => {}
1154                    std::task::Poll::Pending => return std::task::Poll::Pending,
1155                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1156                        this.is_terminated = true;
1157                        return std::task::Poll::Ready(None);
1158                    }
1159                    std::task::Poll::Ready(Err(e)) => {
1160                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1161                            e.into(),
1162                        ))));
1163                    }
1164                }
1165
1166                // A message has been received from the channel
1167                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1168
1169                std::task::Poll::Ready(Some(match header.ordinal {
1170                    0x11541c67eb1b7f8 => {
1171                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1172                        let mut req = fidl::new_empty!(
1173                            UsbFunctionConnectToEndpointRequest,
1174                            fidl::encoding::DefaultFuchsiaResourceDialect
1175                        );
1176                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionConnectToEndpointRequest>(&header, _body_bytes, handles, &mut req)?;
1177                        let control_handle = UsbFunctionControlHandle { inner: this.inner.clone() };
1178                        Ok(UsbFunctionRequest::ConnectToEndpoint {
1179                            ep_addr: req.ep_addr,
1180                            ep: req.ep,
1181
1182                            responder: UsbFunctionConnectToEndpointResponder {
1183                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1184                                tx_id: header.tx_id,
1185                            },
1186                        })
1187                    }
1188                    0x42a444f4abf08b89 => {
1189                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1190                        let mut req = fidl::new_empty!(
1191                            UsbFunctionConfigureRequest,
1192                            fidl::encoding::DefaultFuchsiaResourceDialect
1193                        );
1194                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionConfigureRequest>(&header, _body_bytes, handles, &mut req)?;
1195                        let control_handle = UsbFunctionControlHandle { inner: this.inner.clone() };
1196                        Ok(UsbFunctionRequest::Configure {
1197                            configuration: req.configuration,
1198                            iface: req.iface,
1199
1200                            responder: UsbFunctionConfigureResponder {
1201                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1202                                tx_id: header.tx_id,
1203                            },
1204                        })
1205                    }
1206                    0x26ee8c8c826367b2 => {
1207                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1208                        let mut req = fidl::new_empty!(
1209                            fidl::encoding::EmptyPayload,
1210                            fidl::encoding::DefaultFuchsiaResourceDialect
1211                        );
1212                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1213                        let control_handle = UsbFunctionControlHandle { inner: this.inner.clone() };
1214                        Ok(UsbFunctionRequest::Deconfigure {
1215                            responder: UsbFunctionDeconfigureResponder {
1216                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1217                                tx_id: header.tx_id,
1218                            },
1219                        })
1220                    }
1221                    0x5ab7133ab195daa0 => {
1222                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1223                        let mut req = fidl::new_empty!(
1224                            UsbFunctionAllocResourcesRequest,
1225                            fidl::encoding::DefaultFuchsiaResourceDialect
1226                        );
1227                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionAllocResourcesRequest>(&header, _body_bytes, handles, &mut req)?;
1228                        let control_handle = UsbFunctionControlHandle { inner: this.inner.clone() };
1229                        Ok(UsbFunctionRequest::AllocResources {
1230                            interface_count: req.interface_count,
1231                            endpoints: req.endpoints,
1232                            strings: req.strings,
1233
1234                            responder: UsbFunctionAllocResourcesResponder {
1235                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1236                                tx_id: header.tx_id,
1237                            },
1238                        })
1239                    }
1240                    0x1f32c374dac955f1 => {
1241                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1242                        let mut req = fidl::new_empty!(
1243                            UsbFunctionEndpointSetStallRequest,
1244                            fidl::encoding::DefaultFuchsiaResourceDialect
1245                        );
1246                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionEndpointSetStallRequest>(&header, _body_bytes, handles, &mut req)?;
1247                        let control_handle = UsbFunctionControlHandle { inner: this.inner.clone() };
1248                        Ok(UsbFunctionRequest::EndpointSetStall {
1249                            endpoint_address: req.endpoint_address,
1250
1251                            responder: UsbFunctionEndpointSetStallResponder {
1252                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1253                                tx_id: header.tx_id,
1254                            },
1255                        })
1256                    }
1257                    0x221d9488ac58aaba => {
1258                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1259                        let mut req = fidl::new_empty!(
1260                            UsbFunctionEndpointClearStallRequest,
1261                            fidl::encoding::DefaultFuchsiaResourceDialect
1262                        );
1263                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionEndpointClearStallRequest>(&header, _body_bytes, handles, &mut req)?;
1264                        let control_handle = UsbFunctionControlHandle { inner: this.inner.clone() };
1265                        Ok(UsbFunctionRequest::EndpointClearStall {
1266                            endpoint_address: req.endpoint_address,
1267
1268                            responder: UsbFunctionEndpointClearStallResponder {
1269                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1270                                tx_id: header.tx_id,
1271                            },
1272                        })
1273                    }
1274                    0x314c9dc3c37ebb7c => {
1275                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1276                        let mut req = fidl::new_empty!(
1277                            UsbFunctionConfigureEndpointRequest,
1278                            fidl::encoding::DefaultFuchsiaResourceDialect
1279                        );
1280                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionConfigureEndpointRequest>(&header, _body_bytes, handles, &mut req)?;
1281                        let control_handle = UsbFunctionControlHandle { inner: this.inner.clone() };
1282                        Ok(UsbFunctionRequest::ConfigureEndpoint {
1283                            endpoint_address: req.endpoint_address,
1284                            endpoint_configuration: req.endpoint_configuration,
1285
1286                            responder: UsbFunctionConfigureEndpointResponder {
1287                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1288                                tx_id: header.tx_id,
1289                            },
1290                        })
1291                    }
1292                    0x112a132561499b6e => {
1293                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1294                        let mut req = fidl::new_empty!(
1295                            UsbFunctionDisableEndpointRequest,
1296                            fidl::encoding::DefaultFuchsiaResourceDialect
1297                        );
1298                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionDisableEndpointRequest>(&header, _body_bytes, handles, &mut req)?;
1299                        let control_handle = UsbFunctionControlHandle { inner: this.inner.clone() };
1300                        Ok(UsbFunctionRequest::DisableEndpoint {
1301                            endpoint_address: req.endpoint_address,
1302
1303                            responder: UsbFunctionDisableEndpointResponder {
1304                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1305                                tx_id: header.tx_id,
1306                            },
1307                        })
1308                    }
1309                    _ => Err(fidl::Error::UnknownOrdinal {
1310                        ordinal: header.ordinal,
1311                        protocol_name:
1312                            <UsbFunctionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1313                    }),
1314                }))
1315            },
1316        )
1317    }
1318}
1319
1320/// Protocol for configuring a USB function.
1321///
1322/// This protocol is implemented by the USB peripheral controller (protocol server) and called by
1323/// the USB function driver (protocol client).
1324///
1325/// Closing the `UsbFunction` channel automatically deconfigures the function and closes the `iface`
1326/// ([`UsbFunctionInterface`]) channel.
1327#[derive(Debug)]
1328pub enum UsbFunctionRequest {
1329    /// Connect to an allocated endpoint.
1330    ///
1331    /// This must be called after the endpoint has been allocated via [`AllocResources`]. If the
1332    /// endpoint channel was not provided during `AllocResources`, this method must be called to
1333    /// establish the endpoint channel before any data transfers can occur on the endpoint.
1334    ///
1335    /// If the endpoint channels were not provided in `AllocResources` and this is never called, the
1336    /// protocol client cannot communicate with the endpoint (no channel is established). This does
1337    /// not prevent control-plane callbacks (like `SetConfigured`) from being made.
1338    ///
1339    /// The endpoint connection persists across `Configure` and `Deconfigure` calls. If the protocol
1340    /// server closes the connection (server end closes), it indicates that the endpoint is no
1341    /// longer available (e.g. device disconnected or function removed). The protocol client should
1342    /// clean up by closing its client end of the channel, cancelling any pending I/O operations,
1343    /// and stopping any tasks using the endpoint. The protocol client is not required to call
1344    /// `DisableEndpoint` or `Deconfigure` in this case (and such calls may fail if the interface is
1345    /// being torn down).
1346    ///
1347    /// * error:
1348    ///     * `ZX_ERR_NOT_FOUND` if endpoint address does not exist (e.g. not allocated).
1349    ///     * `ZX_ERR_ALREADY_BOUND` if the endpoint is already bound to an active channel. To
1350    ///       connect a new channel, the existing channel must be closed first. Note that channel
1351    ///       closure detection is asynchronous; if the protocol client closes the existing channel
1352    ///       and immediately calls `ConnectToEndpoint`, it may still fail with
1353    ///       `ZX_ERR_ALREADY_BOUND` if the protocol server has not yet processed the closure.
1354    ConnectToEndpoint {
1355        ep_addr: u8,
1356        ep: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
1357        responder: UsbFunctionConnectToEndpointResponder,
1358    },
1359    /// Configure the function with the given descriptors.
1360    ///
1361    /// **Ordering**: This must be called after `AllocResources` has been called to allocate all
1362    /// interfaces, endpoints, and strings referenced in the descriptors. Calling this when already
1363    /// configured returns `ZX_ERR_ALREADY_BOUND`.
1364    ///
1365    /// This binds the [`UsbFunctionInterface`] callback channel (where the protocol client acts as
1366    /// the server).
1367    ///
1368    /// `configuration` is a vector of concatenated USB descriptors in standard USB wire format
1369    /// (Interface -> Endpoint -> Class/Vendor descriptors). A raw byte vector is used to allow
1370    /// arbitrary class-specific and vendor-specific descriptors that cannot be statically defined
1371    /// in FIDL.
1372    ///
1373    /// This byte vector is expected to contain one or more interface descriptors following the
1374    /// USB specification.
1375    ///
1376    /// This descriptor block is cached by the peripheral controller and sent *as-is* to the host in
1377    /// response to standard host `GET_DESCRIPTOR` (Configuration) requests.
1378    ///
1379    /// **Structure and Validation**:
1380    /// - Must begin with an Interface or Interface Association descriptor.
1381    /// - Standard descriptors (Interface, Endpoint) embedded in the vector must follow the standard
1382    ///   USB specification descriptor layouts.
1383    /// - All interface numbers and endpoint addresses must match the resources allocated in
1384    ///   [`AllocResources`].
1385    /// - The peripheral controller parses this vector linearly using descriptor length fields.
1386    ///   Mismatched resource IDs or malformed layouts return `ZX_ERR_INVALID_ARGS`.
1387    ///
1388    /// `iface` is the client end of [`UsbFunctionInterface`] which the protocol server uses to send
1389    /// events to the protocol client.
1390    ///
1391    /// The function remains configured until `Deconfigure` is called or the `iface` channel is
1392    /// closed. If `iface` is closed, the function is automatically deconfigured, which stops the
1393    /// peripheral controller and disconnects the device from the host.
1394    ///
1395    /// * error:
1396    ///     * `ZX_ERR_INVALID_ARGS` if the configuration is invalid or references unallocated
1397    ///       resources.
1398    ///     * `ZX_ERR_ALREADY_BOUND` if the function interface is already bound.
1399    ///     * `ZX_ERR_NO_MEMORY` if the protocol server fails to allocate memory to store the
1400    ///       descriptors.
1401    ///     * `ZX_ERR_BAD_STATE` if the peripheral device is stopping or tearing down.
1402    Configure {
1403        configuration: Vec<u8>,
1404        iface: fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>,
1405        responder: UsbFunctionConfigureResponder,
1406    },
1407    /// Deconfigure the function.
1408    ///
1409    /// **Ordering**: Can be called at any time. If the function is not configured, it trivially
1410    /// succeeds.
1411    ///
1412    /// This is the opposite of `Configure`. The protocol server disables all physical endpoints
1413    /// for this function, clears its stored descriptors, and unbinds the `iface` channel. If the
1414    /// function was active, the peripheral controller may trigger a USB re-enumeration to reflect
1415    /// the updated function configuration.
1416    ///
1417    /// This does *not* close the endpoint channels (they remain connected and can be reused if the
1418    /// function is re-configured).
1419    ///
1420    /// * error:
1421    ///     * `ZX_ERR_UNAVAILABLE` if a deconfiguration is already in progress.
1422    Deconfigure { responder: UsbFunctionDeconfigureResponder },
1423    /// Allocate resources for the function.
1424    ///
1425    /// This method is atomic. If any resource allocation fails, all allocations made during this
1426    /// call are rolled back.
1427    ///
1428    /// This must be called during driver initialization before `Configure`. Calling this after the
1429    /// function has been configured returns `ZX_ERR_BAD_STATE`.
1430    ///
1431    /// `interface_count` informs how many interfaces to create. `interface_nums` returns a vector
1432    /// of length `interface_count` containing the allocated interface numbers.
1433    ///
1434    /// `endpoints` is a vector of endpoints to allocate. The direction and endpoint server end are
1435    /// provided. The protocol client can optionally provide endpoint channels in `endpoints`
1436    /// to connect them immediately. If an endpoint channel is not provided, the protocol client
1437    /// must call [`ConnectToEndpoint`] later to use it. `endpoint_addrs` returns a vector of the
1438    /// same size containing the allocated endpoint addresses, where element `i` corresponds 1:1
1439    /// to element `i` of `endpoints`. All endpoint channels provided here or connected later via
1440    /// [`ConnectToEndpoint`] persist across [`Configure`] and [`Deconfigure`] calls.
1441    ///
1442    /// `strings` is a vector of strings to allocate. `string_indices` returns a vector of the
1443    /// same size containing the allocated string indices, where element `i` corresponds 1:1 to
1444    /// element `i` of `strings`.
1445    ///
1446    /// Returns the interface ids, endpoint ids, and string ids that were allocated. On error, no
1447    /// resources are allocated.
1448    ///
1449    /// The allocated resource numbers and addresses remain allocated for the lifetime of the
1450    /// connection to `UsbFunction`. They are *not* freed on `Deconfigure`.
1451    ///
1452    /// * error:
1453    ///     * `ZX_ERR_BAD_STATE` if the function has already been configured.
1454    ///     * `ZX_ERR_NO_RESOURCES` if any resource namespace numbers are exhausted.
1455    ///     * `ZX_ERR_INVALID_ARGS` if the endpoint configuration contains invalid arguments.
1456    AllocResources {
1457        interface_count: u8,
1458        endpoints: Vec<EndpointResource>,
1459        strings: Vec<String>,
1460        responder: UsbFunctionAllocResourcesResponder,
1461    },
1462    /// Stall the endpoint.
1463    ///
1464    /// The endpoint must have been allocated and configured.
1465    ///
1466    /// This method returns after the hardware confirms the stall condition is active. All pending
1467    /// transfers queued on the endpoint are cancelled and completed with `ZX_ERR_IO_REFUSED` via
1468    /// `OnCompletion`. While the endpoint is stalled, any new requests submitted via
1469    /// `QueueRequests` must immediately fail and complete with `ZX_ERR_IO_REFUSED`.
1470    ///
1471    /// * error:
1472    ///     * `ZX_ERR_BAD_STATE` if the function is not configured.
1473    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
1474    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
1475    EndpointSetStall { endpoint_address: u8, responder: UsbFunctionEndpointSetStallResponder },
1476    /// Clear the endpoint's stalled state.
1477    ///
1478    /// The endpoint must have been allocated and configured.
1479    ///
1480    /// This method returns after the hardware confirms the stall has been cleared. As required by
1481    /// USB 2.0 Section 9.4.5, clearing the halt feature also resets the endpoint's data toggle bit
1482    /// to `DATA0` in hardware. The client must resubmit any cancelled transfers once the endpoint
1483    /// is cleared. Any requests queued *after* this method returns are processed normally.
1484    ///
1485    /// * error:
1486    ///     * `ZX_ERR_BAD_STATE` if the function is not configured.
1487    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
1488    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
1489    EndpointClearStall { endpoint_address: u8, responder: UsbFunctionEndpointClearStallResponder },
1490    /// Configure and enable an endpoint with the given configuration.
1491    ///
1492    /// Called by the function driver in response to `SetConfigured` (when `configured == true`) or
1493    /// `SetInterface` requests to enable physical transfers on the endpoint. Calling this before
1494    /// the function has been configured via `Configure` returns `ZX_ERR_BAD_STATE`. Clients should
1495    /// wait for the `SetConfigured` or `SetInterface` request before configuring endpoints to
1496    /// ensure the host is ready.
1497    ///
1498    /// The endpoint must have been allocated via `AllocResources`.
1499    ///
1500    /// Returns only after the physical endpoint has been configured by the DCI driver.
1501    ///
1502    /// See USB 2.0 Specification Section 9.6.6 (Endpoint Descriptor) for details on the standard
1503    /// endpoint configuration fields mapped in `EndpointConfiguration`.
1504    ///
1505    /// * error:
1506    ///     * `ZX_ERR_BAD_STATE` if the function is not configured.
1507    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
1508    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
1509    ///     * `ZX_ERR_INVALID_ARGS` if the configuration is invalid.
1510    ConfigureEndpoint {
1511        endpoint_address: u8,
1512        endpoint_configuration: EndpointConfiguration,
1513        responder: UsbFunctionConfigureEndpointResponder,
1514    },
1515    /// Disable an endpoint.
1516    ///
1517    /// Called by the function driver in response to `SetConfigured` (when `configured == false`)
1518    /// or `SetInterface` requests to disable physical transfers on the endpoint. Calling this when
1519    /// the endpoint is already disabled is a no-op and returns `ZX_OK`. If called before the
1520    /// function has been configured via `Configure`, it also trivially succeeds (`ZX_OK`), as the
1521    /// endpoint is already unconfigured and disabled.
1522    ///
1523    /// The endpoint must have been allocated via `AllocResources`.
1524    ///
1525    /// Returns only after the physical endpoint has been disabled by the DCI driver.
1526    ///
1527    /// * error:
1528    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device is not running, disconnected, or inactive.
1529    ///     * `ZX_ERR_NOT_FOUND` if the endpoint address does not exist (not allocated).
1530    DisableEndpoint { endpoint_address: u8, responder: UsbFunctionDisableEndpointResponder },
1531}
1532
1533impl UsbFunctionRequest {
1534    #[allow(irrefutable_let_patterns)]
1535    pub fn into_connect_to_endpoint(
1536        self,
1537    ) -> Option<(
1538        u8,
1539        fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
1540        UsbFunctionConnectToEndpointResponder,
1541    )> {
1542        if let UsbFunctionRequest::ConnectToEndpoint { ep_addr, ep, responder } = self {
1543            Some((ep_addr, ep, responder))
1544        } else {
1545            None
1546        }
1547    }
1548
1549    #[allow(irrefutable_let_patterns)]
1550    pub fn into_configure(
1551        self,
1552    ) -> Option<(
1553        Vec<u8>,
1554        fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>,
1555        UsbFunctionConfigureResponder,
1556    )> {
1557        if let UsbFunctionRequest::Configure { configuration, iface, responder } = self {
1558            Some((configuration, iface, responder))
1559        } else {
1560            None
1561        }
1562    }
1563
1564    #[allow(irrefutable_let_patterns)]
1565    pub fn into_deconfigure(self) -> Option<(UsbFunctionDeconfigureResponder)> {
1566        if let UsbFunctionRequest::Deconfigure { responder } = self {
1567            Some((responder))
1568        } else {
1569            None
1570        }
1571    }
1572
1573    #[allow(irrefutable_let_patterns)]
1574    pub fn into_alloc_resources(
1575        self,
1576    ) -> Option<(u8, Vec<EndpointResource>, Vec<String>, UsbFunctionAllocResourcesResponder)> {
1577        if let UsbFunctionRequest::AllocResources {
1578            interface_count,
1579            endpoints,
1580            strings,
1581            responder,
1582        } = self
1583        {
1584            Some((interface_count, endpoints, strings, responder))
1585        } else {
1586            None
1587        }
1588    }
1589
1590    #[allow(irrefutable_let_patterns)]
1591    pub fn into_endpoint_set_stall(self) -> Option<(u8, UsbFunctionEndpointSetStallResponder)> {
1592        if let UsbFunctionRequest::EndpointSetStall { endpoint_address, responder } = self {
1593            Some((endpoint_address, responder))
1594        } else {
1595            None
1596        }
1597    }
1598
1599    #[allow(irrefutable_let_patterns)]
1600    pub fn into_endpoint_clear_stall(self) -> Option<(u8, UsbFunctionEndpointClearStallResponder)> {
1601        if let UsbFunctionRequest::EndpointClearStall { endpoint_address, responder } = self {
1602            Some((endpoint_address, responder))
1603        } else {
1604            None
1605        }
1606    }
1607
1608    #[allow(irrefutable_let_patterns)]
1609    pub fn into_configure_endpoint(
1610        self,
1611    ) -> Option<(u8, EndpointConfiguration, UsbFunctionConfigureEndpointResponder)> {
1612        if let UsbFunctionRequest::ConfigureEndpoint {
1613            endpoint_address,
1614            endpoint_configuration,
1615            responder,
1616        } = self
1617        {
1618            Some((endpoint_address, endpoint_configuration, responder))
1619        } else {
1620            None
1621        }
1622    }
1623
1624    #[allow(irrefutable_let_patterns)]
1625    pub fn into_disable_endpoint(self) -> Option<(u8, UsbFunctionDisableEndpointResponder)> {
1626        if let UsbFunctionRequest::DisableEndpoint { endpoint_address, responder } = self {
1627            Some((endpoint_address, responder))
1628        } else {
1629            None
1630        }
1631    }
1632
1633    /// Name of the method defined in FIDL
1634    pub fn method_name(&self) -> &'static str {
1635        match *self {
1636            UsbFunctionRequest::ConnectToEndpoint { .. } => "connect_to_endpoint",
1637            UsbFunctionRequest::Configure { .. } => "configure",
1638            UsbFunctionRequest::Deconfigure { .. } => "deconfigure",
1639            UsbFunctionRequest::AllocResources { .. } => "alloc_resources",
1640            UsbFunctionRequest::EndpointSetStall { .. } => "endpoint_set_stall",
1641            UsbFunctionRequest::EndpointClearStall { .. } => "endpoint_clear_stall",
1642            UsbFunctionRequest::ConfigureEndpoint { .. } => "configure_endpoint",
1643            UsbFunctionRequest::DisableEndpoint { .. } => "disable_endpoint",
1644        }
1645    }
1646}
1647
1648#[derive(Debug, Clone)]
1649pub struct UsbFunctionControlHandle {
1650    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1651}
1652
1653impl UsbFunctionControlHandle {
1654    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1655        self.inner.shutdown_with_epitaph(status.into())
1656    }
1657}
1658
1659impl fidl::endpoints::ControlHandle for UsbFunctionControlHandle {
1660    fn shutdown(&self) {
1661        self.inner.shutdown()
1662    }
1663
1664    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1665        self.inner.shutdown_with_epitaph(status)
1666    }
1667
1668    fn is_closed(&self) -> bool {
1669        self.inner.channel().is_closed()
1670    }
1671    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1672        self.inner.channel().on_closed()
1673    }
1674
1675    #[cfg(target_os = "fuchsia")]
1676    fn signal_peer(
1677        &self,
1678        clear_mask: zx::Signals,
1679        set_mask: zx::Signals,
1680    ) -> Result<(), zx_status::Status> {
1681        use fidl::Peered;
1682        self.inner.channel().signal_peer(clear_mask, set_mask)
1683    }
1684}
1685
1686impl UsbFunctionControlHandle {}
1687
1688#[must_use = "FIDL methods require a response to be sent"]
1689#[derive(Debug)]
1690pub struct UsbFunctionConnectToEndpointResponder {
1691    control_handle: std::mem::ManuallyDrop<UsbFunctionControlHandle>,
1692    tx_id: u32,
1693}
1694
1695/// Set the the channel to be shutdown (see [`UsbFunctionControlHandle::shutdown`])
1696/// if the responder is dropped without sending a response, so that the client
1697/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1698impl std::ops::Drop for UsbFunctionConnectToEndpointResponder {
1699    fn drop(&mut self) {
1700        self.control_handle.shutdown();
1701        // Safety: drops once, never accessed again
1702        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1703    }
1704}
1705
1706impl fidl::endpoints::Responder for UsbFunctionConnectToEndpointResponder {
1707    type ControlHandle = UsbFunctionControlHandle;
1708
1709    fn control_handle(&self) -> &UsbFunctionControlHandle {
1710        &self.control_handle
1711    }
1712
1713    fn drop_without_shutdown(mut self) {
1714        // Safety: drops once, never accessed again due to mem::forget
1715        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1716        // Prevent Drop from running (which would shut down the channel)
1717        std::mem::forget(self);
1718    }
1719}
1720
1721impl UsbFunctionConnectToEndpointResponder {
1722    /// Sends a response to the FIDL transaction.
1723    ///
1724    /// Sets the channel to shutdown if an error occurs.
1725    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1726        let _result = self.send_raw(result);
1727        if _result.is_err() {
1728            self.control_handle.shutdown();
1729        }
1730        self.drop_without_shutdown();
1731        _result
1732    }
1733
1734    /// Similar to "send" but does not shutdown the channel if an error occurs.
1735    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1736        let _result = self.send_raw(result);
1737        self.drop_without_shutdown();
1738        _result
1739    }
1740
1741    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1742        self.control_handle
1743            .inner
1744            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
1745                result,
1746                self.tx_id,
1747                0x11541c67eb1b7f8,
1748                fidl::encoding::DynamicFlags::empty(),
1749            )
1750    }
1751}
1752
1753#[must_use = "FIDL methods require a response to be sent"]
1754#[derive(Debug)]
1755pub struct UsbFunctionConfigureResponder {
1756    control_handle: std::mem::ManuallyDrop<UsbFunctionControlHandle>,
1757    tx_id: u32,
1758}
1759
1760/// Set the the channel to be shutdown (see [`UsbFunctionControlHandle::shutdown`])
1761/// if the responder is dropped without sending a response, so that the client
1762/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1763impl std::ops::Drop for UsbFunctionConfigureResponder {
1764    fn drop(&mut self) {
1765        self.control_handle.shutdown();
1766        // Safety: drops once, never accessed again
1767        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1768    }
1769}
1770
1771impl fidl::endpoints::Responder for UsbFunctionConfigureResponder {
1772    type ControlHandle = UsbFunctionControlHandle;
1773
1774    fn control_handle(&self) -> &UsbFunctionControlHandle {
1775        &self.control_handle
1776    }
1777
1778    fn drop_without_shutdown(mut self) {
1779        // Safety: drops once, never accessed again due to mem::forget
1780        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1781        // Prevent Drop from running (which would shut down the channel)
1782        std::mem::forget(self);
1783    }
1784}
1785
1786impl UsbFunctionConfigureResponder {
1787    /// Sends a response to the FIDL transaction.
1788    ///
1789    /// Sets the channel to shutdown if an error occurs.
1790    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1791        let _result = self.send_raw(result);
1792        if _result.is_err() {
1793            self.control_handle.shutdown();
1794        }
1795        self.drop_without_shutdown();
1796        _result
1797    }
1798
1799    /// Similar to "send" but does not shutdown the channel if an error occurs.
1800    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1801        let _result = self.send_raw(result);
1802        self.drop_without_shutdown();
1803        _result
1804    }
1805
1806    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1807        self.control_handle
1808            .inner
1809            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
1810                result,
1811                self.tx_id,
1812                0x42a444f4abf08b89,
1813                fidl::encoding::DynamicFlags::empty(),
1814            )
1815    }
1816}
1817
1818#[must_use = "FIDL methods require a response to be sent"]
1819#[derive(Debug)]
1820pub struct UsbFunctionDeconfigureResponder {
1821    control_handle: std::mem::ManuallyDrop<UsbFunctionControlHandle>,
1822    tx_id: u32,
1823}
1824
1825/// Set the the channel to be shutdown (see [`UsbFunctionControlHandle::shutdown`])
1826/// if the responder is dropped without sending a response, so that the client
1827/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1828impl std::ops::Drop for UsbFunctionDeconfigureResponder {
1829    fn drop(&mut self) {
1830        self.control_handle.shutdown();
1831        // Safety: drops once, never accessed again
1832        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1833    }
1834}
1835
1836impl fidl::endpoints::Responder for UsbFunctionDeconfigureResponder {
1837    type ControlHandle = UsbFunctionControlHandle;
1838
1839    fn control_handle(&self) -> &UsbFunctionControlHandle {
1840        &self.control_handle
1841    }
1842
1843    fn drop_without_shutdown(mut self) {
1844        // Safety: drops once, never accessed again due to mem::forget
1845        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1846        // Prevent Drop from running (which would shut down the channel)
1847        std::mem::forget(self);
1848    }
1849}
1850
1851impl UsbFunctionDeconfigureResponder {
1852    /// Sends a response to the FIDL transaction.
1853    ///
1854    /// Sets the channel to shutdown if an error occurs.
1855    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1856        let _result = self.send_raw(result);
1857        if _result.is_err() {
1858            self.control_handle.shutdown();
1859        }
1860        self.drop_without_shutdown();
1861        _result
1862    }
1863
1864    /// Similar to "send" but does not shutdown the channel if an error occurs.
1865    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1866        let _result = self.send_raw(result);
1867        self.drop_without_shutdown();
1868        _result
1869    }
1870
1871    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1872        self.control_handle
1873            .inner
1874            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
1875                result,
1876                self.tx_id,
1877                0x26ee8c8c826367b2,
1878                fidl::encoding::DynamicFlags::empty(),
1879            )
1880    }
1881}
1882
1883#[must_use = "FIDL methods require a response to be sent"]
1884#[derive(Debug)]
1885pub struct UsbFunctionAllocResourcesResponder {
1886    control_handle: std::mem::ManuallyDrop<UsbFunctionControlHandle>,
1887    tx_id: u32,
1888}
1889
1890/// Set the the channel to be shutdown (see [`UsbFunctionControlHandle::shutdown`])
1891/// if the responder is dropped without sending a response, so that the client
1892/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1893impl std::ops::Drop for UsbFunctionAllocResourcesResponder {
1894    fn drop(&mut self) {
1895        self.control_handle.shutdown();
1896        // Safety: drops once, never accessed again
1897        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1898    }
1899}
1900
1901impl fidl::endpoints::Responder for UsbFunctionAllocResourcesResponder {
1902    type ControlHandle = UsbFunctionControlHandle;
1903
1904    fn control_handle(&self) -> &UsbFunctionControlHandle {
1905        &self.control_handle
1906    }
1907
1908    fn drop_without_shutdown(mut self) {
1909        // Safety: drops once, never accessed again due to mem::forget
1910        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1911        // Prevent Drop from running (which would shut down the channel)
1912        std::mem::forget(self);
1913    }
1914}
1915
1916impl UsbFunctionAllocResourcesResponder {
1917    /// Sends a response to the FIDL transaction.
1918    ///
1919    /// Sets the channel to shutdown if an error occurs.
1920    pub fn send(self, mut result: Result<(&[u8], &[u8], &[u8]), i32>) -> Result<(), fidl::Error> {
1921        let _result = self.send_raw(result);
1922        if _result.is_err() {
1923            self.control_handle.shutdown();
1924        }
1925        self.drop_without_shutdown();
1926        _result
1927    }
1928
1929    /// Similar to "send" but does not shutdown the channel if an error occurs.
1930    pub fn send_no_shutdown_on_err(
1931        self,
1932        mut result: Result<(&[u8], &[u8], &[u8]), i32>,
1933    ) -> Result<(), fidl::Error> {
1934        let _result = self.send_raw(result);
1935        self.drop_without_shutdown();
1936        _result
1937    }
1938
1939    fn send_raw(&self, mut result: Result<(&[u8], &[u8], &[u8]), i32>) -> Result<(), fidl::Error> {
1940        self.control_handle
1941            .inner
1942            .send::<fidl::encoding::ResultType<UsbFunctionAllocResourcesResponse, i32>>(
1943                result,
1944                self.tx_id,
1945                0x5ab7133ab195daa0,
1946                fidl::encoding::DynamicFlags::empty(),
1947            )
1948    }
1949}
1950
1951#[must_use = "FIDL methods require a response to be sent"]
1952#[derive(Debug)]
1953pub struct UsbFunctionEndpointSetStallResponder {
1954    control_handle: std::mem::ManuallyDrop<UsbFunctionControlHandle>,
1955    tx_id: u32,
1956}
1957
1958/// Set the the channel to be shutdown (see [`UsbFunctionControlHandle::shutdown`])
1959/// if the responder is dropped without sending a response, so that the client
1960/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1961impl std::ops::Drop for UsbFunctionEndpointSetStallResponder {
1962    fn drop(&mut self) {
1963        self.control_handle.shutdown();
1964        // Safety: drops once, never accessed again
1965        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1966    }
1967}
1968
1969impl fidl::endpoints::Responder for UsbFunctionEndpointSetStallResponder {
1970    type ControlHandle = UsbFunctionControlHandle;
1971
1972    fn control_handle(&self) -> &UsbFunctionControlHandle {
1973        &self.control_handle
1974    }
1975
1976    fn drop_without_shutdown(mut self) {
1977        // Safety: drops once, never accessed again due to mem::forget
1978        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1979        // Prevent Drop from running (which would shut down the channel)
1980        std::mem::forget(self);
1981    }
1982}
1983
1984impl UsbFunctionEndpointSetStallResponder {
1985    /// Sends a response to the FIDL transaction.
1986    ///
1987    /// Sets the channel to shutdown if an error occurs.
1988    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1989        let _result = self.send_raw(result);
1990        if _result.is_err() {
1991            self.control_handle.shutdown();
1992        }
1993        self.drop_without_shutdown();
1994        _result
1995    }
1996
1997    /// Similar to "send" but does not shutdown the channel if an error occurs.
1998    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1999        let _result = self.send_raw(result);
2000        self.drop_without_shutdown();
2001        _result
2002    }
2003
2004    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2005        self.control_handle
2006            .inner
2007            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
2008                result,
2009                self.tx_id,
2010                0x1f32c374dac955f1,
2011                fidl::encoding::DynamicFlags::empty(),
2012            )
2013    }
2014}
2015
2016#[must_use = "FIDL methods require a response to be sent"]
2017#[derive(Debug)]
2018pub struct UsbFunctionEndpointClearStallResponder {
2019    control_handle: std::mem::ManuallyDrop<UsbFunctionControlHandle>,
2020    tx_id: u32,
2021}
2022
2023/// Set the the channel to be shutdown (see [`UsbFunctionControlHandle::shutdown`])
2024/// if the responder is dropped without sending a response, so that the client
2025/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2026impl std::ops::Drop for UsbFunctionEndpointClearStallResponder {
2027    fn drop(&mut self) {
2028        self.control_handle.shutdown();
2029        // Safety: drops once, never accessed again
2030        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2031    }
2032}
2033
2034impl fidl::endpoints::Responder for UsbFunctionEndpointClearStallResponder {
2035    type ControlHandle = UsbFunctionControlHandle;
2036
2037    fn control_handle(&self) -> &UsbFunctionControlHandle {
2038        &self.control_handle
2039    }
2040
2041    fn drop_without_shutdown(mut self) {
2042        // Safety: drops once, never accessed again due to mem::forget
2043        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2044        // Prevent Drop from running (which would shut down the channel)
2045        std::mem::forget(self);
2046    }
2047}
2048
2049impl UsbFunctionEndpointClearStallResponder {
2050    /// Sends a response to the FIDL transaction.
2051    ///
2052    /// Sets the channel to shutdown if an error occurs.
2053    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2054        let _result = self.send_raw(result);
2055        if _result.is_err() {
2056            self.control_handle.shutdown();
2057        }
2058        self.drop_without_shutdown();
2059        _result
2060    }
2061
2062    /// Similar to "send" but does not shutdown the channel if an error occurs.
2063    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2064        let _result = self.send_raw(result);
2065        self.drop_without_shutdown();
2066        _result
2067    }
2068
2069    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2070        self.control_handle
2071            .inner
2072            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
2073                result,
2074                self.tx_id,
2075                0x221d9488ac58aaba,
2076                fidl::encoding::DynamicFlags::empty(),
2077            )
2078    }
2079}
2080
2081#[must_use = "FIDL methods require a response to be sent"]
2082#[derive(Debug)]
2083pub struct UsbFunctionConfigureEndpointResponder {
2084    control_handle: std::mem::ManuallyDrop<UsbFunctionControlHandle>,
2085    tx_id: u32,
2086}
2087
2088/// Set the the channel to be shutdown (see [`UsbFunctionControlHandle::shutdown`])
2089/// if the responder is dropped without sending a response, so that the client
2090/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2091impl std::ops::Drop for UsbFunctionConfigureEndpointResponder {
2092    fn drop(&mut self) {
2093        self.control_handle.shutdown();
2094        // Safety: drops once, never accessed again
2095        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2096    }
2097}
2098
2099impl fidl::endpoints::Responder for UsbFunctionConfigureEndpointResponder {
2100    type ControlHandle = UsbFunctionControlHandle;
2101
2102    fn control_handle(&self) -> &UsbFunctionControlHandle {
2103        &self.control_handle
2104    }
2105
2106    fn drop_without_shutdown(mut self) {
2107        // Safety: drops once, never accessed again due to mem::forget
2108        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2109        // Prevent Drop from running (which would shut down the channel)
2110        std::mem::forget(self);
2111    }
2112}
2113
2114impl UsbFunctionConfigureEndpointResponder {
2115    /// Sends a response to the FIDL transaction.
2116    ///
2117    /// Sets the channel to shutdown if an error occurs.
2118    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2119        let _result = self.send_raw(result);
2120        if _result.is_err() {
2121            self.control_handle.shutdown();
2122        }
2123        self.drop_without_shutdown();
2124        _result
2125    }
2126
2127    /// Similar to "send" but does not shutdown the channel if an error occurs.
2128    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2129        let _result = self.send_raw(result);
2130        self.drop_without_shutdown();
2131        _result
2132    }
2133
2134    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2135        self.control_handle
2136            .inner
2137            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
2138                result,
2139                self.tx_id,
2140                0x314c9dc3c37ebb7c,
2141                fidl::encoding::DynamicFlags::empty(),
2142            )
2143    }
2144}
2145
2146#[must_use = "FIDL methods require a response to be sent"]
2147#[derive(Debug)]
2148pub struct UsbFunctionDisableEndpointResponder {
2149    control_handle: std::mem::ManuallyDrop<UsbFunctionControlHandle>,
2150    tx_id: u32,
2151}
2152
2153/// Set the the channel to be shutdown (see [`UsbFunctionControlHandle::shutdown`])
2154/// if the responder is dropped without sending a response, so that the client
2155/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2156impl std::ops::Drop for UsbFunctionDisableEndpointResponder {
2157    fn drop(&mut self) {
2158        self.control_handle.shutdown();
2159        // Safety: drops once, never accessed again
2160        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2161    }
2162}
2163
2164impl fidl::endpoints::Responder for UsbFunctionDisableEndpointResponder {
2165    type ControlHandle = UsbFunctionControlHandle;
2166
2167    fn control_handle(&self) -> &UsbFunctionControlHandle {
2168        &self.control_handle
2169    }
2170
2171    fn drop_without_shutdown(mut self) {
2172        // Safety: drops once, never accessed again due to mem::forget
2173        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2174        // Prevent Drop from running (which would shut down the channel)
2175        std::mem::forget(self);
2176    }
2177}
2178
2179impl UsbFunctionDisableEndpointResponder {
2180    /// Sends a response to the FIDL transaction.
2181    ///
2182    /// Sets the channel to shutdown if an error occurs.
2183    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2184        let _result = self.send_raw(result);
2185        if _result.is_err() {
2186            self.control_handle.shutdown();
2187        }
2188        self.drop_without_shutdown();
2189        _result
2190    }
2191
2192    /// Similar to "send" but does not shutdown the channel if an error occurs.
2193    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2194        let _result = self.send_raw(result);
2195        self.drop_without_shutdown();
2196        _result
2197    }
2198
2199    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
2200        self.control_handle
2201            .inner
2202            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
2203                result,
2204                self.tx_id,
2205                0x112a132561499b6e,
2206                fidl::encoding::DynamicFlags::empty(),
2207            )
2208    }
2209}
2210
2211#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
2212pub struct UsbFunctionInterfaceMarker;
2213
2214impl fidl::endpoints::ProtocolMarker for UsbFunctionInterfaceMarker {
2215    type Proxy = UsbFunctionInterfaceProxy;
2216    type RequestStream = UsbFunctionInterfaceRequestStream;
2217    #[cfg(target_os = "fuchsia")]
2218    type SynchronousProxy = UsbFunctionInterfaceSynchronousProxy;
2219
2220    const DEBUG_NAME: &'static str = "(anonymous) UsbFunctionInterface";
2221}
2222pub type UsbFunctionInterfaceControlResult = Result<Vec<u8>, i32>;
2223pub type UsbFunctionInterfaceSetConfiguredResult = Result<(), i32>;
2224pub type UsbFunctionInterfaceSetInterfaceResult = Result<(), i32>;
2225
2226pub trait UsbFunctionInterfaceProxyInterface: Send + Sync {
2227    type ControlResponseFut: std::future::Future<Output = Result<UsbFunctionInterfaceControlResult, fidl::Error>>
2228        + Send;
2229    fn r#control(
2230        &self,
2231        setup: &fidl_fuchsia_hardware_usb_descriptor::UsbSetup,
2232        write: &[u8],
2233    ) -> Self::ControlResponseFut;
2234    type SetConfiguredResponseFut: std::future::Future<Output = Result<UsbFunctionInterfaceSetConfiguredResult, fidl::Error>>
2235        + Send;
2236    fn r#set_configured(
2237        &self,
2238        configured: bool,
2239        speed: fidl_fuchsia_hardware_usb_descriptor::UsbSpeed,
2240    ) -> Self::SetConfiguredResponseFut;
2241    type SetInterfaceResponseFut: std::future::Future<Output = Result<UsbFunctionInterfaceSetInterfaceResult, fidl::Error>>
2242        + Send;
2243    fn r#set_interface(&self, interface: u8, alt_setting: u8) -> Self::SetInterfaceResponseFut;
2244}
2245#[derive(Debug)]
2246#[cfg(target_os = "fuchsia")]
2247pub struct UsbFunctionInterfaceSynchronousProxy {
2248    client: fidl::client::sync::Client,
2249}
2250
2251#[cfg(target_os = "fuchsia")]
2252impl fidl::endpoints::SynchronousProxy for UsbFunctionInterfaceSynchronousProxy {
2253    type Proxy = UsbFunctionInterfaceProxy;
2254    type Protocol = UsbFunctionInterfaceMarker;
2255
2256    fn from_channel(inner: fidl::Channel) -> Self {
2257        Self::new(inner)
2258    }
2259
2260    fn into_channel(self) -> fidl::Channel {
2261        self.client.into_channel()
2262    }
2263
2264    fn as_channel(&self) -> &fidl::Channel {
2265        self.client.as_channel()
2266    }
2267}
2268
2269#[cfg(target_os = "fuchsia")]
2270impl UsbFunctionInterfaceSynchronousProxy {
2271    pub fn new(channel: fidl::Channel) -> Self {
2272        Self { client: fidl::client::sync::Client::new(channel) }
2273    }
2274
2275    pub fn into_channel(self) -> fidl::Channel {
2276        self.client.into_channel()
2277    }
2278
2279    /// Waits until an event arrives and returns it. It is safe for other
2280    /// threads to make concurrent requests while waiting for an event.
2281    pub fn wait_for_event(
2282        &self,
2283        deadline: zx::MonotonicInstant,
2284    ) -> Result<UsbFunctionInterfaceEvent, fidl::Error> {
2285        UsbFunctionInterfaceEvent::decode(
2286            self.client.wait_for_event::<UsbFunctionInterfaceMarker>(deadline)?,
2287        )
2288    }
2289
2290    /// Callback for handling EP0 class/vendor-specific control requests targeting the interface(s)
2291    /// owned by this function.
2292    ///
2293    /// This is called when the host sends a control request to the device. The protocol server (of
2294    /// [`UsbFunctionInterface`]) should process the request and return the result.
2295    ///
2296    /// The host expects a response within a strict timeout period defined by the USB specification
2297    /// Section 9.2.6 (50ms for requests without data, and 500ms for read data stages). Because of
2298    /// these hardware-enforced limits, the implementation must reply as quickly as possible and
2299    /// avoid blocking the dispatcher.
2300    ///
2301    /// `setup` is the control request metadata (setup packet). `write` contains the raw bytes sent
2302    /// by the host in the Data Stage of a host-to-device (OUT) control transfer. It is empty for
2303    /// device-to-host (IN) transfers. `read` in the response payload contains the raw bytes
2304    /// returned to the host in the Data Stage of a device-to-host (IN) control transfer. It must
2305    /// be empty for host-to-device (OUT) transfers.
2306    ///
2307    /// Any error returned by this method (including `ZX_ERR_NOT_SUPPORTED`) causes the
2308    /// peripheral controller to stall Endpoint 0, signaling a "Request Error" to the host.
2309    ///
2310    /// * error:
2311    ///     * `ZX_ERR_NOT_SUPPORTED` if the request is not supported by the protocol server.
2312    ///     * `ZX_ERR_INVALID_ARGS` if the setup packet or data is invalid.
2313    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device was disconnected while processing the request.
2314    pub fn r#control(
2315        &self,
2316        mut setup: &fidl_fuchsia_hardware_usb_descriptor::UsbSetup,
2317        mut write: &[u8],
2318        ___deadline: zx::MonotonicInstant,
2319    ) -> Result<UsbFunctionInterfaceControlResult, fidl::Error> {
2320        let _response = self.client.send_query::<
2321            UsbFunctionInterfaceControlRequest,
2322            fidl::encoding::FlexibleResultType<UsbFunctionInterfaceControlResponse, i32>,
2323            UsbFunctionInterfaceMarker,
2324        >(
2325            (setup, write,),
2326            0x3cce27231c012cff,
2327            fidl::encoding::DynamicFlags::FLEXIBLE,
2328            ___deadline,
2329        )?
2330        .into_result::<UsbFunctionInterfaceMarker>("control")?;
2331        Ok(_response.map(|x| x.read))
2332    }
2333
2334    /// Inform the protocol server (of [`UsbFunctionInterface`]) when the USB device configured
2335    /// state changes.
2336    ///
2337    /// Called with `configured == true` in response to a `SET_CONFIGURATION` control request that
2338    /// selects a configuration that contains this function. In this case, the protocol server
2339    /// should use [`UsbFunction.ConfigureEndpoint`] to configure its endpoints.
2340    ///
2341    /// Per USB 2.0 Specification Section 9.4.7, receiving a `SET_CONFIGURATION` request when the
2342    /// function is already configured is valid and should reset/re-initialize the function state
2343    /// rather than returning an error.
2344    ///
2345    /// Called with `configured == false` when configuration is disabled or USB is disconnected.
2346    /// The protocol server should then use [`UsbFunction.DisableEndpoint`] to disable its
2347    /// endpoints.
2348    ///
2349    /// The protocol server must perform all endpoint configuration/disabling and wait for those
2350    /// calls to complete before replying to this method. This ensures that the protocol client can
2351    /// report success/failure back to the host (by ACK'ing or STALL'ing the `SET_CONFIGURATION`
2352    /// request).
2353    ///
2354    /// Any error returned by this method causes the peripheral controller to stall Control
2355    /// Endpoint 0, signaling a failure to the host (rejecting the `SET_CONFIGURATION` request).
2356    ///
2357    /// * error:
2358    ///     * `ZX_ERR_BAD_STATE` if the device or function is in an uninitialized state where
2359    ///       configuration transitions are invalid (excluding re-configuring an active state).
2360    ///     * `ZX_ERR_INVALID_ARGS` if the speed or configuration parameters are invalid.
2361    ///     * `ZX_ERR_NOT_SUPPORTED` if the requested speed or configuration is unsupported.
2362    ///     * `ZX_ERR_NO_RESOURCES` if endpoint allocation or hardware configuration fails.
2363    pub fn r#set_configured(
2364        &self,
2365        mut configured: bool,
2366        mut speed: fidl_fuchsia_hardware_usb_descriptor::UsbSpeed,
2367        ___deadline: zx::MonotonicInstant,
2368    ) -> Result<UsbFunctionInterfaceSetConfiguredResult, fidl::Error> {
2369        let _response = self.client.send_query::<
2370            UsbFunctionInterfaceSetConfiguredRequest,
2371            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
2372            UsbFunctionInterfaceMarker,
2373        >(
2374            (configured, speed,),
2375            0x5c26cc1f53f57a72,
2376            fidl::encoding::DynamicFlags::FLEXIBLE,
2377            ___deadline,
2378        )?
2379        .into_result::<UsbFunctionInterfaceMarker>("set_configured")?;
2380        Ok(_response.map(|x| x))
2381    }
2382
2383    /// Called to set an alternate setting for an interface due to a `SET_INTERFACE` control
2384    /// request.
2385    ///
2386    /// The protocol server (of [`UsbFunctionInterface`]) must use [`UsbFunction.ConfigureEndpoint`]
2387    /// and [`UsbFunction.DisableEndpoint`] to configure or disable the interface's endpoints as
2388    /// appropriate for the new alternate setting.
2389    ///
2390    /// Depending on the alternate setting definition, this transition may require configuring new
2391    /// endpoints (via `ConfigureEndpoint`), disabling existing endpoints (via `DisableEndpoint`),
2392    /// or doing both. If an alternate setting does not use any endpoints, no endpoint
2393    /// configuration calls are required.
2394    ///
2395    /// The protocol server must perform all endpoint configuration/disabling and wait for those
2396    /// calls to complete before replying to this method. This ensures that the protocol client can
2397    /// report success/failure back to the host (by ACK'ing or STALL'ing the `SET_INTERFACE`
2398    /// request).
2399    ///
2400    /// Any error returned by this method causes the peripheral controller to stall Control
2401    /// Endpoint 0, signaling a failure to the host (rejecting the `SET_INTERFACE` request).
2402    ///
2403    /// * error:
2404    ///     * `ZX_ERR_NOT_SUPPORTED` if the alternate setting is not supported.
2405    ///     * `ZX_ERR_INVALID_ARGS` if the interface or alt_setting is invalid.
2406    ///     * Other errors if the function driver fails to configure or disable endpoints for the
2407    ///       new setting.
2408    pub fn r#set_interface(
2409        &self,
2410        mut interface: u8,
2411        mut alt_setting: u8,
2412        ___deadline: zx::MonotonicInstant,
2413    ) -> Result<UsbFunctionInterfaceSetInterfaceResult, fidl::Error> {
2414        let _response = self.client.send_query::<
2415            UsbFunctionInterfaceSetInterfaceRequest,
2416            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
2417            UsbFunctionInterfaceMarker,
2418        >(
2419            (interface, alt_setting,),
2420            0x42ebdcefc1543f32,
2421            fidl::encoding::DynamicFlags::FLEXIBLE,
2422            ___deadline,
2423        )?
2424        .into_result::<UsbFunctionInterfaceMarker>("set_interface")?;
2425        Ok(_response.map(|x| x))
2426    }
2427}
2428
2429#[cfg(target_os = "fuchsia")]
2430impl From<UsbFunctionInterfaceSynchronousProxy> for zx::NullableHandle {
2431    fn from(value: UsbFunctionInterfaceSynchronousProxy) -> Self {
2432        value.into_channel().into()
2433    }
2434}
2435
2436#[cfg(target_os = "fuchsia")]
2437impl From<fidl::Channel> for UsbFunctionInterfaceSynchronousProxy {
2438    fn from(value: fidl::Channel) -> Self {
2439        Self::new(value)
2440    }
2441}
2442
2443#[cfg(target_os = "fuchsia")]
2444impl fidl::endpoints::FromClient for UsbFunctionInterfaceSynchronousProxy {
2445    type Protocol = UsbFunctionInterfaceMarker;
2446
2447    fn from_client(value: fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>) -> Self {
2448        Self::new(value.into_channel())
2449    }
2450}
2451
2452#[derive(Debug, Clone)]
2453pub struct UsbFunctionInterfaceProxy {
2454    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
2455}
2456
2457impl fidl::endpoints::Proxy for UsbFunctionInterfaceProxy {
2458    type Protocol = UsbFunctionInterfaceMarker;
2459
2460    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
2461        Self::new(inner)
2462    }
2463
2464    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
2465        self.client.into_channel().map_err(|client| Self { client })
2466    }
2467
2468    fn as_channel(&self) -> &::fidl::AsyncChannel {
2469        self.client.as_channel()
2470    }
2471}
2472
2473impl UsbFunctionInterfaceProxy {
2474    /// Create a new Proxy for fuchsia.hardware.usb.function/UsbFunctionInterface.
2475    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
2476        let protocol_name =
2477            <UsbFunctionInterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
2478        Self { client: fidl::client::Client::new(channel, protocol_name) }
2479    }
2480
2481    /// Get a Stream of events from the remote end of the protocol.
2482    ///
2483    /// # Panics
2484    ///
2485    /// Panics if the event stream was already taken.
2486    pub fn take_event_stream(&self) -> UsbFunctionInterfaceEventStream {
2487        UsbFunctionInterfaceEventStream { event_receiver: self.client.take_event_receiver() }
2488    }
2489
2490    /// Callback for handling EP0 class/vendor-specific control requests targeting the interface(s)
2491    /// owned by this function.
2492    ///
2493    /// This is called when the host sends a control request to the device. The protocol server (of
2494    /// [`UsbFunctionInterface`]) should process the request and return the result.
2495    ///
2496    /// The host expects a response within a strict timeout period defined by the USB specification
2497    /// Section 9.2.6 (50ms for requests without data, and 500ms for read data stages). Because of
2498    /// these hardware-enforced limits, the implementation must reply as quickly as possible and
2499    /// avoid blocking the dispatcher.
2500    ///
2501    /// `setup` is the control request metadata (setup packet). `write` contains the raw bytes sent
2502    /// by the host in the Data Stage of a host-to-device (OUT) control transfer. It is empty for
2503    /// device-to-host (IN) transfers. `read` in the response payload contains the raw bytes
2504    /// returned to the host in the Data Stage of a device-to-host (IN) control transfer. It must
2505    /// be empty for host-to-device (OUT) transfers.
2506    ///
2507    /// Any error returned by this method (including `ZX_ERR_NOT_SUPPORTED`) causes the
2508    /// peripheral controller to stall Endpoint 0, signaling a "Request Error" to the host.
2509    ///
2510    /// * error:
2511    ///     * `ZX_ERR_NOT_SUPPORTED` if the request is not supported by the protocol server.
2512    ///     * `ZX_ERR_INVALID_ARGS` if the setup packet or data is invalid.
2513    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device was disconnected while processing the request.
2514    pub fn r#control(
2515        &self,
2516        mut setup: &fidl_fuchsia_hardware_usb_descriptor::UsbSetup,
2517        mut write: &[u8],
2518    ) -> fidl::client::QueryResponseFut<
2519        UsbFunctionInterfaceControlResult,
2520        fidl::encoding::DefaultFuchsiaResourceDialect,
2521    > {
2522        UsbFunctionInterfaceProxyInterface::r#control(self, setup, write)
2523    }
2524
2525    /// Inform the protocol server (of [`UsbFunctionInterface`]) when the USB device configured
2526    /// state changes.
2527    ///
2528    /// Called with `configured == true` in response to a `SET_CONFIGURATION` control request that
2529    /// selects a configuration that contains this function. In this case, the protocol server
2530    /// should use [`UsbFunction.ConfigureEndpoint`] to configure its endpoints.
2531    ///
2532    /// Per USB 2.0 Specification Section 9.4.7, receiving a `SET_CONFIGURATION` request when the
2533    /// function is already configured is valid and should reset/re-initialize the function state
2534    /// rather than returning an error.
2535    ///
2536    /// Called with `configured == false` when configuration is disabled or USB is disconnected.
2537    /// The protocol server should then use [`UsbFunction.DisableEndpoint`] to disable its
2538    /// endpoints.
2539    ///
2540    /// The protocol server must perform all endpoint configuration/disabling and wait for those
2541    /// calls to complete before replying to this method. This ensures that the protocol client can
2542    /// report success/failure back to the host (by ACK'ing or STALL'ing the `SET_CONFIGURATION`
2543    /// request).
2544    ///
2545    /// Any error returned by this method causes the peripheral controller to stall Control
2546    /// Endpoint 0, signaling a failure to the host (rejecting the `SET_CONFIGURATION` request).
2547    ///
2548    /// * error:
2549    ///     * `ZX_ERR_BAD_STATE` if the device or function is in an uninitialized state where
2550    ///       configuration transitions are invalid (excluding re-configuring an active state).
2551    ///     * `ZX_ERR_INVALID_ARGS` if the speed or configuration parameters are invalid.
2552    ///     * `ZX_ERR_NOT_SUPPORTED` if the requested speed or configuration is unsupported.
2553    ///     * `ZX_ERR_NO_RESOURCES` if endpoint allocation or hardware configuration fails.
2554    pub fn r#set_configured(
2555        &self,
2556        mut configured: bool,
2557        mut speed: fidl_fuchsia_hardware_usb_descriptor::UsbSpeed,
2558    ) -> fidl::client::QueryResponseFut<
2559        UsbFunctionInterfaceSetConfiguredResult,
2560        fidl::encoding::DefaultFuchsiaResourceDialect,
2561    > {
2562        UsbFunctionInterfaceProxyInterface::r#set_configured(self, configured, speed)
2563    }
2564
2565    /// Called to set an alternate setting for an interface due to a `SET_INTERFACE` control
2566    /// request.
2567    ///
2568    /// The protocol server (of [`UsbFunctionInterface`]) must use [`UsbFunction.ConfigureEndpoint`]
2569    /// and [`UsbFunction.DisableEndpoint`] to configure or disable the interface's endpoints as
2570    /// appropriate for the new alternate setting.
2571    ///
2572    /// Depending on the alternate setting definition, this transition may require configuring new
2573    /// endpoints (via `ConfigureEndpoint`), disabling existing endpoints (via `DisableEndpoint`),
2574    /// or doing both. If an alternate setting does not use any endpoints, no endpoint
2575    /// configuration calls are required.
2576    ///
2577    /// The protocol server must perform all endpoint configuration/disabling and wait for those
2578    /// calls to complete before replying to this method. This ensures that the protocol client can
2579    /// report success/failure back to the host (by ACK'ing or STALL'ing the `SET_INTERFACE`
2580    /// request).
2581    ///
2582    /// Any error returned by this method causes the peripheral controller to stall Control
2583    /// Endpoint 0, signaling a failure to the host (rejecting the `SET_INTERFACE` request).
2584    ///
2585    /// * error:
2586    ///     * `ZX_ERR_NOT_SUPPORTED` if the alternate setting is not supported.
2587    ///     * `ZX_ERR_INVALID_ARGS` if the interface or alt_setting is invalid.
2588    ///     * Other errors if the function driver fails to configure or disable endpoints for the
2589    ///       new setting.
2590    pub fn r#set_interface(
2591        &self,
2592        mut interface: u8,
2593        mut alt_setting: u8,
2594    ) -> fidl::client::QueryResponseFut<
2595        UsbFunctionInterfaceSetInterfaceResult,
2596        fidl::encoding::DefaultFuchsiaResourceDialect,
2597    > {
2598        UsbFunctionInterfaceProxyInterface::r#set_interface(self, interface, alt_setting)
2599    }
2600}
2601
2602impl UsbFunctionInterfaceProxyInterface for UsbFunctionInterfaceProxy {
2603    type ControlResponseFut = fidl::client::QueryResponseFut<
2604        UsbFunctionInterfaceControlResult,
2605        fidl::encoding::DefaultFuchsiaResourceDialect,
2606    >;
2607    fn r#control(
2608        &self,
2609        mut setup: &fidl_fuchsia_hardware_usb_descriptor::UsbSetup,
2610        mut write: &[u8],
2611    ) -> Self::ControlResponseFut {
2612        fn _decode(
2613            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
2614        ) -> Result<UsbFunctionInterfaceControlResult, fidl::Error> {
2615            let _response = fidl::client::decode_transaction_body::<
2616                fidl::encoding::FlexibleResultType<UsbFunctionInterfaceControlResponse, i32>,
2617                fidl::encoding::DefaultFuchsiaResourceDialect,
2618                0x3cce27231c012cff,
2619            >(_buf?)?
2620            .into_result::<UsbFunctionInterfaceMarker>("control")?;
2621            Ok(_response.map(|x| x.read))
2622        }
2623        self.client.send_query_and_decode::<
2624            UsbFunctionInterfaceControlRequest,
2625            UsbFunctionInterfaceControlResult,
2626        >(
2627            (setup, write,),
2628            0x3cce27231c012cff,
2629            fidl::encoding::DynamicFlags::FLEXIBLE,
2630            _decode,
2631        )
2632    }
2633
2634    type SetConfiguredResponseFut = fidl::client::QueryResponseFut<
2635        UsbFunctionInterfaceSetConfiguredResult,
2636        fidl::encoding::DefaultFuchsiaResourceDialect,
2637    >;
2638    fn r#set_configured(
2639        &self,
2640        mut configured: bool,
2641        mut speed: fidl_fuchsia_hardware_usb_descriptor::UsbSpeed,
2642    ) -> Self::SetConfiguredResponseFut {
2643        fn _decode(
2644            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
2645        ) -> Result<UsbFunctionInterfaceSetConfiguredResult, fidl::Error> {
2646            let _response = fidl::client::decode_transaction_body::<
2647                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
2648                fidl::encoding::DefaultFuchsiaResourceDialect,
2649                0x5c26cc1f53f57a72,
2650            >(_buf?)?
2651            .into_result::<UsbFunctionInterfaceMarker>("set_configured")?;
2652            Ok(_response.map(|x| x))
2653        }
2654        self.client.send_query_and_decode::<
2655            UsbFunctionInterfaceSetConfiguredRequest,
2656            UsbFunctionInterfaceSetConfiguredResult,
2657        >(
2658            (configured, speed,),
2659            0x5c26cc1f53f57a72,
2660            fidl::encoding::DynamicFlags::FLEXIBLE,
2661            _decode,
2662        )
2663    }
2664
2665    type SetInterfaceResponseFut = fidl::client::QueryResponseFut<
2666        UsbFunctionInterfaceSetInterfaceResult,
2667        fidl::encoding::DefaultFuchsiaResourceDialect,
2668    >;
2669    fn r#set_interface(
2670        &self,
2671        mut interface: u8,
2672        mut alt_setting: u8,
2673    ) -> Self::SetInterfaceResponseFut {
2674        fn _decode(
2675            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
2676        ) -> Result<UsbFunctionInterfaceSetInterfaceResult, fidl::Error> {
2677            let _response = fidl::client::decode_transaction_body::<
2678                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
2679                fidl::encoding::DefaultFuchsiaResourceDialect,
2680                0x42ebdcefc1543f32,
2681            >(_buf?)?
2682            .into_result::<UsbFunctionInterfaceMarker>("set_interface")?;
2683            Ok(_response.map(|x| x))
2684        }
2685        self.client.send_query_and_decode::<
2686            UsbFunctionInterfaceSetInterfaceRequest,
2687            UsbFunctionInterfaceSetInterfaceResult,
2688        >(
2689            (interface, alt_setting,),
2690            0x42ebdcefc1543f32,
2691            fidl::encoding::DynamicFlags::FLEXIBLE,
2692            _decode,
2693        )
2694    }
2695}
2696
2697pub struct UsbFunctionInterfaceEventStream {
2698    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
2699}
2700
2701impl std::marker::Unpin for UsbFunctionInterfaceEventStream {}
2702
2703impl futures::stream::FusedStream for UsbFunctionInterfaceEventStream {
2704    fn is_terminated(&self) -> bool {
2705        self.event_receiver.is_terminated()
2706    }
2707}
2708
2709impl futures::Stream for UsbFunctionInterfaceEventStream {
2710    type Item = Result<UsbFunctionInterfaceEvent, fidl::Error>;
2711
2712    fn poll_next(
2713        mut self: std::pin::Pin<&mut Self>,
2714        cx: &mut std::task::Context<'_>,
2715    ) -> std::task::Poll<Option<Self::Item>> {
2716        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
2717            &mut self.event_receiver,
2718            cx
2719        )?) {
2720            Some(buf) => std::task::Poll::Ready(Some(UsbFunctionInterfaceEvent::decode(buf))),
2721            None => std::task::Poll::Ready(None),
2722        }
2723    }
2724}
2725
2726#[derive(Debug)]
2727pub enum UsbFunctionInterfaceEvent {
2728    #[non_exhaustive]
2729    _UnknownEvent {
2730        /// Ordinal of the event that was sent.
2731        ordinal: u64,
2732    },
2733}
2734
2735impl UsbFunctionInterfaceEvent {
2736    /// Decodes a message buffer as a [`UsbFunctionInterfaceEvent`].
2737    fn decode(
2738        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
2739    ) -> Result<UsbFunctionInterfaceEvent, fidl::Error> {
2740        let (bytes, _handles) = buf.split_mut();
2741        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
2742        debug_assert_eq!(tx_header.tx_id, 0);
2743        match tx_header.ordinal {
2744            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
2745                Ok(UsbFunctionInterfaceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
2746            }
2747            _ => Err(fidl::Error::UnknownOrdinal {
2748                ordinal: tx_header.ordinal,
2749                protocol_name:
2750                    <UsbFunctionInterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
2751            }),
2752        }
2753    }
2754}
2755
2756/// A Stream of incoming requests for fuchsia.hardware.usb.function/UsbFunctionInterface.
2757pub struct UsbFunctionInterfaceRequestStream {
2758    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
2759    is_terminated: bool,
2760}
2761
2762impl std::marker::Unpin for UsbFunctionInterfaceRequestStream {}
2763
2764impl futures::stream::FusedStream for UsbFunctionInterfaceRequestStream {
2765    fn is_terminated(&self) -> bool {
2766        self.is_terminated
2767    }
2768}
2769
2770impl fidl::endpoints::RequestStream for UsbFunctionInterfaceRequestStream {
2771    type Protocol = UsbFunctionInterfaceMarker;
2772    type ControlHandle = UsbFunctionInterfaceControlHandle;
2773
2774    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
2775        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
2776    }
2777
2778    fn control_handle(&self) -> Self::ControlHandle {
2779        UsbFunctionInterfaceControlHandle { inner: self.inner.clone() }
2780    }
2781
2782    fn into_inner(
2783        self,
2784    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
2785    {
2786        (self.inner, self.is_terminated)
2787    }
2788
2789    fn from_inner(
2790        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
2791        is_terminated: bool,
2792    ) -> Self {
2793        Self { inner, is_terminated }
2794    }
2795}
2796
2797impl futures::Stream for UsbFunctionInterfaceRequestStream {
2798    type Item = Result<UsbFunctionInterfaceRequest, fidl::Error>;
2799
2800    fn poll_next(
2801        mut self: std::pin::Pin<&mut Self>,
2802        cx: &mut std::task::Context<'_>,
2803    ) -> std::task::Poll<Option<Self::Item>> {
2804        let this = &mut *self;
2805        if this.inner.check_shutdown(cx) {
2806            this.is_terminated = true;
2807            return std::task::Poll::Ready(None);
2808        }
2809        if this.is_terminated {
2810            panic!("polled UsbFunctionInterfaceRequestStream after completion");
2811        }
2812        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
2813            |bytes, handles| {
2814                match this.inner.channel().read_etc(cx, bytes, handles) {
2815                    std::task::Poll::Ready(Ok(())) => {}
2816                    std::task::Poll::Pending => return std::task::Poll::Pending,
2817                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
2818                        this.is_terminated = true;
2819                        return std::task::Poll::Ready(None);
2820                    }
2821                    std::task::Poll::Ready(Err(e)) => {
2822                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
2823                            e.into(),
2824                        ))));
2825                    }
2826                }
2827
2828                // A message has been received from the channel
2829                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
2830
2831                std::task::Poll::Ready(Some(match header.ordinal {
2832                0x3cce27231c012cff => {
2833                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
2834                    let mut req = fidl::new_empty!(UsbFunctionInterfaceControlRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
2835                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionInterfaceControlRequest>(&header, _body_bytes, handles, &mut req)?;
2836                    let control_handle = UsbFunctionInterfaceControlHandle {
2837                        inner: this.inner.clone(),
2838                    };
2839                    Ok(UsbFunctionInterfaceRequest::Control {setup: req.setup,
2840write: req.write,
2841
2842                        responder: UsbFunctionInterfaceControlResponder {
2843                            control_handle: std::mem::ManuallyDrop::new(control_handle),
2844                            tx_id: header.tx_id,
2845                        },
2846                    })
2847                }
2848                0x5c26cc1f53f57a72 => {
2849                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
2850                    let mut req = fidl::new_empty!(UsbFunctionInterfaceSetConfiguredRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
2851                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionInterfaceSetConfiguredRequest>(&header, _body_bytes, handles, &mut req)?;
2852                    let control_handle = UsbFunctionInterfaceControlHandle {
2853                        inner: this.inner.clone(),
2854                    };
2855                    Ok(UsbFunctionInterfaceRequest::SetConfigured {configured: req.configured,
2856speed: req.speed,
2857
2858                        responder: UsbFunctionInterfaceSetConfiguredResponder {
2859                            control_handle: std::mem::ManuallyDrop::new(control_handle),
2860                            tx_id: header.tx_id,
2861                        },
2862                    })
2863                }
2864                0x42ebdcefc1543f32 => {
2865                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
2866                    let mut req = fidl::new_empty!(UsbFunctionInterfaceSetInterfaceRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
2867                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UsbFunctionInterfaceSetInterfaceRequest>(&header, _body_bytes, handles, &mut req)?;
2868                    let control_handle = UsbFunctionInterfaceControlHandle {
2869                        inner: this.inner.clone(),
2870                    };
2871                    Ok(UsbFunctionInterfaceRequest::SetInterface {interface: req.interface,
2872alt_setting: req.alt_setting,
2873
2874                        responder: UsbFunctionInterfaceSetInterfaceResponder {
2875                            control_handle: std::mem::ManuallyDrop::new(control_handle),
2876                            tx_id: header.tx_id,
2877                        },
2878                    })
2879                }
2880                _ if header.tx_id == 0 && header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
2881                    Ok(UsbFunctionInterfaceRequest::_UnknownMethod {
2882                        ordinal: header.ordinal,
2883                        control_handle: UsbFunctionInterfaceControlHandle { inner: this.inner.clone() },
2884                        method_type: fidl::MethodType::OneWay,
2885                    })
2886                }
2887                _ if header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
2888                    this.inner.send_framework_err(
2889                        fidl::encoding::FrameworkErr::UnknownMethod,
2890                        header.tx_id,
2891                        header.ordinal,
2892                        header.dynamic_flags(),
2893                        (bytes, handles),
2894                    )?;
2895                    Ok(UsbFunctionInterfaceRequest::_UnknownMethod {
2896                        ordinal: header.ordinal,
2897                        control_handle: UsbFunctionInterfaceControlHandle { inner: this.inner.clone() },
2898                        method_type: fidl::MethodType::TwoWay,
2899                    })
2900                }
2901                _ => Err(fidl::Error::UnknownOrdinal {
2902                    ordinal: header.ordinal,
2903                    protocol_name: <UsbFunctionInterfaceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
2904                }),
2905            }))
2906            },
2907        )
2908    }
2909}
2910
2911/// Protocol offered to [`UsbFunction`] instances to handle host-initiated
2912/// requests.
2913///
2914/// This protocol is implemented by the USB function driver (protocol server)
2915/// and called by the USB peripheral controller (protocol client).
2916#[derive(Debug)]
2917pub enum UsbFunctionInterfaceRequest {
2918    /// Callback for handling EP0 class/vendor-specific control requests targeting the interface(s)
2919    /// owned by this function.
2920    ///
2921    /// This is called when the host sends a control request to the device. The protocol server (of
2922    /// [`UsbFunctionInterface`]) should process the request and return the result.
2923    ///
2924    /// The host expects a response within a strict timeout period defined by the USB specification
2925    /// Section 9.2.6 (50ms for requests without data, and 500ms for read data stages). Because of
2926    /// these hardware-enforced limits, the implementation must reply as quickly as possible and
2927    /// avoid blocking the dispatcher.
2928    ///
2929    /// `setup` is the control request metadata (setup packet). `write` contains the raw bytes sent
2930    /// by the host in the Data Stage of a host-to-device (OUT) control transfer. It is empty for
2931    /// device-to-host (IN) transfers. `read` in the response payload contains the raw bytes
2932    /// returned to the host in the Data Stage of a device-to-host (IN) control transfer. It must
2933    /// be empty for host-to-device (OUT) transfers.
2934    ///
2935    /// Any error returned by this method (including `ZX_ERR_NOT_SUPPORTED`) causes the
2936    /// peripheral controller to stall Endpoint 0, signaling a "Request Error" to the host.
2937    ///
2938    /// * error:
2939    ///     * `ZX_ERR_NOT_SUPPORTED` if the request is not supported by the protocol server.
2940    ///     * `ZX_ERR_INVALID_ARGS` if the setup packet or data is invalid.
2941    ///     * `ZX_ERR_IO_NOT_PRESENT` if the device was disconnected while processing the request.
2942    Control {
2943        setup: fidl_fuchsia_hardware_usb_descriptor::UsbSetup,
2944        write: Vec<u8>,
2945        responder: UsbFunctionInterfaceControlResponder,
2946    },
2947    /// Inform the protocol server (of [`UsbFunctionInterface`]) when the USB device configured
2948    /// state changes.
2949    ///
2950    /// Called with `configured == true` in response to a `SET_CONFIGURATION` control request that
2951    /// selects a configuration that contains this function. In this case, the protocol server
2952    /// should use [`UsbFunction.ConfigureEndpoint`] to configure its endpoints.
2953    ///
2954    /// Per USB 2.0 Specification Section 9.4.7, receiving a `SET_CONFIGURATION` request when the
2955    /// function is already configured is valid and should reset/re-initialize the function state
2956    /// rather than returning an error.
2957    ///
2958    /// Called with `configured == false` when configuration is disabled or USB is disconnected.
2959    /// The protocol server should then use [`UsbFunction.DisableEndpoint`] to disable its
2960    /// endpoints.
2961    ///
2962    /// The protocol server must perform all endpoint configuration/disabling and wait for those
2963    /// calls to complete before replying to this method. This ensures that the protocol client can
2964    /// report success/failure back to the host (by ACK'ing or STALL'ing the `SET_CONFIGURATION`
2965    /// request).
2966    ///
2967    /// Any error returned by this method causes the peripheral controller to stall Control
2968    /// Endpoint 0, signaling a failure to the host (rejecting the `SET_CONFIGURATION` request).
2969    ///
2970    /// * error:
2971    ///     * `ZX_ERR_BAD_STATE` if the device or function is in an uninitialized state where
2972    ///       configuration transitions are invalid (excluding re-configuring an active state).
2973    ///     * `ZX_ERR_INVALID_ARGS` if the speed or configuration parameters are invalid.
2974    ///     * `ZX_ERR_NOT_SUPPORTED` if the requested speed or configuration is unsupported.
2975    ///     * `ZX_ERR_NO_RESOURCES` if endpoint allocation or hardware configuration fails.
2976    SetConfigured {
2977        configured: bool,
2978        speed: fidl_fuchsia_hardware_usb_descriptor::UsbSpeed,
2979        responder: UsbFunctionInterfaceSetConfiguredResponder,
2980    },
2981    /// Called to set an alternate setting for an interface due to a `SET_INTERFACE` control
2982    /// request.
2983    ///
2984    /// The protocol server (of [`UsbFunctionInterface`]) must use [`UsbFunction.ConfigureEndpoint`]
2985    /// and [`UsbFunction.DisableEndpoint`] to configure or disable the interface's endpoints as
2986    /// appropriate for the new alternate setting.
2987    ///
2988    /// Depending on the alternate setting definition, this transition may require configuring new
2989    /// endpoints (via `ConfigureEndpoint`), disabling existing endpoints (via `DisableEndpoint`),
2990    /// or doing both. If an alternate setting does not use any endpoints, no endpoint
2991    /// configuration calls are required.
2992    ///
2993    /// The protocol server must perform all endpoint configuration/disabling and wait for those
2994    /// calls to complete before replying to this method. This ensures that the protocol client can
2995    /// report success/failure back to the host (by ACK'ing or STALL'ing the `SET_INTERFACE`
2996    /// request).
2997    ///
2998    /// Any error returned by this method causes the peripheral controller to stall Control
2999    /// Endpoint 0, signaling a failure to the host (rejecting the `SET_INTERFACE` request).
3000    ///
3001    /// * error:
3002    ///     * `ZX_ERR_NOT_SUPPORTED` if the alternate setting is not supported.
3003    ///     * `ZX_ERR_INVALID_ARGS` if the interface or alt_setting is invalid.
3004    ///     * Other errors if the function driver fails to configure or disable endpoints for the
3005    ///       new setting.
3006    SetInterface {
3007        interface: u8,
3008        alt_setting: u8,
3009        responder: UsbFunctionInterfaceSetInterfaceResponder,
3010    },
3011    /// An interaction was received which does not match any known method.
3012    #[non_exhaustive]
3013    _UnknownMethod {
3014        /// Ordinal of the method that was called.
3015        ordinal: u64,
3016        control_handle: UsbFunctionInterfaceControlHandle,
3017        method_type: fidl::MethodType,
3018    },
3019}
3020
3021impl UsbFunctionInterfaceRequest {
3022    #[allow(irrefutable_let_patterns)]
3023    pub fn into_control(
3024        self,
3025    ) -> Option<(
3026        fidl_fuchsia_hardware_usb_descriptor::UsbSetup,
3027        Vec<u8>,
3028        UsbFunctionInterfaceControlResponder,
3029    )> {
3030        if let UsbFunctionInterfaceRequest::Control { setup, write, responder } = self {
3031            Some((setup, write, responder))
3032        } else {
3033            None
3034        }
3035    }
3036
3037    #[allow(irrefutable_let_patterns)]
3038    pub fn into_set_configured(
3039        self,
3040    ) -> Option<(
3041        bool,
3042        fidl_fuchsia_hardware_usb_descriptor::UsbSpeed,
3043        UsbFunctionInterfaceSetConfiguredResponder,
3044    )> {
3045        if let UsbFunctionInterfaceRequest::SetConfigured { configured, speed, responder } = self {
3046            Some((configured, speed, responder))
3047        } else {
3048            None
3049        }
3050    }
3051
3052    #[allow(irrefutable_let_patterns)]
3053    pub fn into_set_interface(self) -> Option<(u8, u8, UsbFunctionInterfaceSetInterfaceResponder)> {
3054        if let UsbFunctionInterfaceRequest::SetInterface { interface, alt_setting, responder } =
3055            self
3056        {
3057            Some((interface, alt_setting, responder))
3058        } else {
3059            None
3060        }
3061    }
3062
3063    /// Name of the method defined in FIDL
3064    pub fn method_name(&self) -> &'static str {
3065        match *self {
3066            UsbFunctionInterfaceRequest::Control { .. } => "control",
3067            UsbFunctionInterfaceRequest::SetConfigured { .. } => "set_configured",
3068            UsbFunctionInterfaceRequest::SetInterface { .. } => "set_interface",
3069            UsbFunctionInterfaceRequest::_UnknownMethod {
3070                method_type: fidl::MethodType::OneWay,
3071                ..
3072            } => "unknown one-way method",
3073            UsbFunctionInterfaceRequest::_UnknownMethod {
3074                method_type: fidl::MethodType::TwoWay,
3075                ..
3076            } => "unknown two-way method",
3077        }
3078    }
3079}
3080
3081#[derive(Debug, Clone)]
3082pub struct UsbFunctionInterfaceControlHandle {
3083    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
3084}
3085
3086impl UsbFunctionInterfaceControlHandle {
3087    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
3088        self.inner.shutdown_with_epitaph(status.into())
3089    }
3090}
3091
3092impl fidl::endpoints::ControlHandle for UsbFunctionInterfaceControlHandle {
3093    fn shutdown(&self) {
3094        self.inner.shutdown()
3095    }
3096
3097    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
3098        self.inner.shutdown_with_epitaph(status)
3099    }
3100
3101    fn is_closed(&self) -> bool {
3102        self.inner.channel().is_closed()
3103    }
3104    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
3105        self.inner.channel().on_closed()
3106    }
3107
3108    #[cfg(target_os = "fuchsia")]
3109    fn signal_peer(
3110        &self,
3111        clear_mask: zx::Signals,
3112        set_mask: zx::Signals,
3113    ) -> Result<(), zx_status::Status> {
3114        use fidl::Peered;
3115        self.inner.channel().signal_peer(clear_mask, set_mask)
3116    }
3117}
3118
3119impl UsbFunctionInterfaceControlHandle {}
3120
3121#[must_use = "FIDL methods require a response to be sent"]
3122#[derive(Debug)]
3123pub struct UsbFunctionInterfaceControlResponder {
3124    control_handle: std::mem::ManuallyDrop<UsbFunctionInterfaceControlHandle>,
3125    tx_id: u32,
3126}
3127
3128/// Set the the channel to be shutdown (see [`UsbFunctionInterfaceControlHandle::shutdown`])
3129/// if the responder is dropped without sending a response, so that the client
3130/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
3131impl std::ops::Drop for UsbFunctionInterfaceControlResponder {
3132    fn drop(&mut self) {
3133        self.control_handle.shutdown();
3134        // Safety: drops once, never accessed again
3135        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3136    }
3137}
3138
3139impl fidl::endpoints::Responder for UsbFunctionInterfaceControlResponder {
3140    type ControlHandle = UsbFunctionInterfaceControlHandle;
3141
3142    fn control_handle(&self) -> &UsbFunctionInterfaceControlHandle {
3143        &self.control_handle
3144    }
3145
3146    fn drop_without_shutdown(mut self) {
3147        // Safety: drops once, never accessed again due to mem::forget
3148        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3149        // Prevent Drop from running (which would shut down the channel)
3150        std::mem::forget(self);
3151    }
3152}
3153
3154impl UsbFunctionInterfaceControlResponder {
3155    /// Sends a response to the FIDL transaction.
3156    ///
3157    /// Sets the channel to shutdown if an error occurs.
3158    pub fn send(self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
3159        let _result = self.send_raw(result);
3160        if _result.is_err() {
3161            self.control_handle.shutdown();
3162        }
3163        self.drop_without_shutdown();
3164        _result
3165    }
3166
3167    /// Similar to "send" but does not shutdown the channel if an error occurs.
3168    pub fn send_no_shutdown_on_err(
3169        self,
3170        mut result: Result<&[u8], i32>,
3171    ) -> Result<(), fidl::Error> {
3172        let _result = self.send_raw(result);
3173        self.drop_without_shutdown();
3174        _result
3175    }
3176
3177    fn send_raw(&self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
3178        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
3179            UsbFunctionInterfaceControlResponse,
3180            i32,
3181        >>(
3182            fidl::encoding::FlexibleResult::new(result.map(|read| (read,))),
3183            self.tx_id,
3184            0x3cce27231c012cff,
3185            fidl::encoding::DynamicFlags::FLEXIBLE,
3186        )
3187    }
3188}
3189
3190#[must_use = "FIDL methods require a response to be sent"]
3191#[derive(Debug)]
3192pub struct UsbFunctionInterfaceSetConfiguredResponder {
3193    control_handle: std::mem::ManuallyDrop<UsbFunctionInterfaceControlHandle>,
3194    tx_id: u32,
3195}
3196
3197/// Set the the channel to be shutdown (see [`UsbFunctionInterfaceControlHandle::shutdown`])
3198/// if the responder is dropped without sending a response, so that the client
3199/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
3200impl std::ops::Drop for UsbFunctionInterfaceSetConfiguredResponder {
3201    fn drop(&mut self) {
3202        self.control_handle.shutdown();
3203        // Safety: drops once, never accessed again
3204        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3205    }
3206}
3207
3208impl fidl::endpoints::Responder for UsbFunctionInterfaceSetConfiguredResponder {
3209    type ControlHandle = UsbFunctionInterfaceControlHandle;
3210
3211    fn control_handle(&self) -> &UsbFunctionInterfaceControlHandle {
3212        &self.control_handle
3213    }
3214
3215    fn drop_without_shutdown(mut self) {
3216        // Safety: drops once, never accessed again due to mem::forget
3217        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3218        // Prevent Drop from running (which would shut down the channel)
3219        std::mem::forget(self);
3220    }
3221}
3222
3223impl UsbFunctionInterfaceSetConfiguredResponder {
3224    /// Sends a response to the FIDL transaction.
3225    ///
3226    /// Sets the channel to shutdown if an error occurs.
3227    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
3228        let _result = self.send_raw(result);
3229        if _result.is_err() {
3230            self.control_handle.shutdown();
3231        }
3232        self.drop_without_shutdown();
3233        _result
3234    }
3235
3236    /// Similar to "send" but does not shutdown the channel if an error occurs.
3237    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
3238        let _result = self.send_raw(result);
3239        self.drop_without_shutdown();
3240        _result
3241    }
3242
3243    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
3244        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
3245            fidl::encoding::EmptyStruct,
3246            i32,
3247        >>(
3248            fidl::encoding::FlexibleResult::new(result),
3249            self.tx_id,
3250            0x5c26cc1f53f57a72,
3251            fidl::encoding::DynamicFlags::FLEXIBLE,
3252        )
3253    }
3254}
3255
3256#[must_use = "FIDL methods require a response to be sent"]
3257#[derive(Debug)]
3258pub struct UsbFunctionInterfaceSetInterfaceResponder {
3259    control_handle: std::mem::ManuallyDrop<UsbFunctionInterfaceControlHandle>,
3260    tx_id: u32,
3261}
3262
3263/// Set the the channel to be shutdown (see [`UsbFunctionInterfaceControlHandle::shutdown`])
3264/// if the responder is dropped without sending a response, so that the client
3265/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
3266impl std::ops::Drop for UsbFunctionInterfaceSetInterfaceResponder {
3267    fn drop(&mut self) {
3268        self.control_handle.shutdown();
3269        // Safety: drops once, never accessed again
3270        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3271    }
3272}
3273
3274impl fidl::endpoints::Responder for UsbFunctionInterfaceSetInterfaceResponder {
3275    type ControlHandle = UsbFunctionInterfaceControlHandle;
3276
3277    fn control_handle(&self) -> &UsbFunctionInterfaceControlHandle {
3278        &self.control_handle
3279    }
3280
3281    fn drop_without_shutdown(mut self) {
3282        // Safety: drops once, never accessed again due to mem::forget
3283        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3284        // Prevent Drop from running (which would shut down the channel)
3285        std::mem::forget(self);
3286    }
3287}
3288
3289impl UsbFunctionInterfaceSetInterfaceResponder {
3290    /// Sends a response to the FIDL transaction.
3291    ///
3292    /// Sets the channel to shutdown if an error occurs.
3293    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
3294        let _result = self.send_raw(result);
3295        if _result.is_err() {
3296            self.control_handle.shutdown();
3297        }
3298        self.drop_without_shutdown();
3299        _result
3300    }
3301
3302    /// Similar to "send" but does not shutdown the channel if an error occurs.
3303    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
3304        let _result = self.send_raw(result);
3305        self.drop_without_shutdown();
3306        _result
3307    }
3308
3309    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
3310        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
3311            fidl::encoding::EmptyStruct,
3312            i32,
3313        >>(
3314            fidl::encoding::FlexibleResult::new(result),
3315            self.tx_id,
3316            0x42ebdcefc1543f32,
3317            fidl::encoding::DynamicFlags::FLEXIBLE,
3318        )
3319    }
3320}
3321
3322#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
3323pub struct UsbFunctionServiceMarker;
3324
3325#[cfg(target_os = "fuchsia")]
3326impl fidl::endpoints::ServiceMarker for UsbFunctionServiceMarker {
3327    type Proxy = UsbFunctionServiceProxy;
3328    type Request = UsbFunctionServiceRequest;
3329    const SERVICE_NAME: &'static str = "fuchsia.hardware.usb.function.UsbFunctionService";
3330}
3331
3332/// A request for one of the member protocols of UsbFunctionService.
3333///
3334#[cfg(target_os = "fuchsia")]
3335pub enum UsbFunctionServiceRequest {
3336    Device(UsbFunctionRequestStream),
3337}
3338
3339#[cfg(target_os = "fuchsia")]
3340impl fidl::endpoints::ServiceRequest for UsbFunctionServiceRequest {
3341    type Service = UsbFunctionServiceMarker;
3342
3343    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
3344        match name {
3345            "device" => Self::Device(
3346                <UsbFunctionRequestStream as fidl::endpoints::RequestStream>::from_channel(
3347                    _channel,
3348                ),
3349            ),
3350            _ => panic!("no such member protocol name for service UsbFunctionService"),
3351        }
3352    }
3353
3354    fn member_names() -> &'static [&'static str] {
3355        &["device"]
3356    }
3357}
3358#[cfg(target_os = "fuchsia")]
3359pub struct UsbFunctionServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
3360
3361#[cfg(target_os = "fuchsia")]
3362impl fidl::endpoints::ServiceProxy for UsbFunctionServiceProxy {
3363    type Service = UsbFunctionServiceMarker;
3364
3365    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
3366        Self(opener)
3367    }
3368}
3369
3370#[cfg(target_os = "fuchsia")]
3371impl UsbFunctionServiceProxy {
3372    pub fn connect_to_device(&self) -> Result<UsbFunctionProxy, fidl::Error> {
3373        let (proxy, server_end) = fidl::endpoints::create_proxy::<UsbFunctionMarker>();
3374        self.connect_channel_to_device(server_end)?;
3375        Ok(proxy)
3376    }
3377
3378    /// Like `connect_to_device`, but returns a sync proxy.
3379    /// See [`Self::connect_to_device`] for more details.
3380    pub fn connect_to_device_sync(&self) -> Result<UsbFunctionSynchronousProxy, fidl::Error> {
3381        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<UsbFunctionMarker>();
3382        self.connect_channel_to_device(server_end)?;
3383        Ok(proxy)
3384    }
3385
3386    /// Like `connect_to_device`, but accepts a server end.
3387    /// See [`Self::connect_to_device`] for more details.
3388    pub fn connect_channel_to_device(
3389        &self,
3390        server_end: fidl::endpoints::ServerEnd<UsbFunctionMarker>,
3391    ) -> Result<(), fidl::Error> {
3392        self.0.open_member("device", server_end.into_channel())
3393    }
3394
3395    pub fn instance_name(&self) -> &str {
3396        self.0.instance_name()
3397    }
3398}
3399
3400mod internal {
3401    use super::*;
3402
3403    impl fidl::encoding::ResourceTypeMarker for EndpointResource {
3404        type Borrowed<'a> = &'a mut Self;
3405        fn take_or_borrow<'a>(
3406            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
3407        ) -> Self::Borrowed<'a> {
3408            value
3409        }
3410    }
3411
3412    unsafe impl fidl::encoding::TypeMarker for EndpointResource {
3413        type Owned = Self;
3414
3415        #[inline(always)]
3416        fn inline_align(_context: fidl::encoding::Context) -> usize {
3417            8
3418        }
3419
3420        #[inline(always)]
3421        fn inline_size(_context: fidl::encoding::Context) -> usize {
3422            32
3423        }
3424    }
3425
3426    unsafe impl
3427        fidl::encoding::Encode<EndpointResource, fidl::encoding::DefaultFuchsiaResourceDialect>
3428        for &mut EndpointResource
3429    {
3430        #[inline]
3431        unsafe fn encode(
3432            self,
3433            encoder: &mut fidl::encoding::Encoder<
3434                '_,
3435                fidl::encoding::DefaultFuchsiaResourceDialect,
3436            >,
3437            offset: usize,
3438            _depth: fidl::encoding::Depth,
3439        ) -> fidl::Result<()> {
3440            encoder.debug_check_bounds::<EndpointResource>(offset);
3441            // Delegate to tuple encoding.
3442            fidl::encoding::Encode::<EndpointResource, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
3443                (
3444                    <fidl_fuchsia_hardware_usb_descriptor::EndpointDirection as fidl::encoding::ValueTypeMarker>::borrow(&self.direction),
3445                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.endpoint),
3446                    <fidl_fuchsia_hardware_usb_endpoint::EndpointInfo as fidl::encoding::ValueTypeMarker>::borrow(&self.ep_info),
3447                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.max_packet_size),
3448                ),
3449                encoder, offset, _depth
3450            )
3451        }
3452    }
3453    unsafe impl<
3454        T0: fidl::encoding::Encode<
3455                fidl_fuchsia_hardware_usb_descriptor::EndpointDirection,
3456                fidl::encoding::DefaultFuchsiaResourceDialect,
3457            >,
3458        T1: fidl::encoding::Encode<
3459                fidl::encoding::Endpoint<
3460                    fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
3461                >,
3462                fidl::encoding::DefaultFuchsiaResourceDialect,
3463            >,
3464        T2: fidl::encoding::Encode<
3465                fidl_fuchsia_hardware_usb_endpoint::EndpointInfo,
3466                fidl::encoding::DefaultFuchsiaResourceDialect,
3467            >,
3468        T3: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
3469    > fidl::encoding::Encode<EndpointResource, fidl::encoding::DefaultFuchsiaResourceDialect>
3470        for (T0, T1, T2, T3)
3471    {
3472        #[inline]
3473        unsafe fn encode(
3474            self,
3475            encoder: &mut fidl::encoding::Encoder<
3476                '_,
3477                fidl::encoding::DefaultFuchsiaResourceDialect,
3478            >,
3479            offset: usize,
3480            depth: fidl::encoding::Depth,
3481        ) -> fidl::Result<()> {
3482            encoder.debug_check_bounds::<EndpointResource>(offset);
3483            // Zero out padding regions. There's no need to apply masks
3484            // because the unmasked parts will be overwritten by fields.
3485            unsafe {
3486                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
3487                (ptr as *mut u64).write_unaligned(0);
3488            }
3489            unsafe {
3490                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(24);
3491                (ptr as *mut u64).write_unaligned(0);
3492            }
3493            // Write the fields.
3494            self.0.encode(encoder, offset + 0, depth)?;
3495            self.1.encode(encoder, offset + 4, depth)?;
3496            self.2.encode(encoder, offset + 8, depth)?;
3497            self.3.encode(encoder, offset + 24, depth)?;
3498            Ok(())
3499        }
3500    }
3501
3502    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
3503        for EndpointResource
3504    {
3505        #[inline(always)]
3506        fn new_empty() -> Self {
3507            Self {
3508                direction: fidl::new_empty!(
3509                    fidl_fuchsia_hardware_usb_descriptor::EndpointDirection,
3510                    fidl::encoding::DefaultFuchsiaResourceDialect
3511                ),
3512                endpoint: fidl::new_empty!(
3513                    fidl::encoding::Endpoint<
3514                        fidl::endpoints::ServerEnd<
3515                            fidl_fuchsia_hardware_usb_endpoint::EndpointMarker,
3516                        >,
3517                    >,
3518                    fidl::encoding::DefaultFuchsiaResourceDialect
3519                ),
3520                ep_info: fidl::new_empty!(
3521                    fidl_fuchsia_hardware_usb_endpoint::EndpointInfo,
3522                    fidl::encoding::DefaultFuchsiaResourceDialect
3523                ),
3524                max_packet_size: fidl::new_empty!(
3525                    u32,
3526                    fidl::encoding::DefaultFuchsiaResourceDialect
3527                ),
3528            }
3529        }
3530
3531        #[inline]
3532        unsafe fn decode(
3533            &mut self,
3534            decoder: &mut fidl::encoding::Decoder<
3535                '_,
3536                fidl::encoding::DefaultFuchsiaResourceDialect,
3537            >,
3538            offset: usize,
3539            _depth: fidl::encoding::Depth,
3540        ) -> fidl::Result<()> {
3541            decoder.debug_check_bounds::<Self>(offset);
3542            // Verify that padding bytes are zero.
3543            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
3544            let padval = unsafe { (ptr as *const u64).read_unaligned() };
3545            let mask = 0xffffff00u64;
3546            let maskedval = padval & mask;
3547            if maskedval != 0 {
3548                return Err(fidl::Error::NonZeroPadding {
3549                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
3550                });
3551            }
3552            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(24) };
3553            let padval = unsafe { (ptr as *const u64).read_unaligned() };
3554            let mask = 0xffffffff00000000u64;
3555            let maskedval = padval & mask;
3556            if maskedval != 0 {
3557                return Err(fidl::Error::NonZeroPadding {
3558                    padding_start: offset + 24 + ((mask as u64).trailing_zeros() / 8) as usize,
3559                });
3560            }
3561            fidl::decode!(
3562                fidl_fuchsia_hardware_usb_descriptor::EndpointDirection,
3563                fidl::encoding::DefaultFuchsiaResourceDialect,
3564                &mut self.direction,
3565                decoder,
3566                offset + 0,
3567                _depth
3568            )?;
3569            fidl::decode!(
3570                fidl::encoding::Endpoint<
3571                    fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
3572                >,
3573                fidl::encoding::DefaultFuchsiaResourceDialect,
3574                &mut self.endpoint,
3575                decoder,
3576                offset + 4,
3577                _depth
3578            )?;
3579            fidl::decode!(
3580                fidl_fuchsia_hardware_usb_endpoint::EndpointInfo,
3581                fidl::encoding::DefaultFuchsiaResourceDialect,
3582                &mut self.ep_info,
3583                decoder,
3584                offset + 8,
3585                _depth
3586            )?;
3587            fidl::decode!(
3588                u32,
3589                fidl::encoding::DefaultFuchsiaResourceDialect,
3590                &mut self.max_packet_size,
3591                decoder,
3592                offset + 24,
3593                _depth
3594            )?;
3595            Ok(())
3596        }
3597    }
3598
3599    impl fidl::encoding::ResourceTypeMarker for UsbFunctionAllocResourcesRequest {
3600        type Borrowed<'a> = &'a mut Self;
3601        fn take_or_borrow<'a>(
3602            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
3603        ) -> Self::Borrowed<'a> {
3604            value
3605        }
3606    }
3607
3608    unsafe impl fidl::encoding::TypeMarker for UsbFunctionAllocResourcesRequest {
3609        type Owned = Self;
3610
3611        #[inline(always)]
3612        fn inline_align(_context: fidl::encoding::Context) -> usize {
3613            8
3614        }
3615
3616        #[inline(always)]
3617        fn inline_size(_context: fidl::encoding::Context) -> usize {
3618            40
3619        }
3620    }
3621
3622    unsafe impl
3623        fidl::encoding::Encode<
3624            UsbFunctionAllocResourcesRequest,
3625            fidl::encoding::DefaultFuchsiaResourceDialect,
3626        > for &mut UsbFunctionAllocResourcesRequest
3627    {
3628        #[inline]
3629        unsafe fn encode(
3630            self,
3631            encoder: &mut fidl::encoding::Encoder<
3632                '_,
3633                fidl::encoding::DefaultFuchsiaResourceDialect,
3634            >,
3635            offset: usize,
3636            _depth: fidl::encoding::Depth,
3637        ) -> fidl::Result<()> {
3638            encoder.debug_check_bounds::<UsbFunctionAllocResourcesRequest>(offset);
3639            // Delegate to tuple encoding.
3640            fidl::encoding::Encode::<UsbFunctionAllocResourcesRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
3641                (
3642                    <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.interface_count),
3643                    <fidl::encoding::Vector<EndpointResource, 255> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.endpoints),
3644                    <fidl::encoding::Vector<fidl::encoding::BoundedString<126>, 255> as fidl::encoding::ValueTypeMarker>::borrow(&self.strings),
3645                ),
3646                encoder, offset, _depth
3647            )
3648        }
3649    }
3650    unsafe impl<
3651        T0: fidl::encoding::Encode<u8, fidl::encoding::DefaultFuchsiaResourceDialect>,
3652        T1: fidl::encoding::Encode<
3653                fidl::encoding::Vector<EndpointResource, 255>,
3654                fidl::encoding::DefaultFuchsiaResourceDialect,
3655            >,
3656        T2: fidl::encoding::Encode<
3657                fidl::encoding::Vector<fidl::encoding::BoundedString<126>, 255>,
3658                fidl::encoding::DefaultFuchsiaResourceDialect,
3659            >,
3660    >
3661        fidl::encoding::Encode<
3662            UsbFunctionAllocResourcesRequest,
3663            fidl::encoding::DefaultFuchsiaResourceDialect,
3664        > for (T0, T1, T2)
3665    {
3666        #[inline]
3667        unsafe fn encode(
3668            self,
3669            encoder: &mut fidl::encoding::Encoder<
3670                '_,
3671                fidl::encoding::DefaultFuchsiaResourceDialect,
3672            >,
3673            offset: usize,
3674            depth: fidl::encoding::Depth,
3675        ) -> fidl::Result<()> {
3676            encoder.debug_check_bounds::<UsbFunctionAllocResourcesRequest>(offset);
3677            // Zero out padding regions. There's no need to apply masks
3678            // because the unmasked parts will be overwritten by fields.
3679            unsafe {
3680                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
3681                (ptr as *mut u64).write_unaligned(0);
3682            }
3683            // Write the fields.
3684            self.0.encode(encoder, offset + 0, depth)?;
3685            self.1.encode(encoder, offset + 8, depth)?;
3686            self.2.encode(encoder, offset + 24, depth)?;
3687            Ok(())
3688        }
3689    }
3690
3691    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
3692        for UsbFunctionAllocResourcesRequest
3693    {
3694        #[inline(always)]
3695        fn new_empty() -> Self {
3696            Self {
3697                interface_count: fidl::new_empty!(
3698                    u8,
3699                    fidl::encoding::DefaultFuchsiaResourceDialect
3700                ),
3701                endpoints: fidl::new_empty!(fidl::encoding::Vector<EndpointResource, 255>, fidl::encoding::DefaultFuchsiaResourceDialect),
3702                strings: fidl::new_empty!(
3703                    fidl::encoding::Vector<fidl::encoding::BoundedString<126>, 255>,
3704                    fidl::encoding::DefaultFuchsiaResourceDialect
3705                ),
3706            }
3707        }
3708
3709        #[inline]
3710        unsafe fn decode(
3711            &mut self,
3712            decoder: &mut fidl::encoding::Decoder<
3713                '_,
3714                fidl::encoding::DefaultFuchsiaResourceDialect,
3715            >,
3716            offset: usize,
3717            _depth: fidl::encoding::Depth,
3718        ) -> fidl::Result<()> {
3719            decoder.debug_check_bounds::<Self>(offset);
3720            // Verify that padding bytes are zero.
3721            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
3722            let padval = unsafe { (ptr as *const u64).read_unaligned() };
3723            let mask = 0xffffffffffffff00u64;
3724            let maskedval = padval & mask;
3725            if maskedval != 0 {
3726                return Err(fidl::Error::NonZeroPadding {
3727                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
3728                });
3729            }
3730            fidl::decode!(
3731                u8,
3732                fidl::encoding::DefaultFuchsiaResourceDialect,
3733                &mut self.interface_count,
3734                decoder,
3735                offset + 0,
3736                _depth
3737            )?;
3738            fidl::decode!(fidl::encoding::Vector<EndpointResource, 255>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.endpoints, decoder, offset + 8, _depth)?;
3739            fidl::decode!(
3740                fidl::encoding::Vector<fidl::encoding::BoundedString<126>, 255>,
3741                fidl::encoding::DefaultFuchsiaResourceDialect,
3742                &mut self.strings,
3743                decoder,
3744                offset + 24,
3745                _depth
3746            )?;
3747            Ok(())
3748        }
3749    }
3750
3751    impl fidl::encoding::ResourceTypeMarker for UsbFunctionConfigureRequest {
3752        type Borrowed<'a> = &'a mut Self;
3753        fn take_or_borrow<'a>(
3754            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
3755        ) -> Self::Borrowed<'a> {
3756            value
3757        }
3758    }
3759
3760    unsafe impl fidl::encoding::TypeMarker for UsbFunctionConfigureRequest {
3761        type Owned = Self;
3762
3763        #[inline(always)]
3764        fn inline_align(_context: fidl::encoding::Context) -> usize {
3765            8
3766        }
3767
3768        #[inline(always)]
3769        fn inline_size(_context: fidl::encoding::Context) -> usize {
3770            24
3771        }
3772    }
3773
3774    unsafe impl
3775        fidl::encoding::Encode<
3776            UsbFunctionConfigureRequest,
3777            fidl::encoding::DefaultFuchsiaResourceDialect,
3778        > for &mut UsbFunctionConfigureRequest
3779    {
3780        #[inline]
3781        unsafe fn encode(
3782            self,
3783            encoder: &mut fidl::encoding::Encoder<
3784                '_,
3785                fidl::encoding::DefaultFuchsiaResourceDialect,
3786            >,
3787            offset: usize,
3788            _depth: fidl::encoding::Depth,
3789        ) -> fidl::Result<()> {
3790            encoder.debug_check_bounds::<UsbFunctionConfigureRequest>(offset);
3791            // Delegate to tuple encoding.
3792            fidl::encoding::Encode::<
3793                UsbFunctionConfigureRequest,
3794                fidl::encoding::DefaultFuchsiaResourceDialect,
3795            >::encode(
3796                (
3797                    <fidl::encoding::Vector<u8, 32768> as fidl::encoding::ValueTypeMarker>::borrow(
3798                        &self.configuration,
3799                    ),
3800                    <fidl::encoding::Endpoint<
3801                        fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>,
3802                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
3803                        &mut self.iface
3804                    ),
3805                ),
3806                encoder,
3807                offset,
3808                _depth,
3809            )
3810        }
3811    }
3812    unsafe impl<
3813        T0: fidl::encoding::Encode<
3814                fidl::encoding::Vector<u8, 32768>,
3815                fidl::encoding::DefaultFuchsiaResourceDialect,
3816            >,
3817        T1: fidl::encoding::Encode<
3818                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>>,
3819                fidl::encoding::DefaultFuchsiaResourceDialect,
3820            >,
3821    >
3822        fidl::encoding::Encode<
3823            UsbFunctionConfigureRequest,
3824            fidl::encoding::DefaultFuchsiaResourceDialect,
3825        > for (T0, T1)
3826    {
3827        #[inline]
3828        unsafe fn encode(
3829            self,
3830            encoder: &mut fidl::encoding::Encoder<
3831                '_,
3832                fidl::encoding::DefaultFuchsiaResourceDialect,
3833            >,
3834            offset: usize,
3835            depth: fidl::encoding::Depth,
3836        ) -> fidl::Result<()> {
3837            encoder.debug_check_bounds::<UsbFunctionConfigureRequest>(offset);
3838            // Zero out padding regions. There's no need to apply masks
3839            // because the unmasked parts will be overwritten by fields.
3840            unsafe {
3841                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
3842                (ptr as *mut u64).write_unaligned(0);
3843            }
3844            // Write the fields.
3845            self.0.encode(encoder, offset + 0, depth)?;
3846            self.1.encode(encoder, offset + 16, depth)?;
3847            Ok(())
3848        }
3849    }
3850
3851    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
3852        for UsbFunctionConfigureRequest
3853    {
3854        #[inline(always)]
3855        fn new_empty() -> Self {
3856            Self {
3857                configuration: fidl::new_empty!(fidl::encoding::Vector<u8, 32768>, fidl::encoding::DefaultFuchsiaResourceDialect),
3858                iface: fidl::new_empty!(
3859                    fidl::encoding::Endpoint<
3860                        fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>,
3861                    >,
3862                    fidl::encoding::DefaultFuchsiaResourceDialect
3863                ),
3864            }
3865        }
3866
3867        #[inline]
3868        unsafe fn decode(
3869            &mut self,
3870            decoder: &mut fidl::encoding::Decoder<
3871                '_,
3872                fidl::encoding::DefaultFuchsiaResourceDialect,
3873            >,
3874            offset: usize,
3875            _depth: fidl::encoding::Depth,
3876        ) -> fidl::Result<()> {
3877            decoder.debug_check_bounds::<Self>(offset);
3878            // Verify that padding bytes are zero.
3879            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
3880            let padval = unsafe { (ptr as *const u64).read_unaligned() };
3881            let mask = 0xffffffff00000000u64;
3882            let maskedval = padval & mask;
3883            if maskedval != 0 {
3884                return Err(fidl::Error::NonZeroPadding {
3885                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
3886                });
3887            }
3888            fidl::decode!(fidl::encoding::Vector<u8, 32768>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.configuration, decoder, offset + 0, _depth)?;
3889            fidl::decode!(
3890                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<UsbFunctionInterfaceMarker>>,
3891                fidl::encoding::DefaultFuchsiaResourceDialect,
3892                &mut self.iface,
3893                decoder,
3894                offset + 16,
3895                _depth
3896            )?;
3897            Ok(())
3898        }
3899    }
3900
3901    impl fidl::encoding::ResourceTypeMarker for UsbFunctionConnectToEndpointRequest {
3902        type Borrowed<'a> = &'a mut Self;
3903        fn take_or_borrow<'a>(
3904            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
3905        ) -> Self::Borrowed<'a> {
3906            value
3907        }
3908    }
3909
3910    unsafe impl fidl::encoding::TypeMarker for UsbFunctionConnectToEndpointRequest {
3911        type Owned = Self;
3912
3913        #[inline(always)]
3914        fn inline_align(_context: fidl::encoding::Context) -> usize {
3915            4
3916        }
3917
3918        #[inline(always)]
3919        fn inline_size(_context: fidl::encoding::Context) -> usize {
3920            8
3921        }
3922    }
3923
3924    unsafe impl
3925        fidl::encoding::Encode<
3926            UsbFunctionConnectToEndpointRequest,
3927            fidl::encoding::DefaultFuchsiaResourceDialect,
3928        > for &mut UsbFunctionConnectToEndpointRequest
3929    {
3930        #[inline]
3931        unsafe fn encode(
3932            self,
3933            encoder: &mut fidl::encoding::Encoder<
3934                '_,
3935                fidl::encoding::DefaultFuchsiaResourceDialect,
3936            >,
3937            offset: usize,
3938            _depth: fidl::encoding::Depth,
3939        ) -> fidl::Result<()> {
3940            encoder.debug_check_bounds::<UsbFunctionConnectToEndpointRequest>(offset);
3941            // Delegate to tuple encoding.
3942            fidl::encoding::Encode::<
3943                UsbFunctionConnectToEndpointRequest,
3944                fidl::encoding::DefaultFuchsiaResourceDialect,
3945            >::encode(
3946                (
3947                    <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.ep_addr),
3948                    <fidl::encoding::Endpoint<
3949                        fidl::endpoints::ServerEnd<
3950                            fidl_fuchsia_hardware_usb_endpoint::EndpointMarker,
3951                        >,
3952                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
3953                        &mut self.ep
3954                    ),
3955                ),
3956                encoder,
3957                offset,
3958                _depth,
3959            )
3960        }
3961    }
3962    unsafe impl<
3963        T0: fidl::encoding::Encode<u8, fidl::encoding::DefaultFuchsiaResourceDialect>,
3964        T1: fidl::encoding::Encode<
3965                fidl::encoding::Endpoint<
3966                    fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
3967                >,
3968                fidl::encoding::DefaultFuchsiaResourceDialect,
3969            >,
3970    >
3971        fidl::encoding::Encode<
3972            UsbFunctionConnectToEndpointRequest,
3973            fidl::encoding::DefaultFuchsiaResourceDialect,
3974        > for (T0, T1)
3975    {
3976        #[inline]
3977        unsafe fn encode(
3978            self,
3979            encoder: &mut fidl::encoding::Encoder<
3980                '_,
3981                fidl::encoding::DefaultFuchsiaResourceDialect,
3982            >,
3983            offset: usize,
3984            depth: fidl::encoding::Depth,
3985        ) -> fidl::Result<()> {
3986            encoder.debug_check_bounds::<UsbFunctionConnectToEndpointRequest>(offset);
3987            // Zero out padding regions. There's no need to apply masks
3988            // because the unmasked parts will be overwritten by fields.
3989            unsafe {
3990                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
3991                (ptr as *mut u32).write_unaligned(0);
3992            }
3993            // Write the fields.
3994            self.0.encode(encoder, offset + 0, depth)?;
3995            self.1.encode(encoder, offset + 4, depth)?;
3996            Ok(())
3997        }
3998    }
3999
4000    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
4001        for UsbFunctionConnectToEndpointRequest
4002    {
4003        #[inline(always)]
4004        fn new_empty() -> Self {
4005            Self {
4006                ep_addr: fidl::new_empty!(u8, fidl::encoding::DefaultFuchsiaResourceDialect),
4007                ep: fidl::new_empty!(
4008                    fidl::encoding::Endpoint<
4009                        fidl::endpoints::ServerEnd<
4010                            fidl_fuchsia_hardware_usb_endpoint::EndpointMarker,
4011                        >,
4012                    >,
4013                    fidl::encoding::DefaultFuchsiaResourceDialect
4014                ),
4015            }
4016        }
4017
4018        #[inline]
4019        unsafe fn decode(
4020            &mut self,
4021            decoder: &mut fidl::encoding::Decoder<
4022                '_,
4023                fidl::encoding::DefaultFuchsiaResourceDialect,
4024            >,
4025            offset: usize,
4026            _depth: fidl::encoding::Depth,
4027        ) -> fidl::Result<()> {
4028            decoder.debug_check_bounds::<Self>(offset);
4029            // Verify that padding bytes are zero.
4030            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
4031            let padval = unsafe { (ptr as *const u32).read_unaligned() };
4032            let mask = 0xffffff00u32;
4033            let maskedval = padval & mask;
4034            if maskedval != 0 {
4035                return Err(fidl::Error::NonZeroPadding {
4036                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
4037                });
4038            }
4039            fidl::decode!(
4040                u8,
4041                fidl::encoding::DefaultFuchsiaResourceDialect,
4042                &mut self.ep_addr,
4043                decoder,
4044                offset + 0,
4045                _depth
4046            )?;
4047            fidl::decode!(
4048                fidl::encoding::Endpoint<
4049                    fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_usb_endpoint::EndpointMarker>,
4050                >,
4051                fidl::encoding::DefaultFuchsiaResourceDialect,
4052                &mut self.ep,
4053                decoder,
4054                offset + 4,
4055                _depth
4056            )?;
4057            Ok(())
4058        }
4059    }
4060}