fidl_next_codec/fuchsia/
mod.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Fuchsia-specific extensions to the FIDL codec.
6
7mod channel;
8mod handle;
9
10use zx::sys::zx_handle_t;
11use zx::Handle;
12
13use crate::decoder::InternalHandleDecoder;
14use crate::encoder::InternalHandleEncoder;
15use crate::{DecodeError, EncodeError};
16
17pub use self::channel::*;
18pub use self::handle::*;
19pub use zx;
20
21/// A decoder which support Zircon handles.
22pub trait HandleDecoder: InternalHandleDecoder {
23    /// Takes the next raw handle from the decoder.
24    ///
25    /// The returned raw handle must not be considered owned until the decoder is committed.
26    fn take_raw_handle(&mut self) -> Result<zx_handle_t, DecodeError>;
27
28    /// Returns the number of handles remaining in the decoder.
29    fn handles_remaining(&mut self) -> usize;
30
31    /// Takes the next raw driver handle from the decoder.
32    #[doc(hidden)]
33    fn take_raw_driver_handle(&mut self) -> Result<u32, DecodeError> {
34        Err(DecodeError::DriverHandlesUnsupported)
35    }
36}
37
38/// An encoder which supports Zircon handles.
39pub trait HandleEncoder: InternalHandleEncoder {
40    /// Pushes a handle into the encoder.
41    fn push_handle(&mut self, handle: Handle) -> Result<(), EncodeError>;
42
43    /// Returns the number of handles added to the encoder.
44    fn handles_pushed(&self) -> usize;
45
46    /// Pushes a raw driver handle into the encoder.
47    #[doc(hidden)]
48    fn push_raw_driver_handle(&mut self, _raw_driver_handle: u32) -> Result<(), EncodeError> {
49        Err(EncodeError::DriverHandlesUnsupported)
50    }
51}