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::Handle;
11
12use crate::decoder::InternalHandleDecoder;
13use crate::encoder::InternalHandleEncoder;
14use crate::{DecodeError, EncodeError};
15
16pub use self::channel::*;
17pub use self::handle::*;
18pub use zx;
19
20/// A decoder which support Zircon handles.
21pub trait HandleDecoder: InternalHandleDecoder {
22    /// Takes the next handle from the decoder.
23    fn take_handle(&mut self) -> Result<Handle, DecodeError>;
24
25    /// Returns the number of handles remaining in the decoder.
26    fn handles_remaining(&mut self) -> usize;
27
28    /// Takes the next raw driver handle from the decoder.
29    #[doc(hidden)]
30    fn take_raw_driver_handle(&mut self) -> Result<u32, DecodeError> {
31        Err(DecodeError::DriverHandlesUnsupported)
32    }
33}
34
35/// An encoder which supports Zircon handles.
36pub trait HandleEncoder: InternalHandleEncoder {
37    /// Pushes a handle into the encoder.
38    fn push_handle(&mut self, handle: Handle) -> Result<(), EncodeError>;
39
40    /// Returns the number of handles added to the encoder.
41    fn handles_pushed(&self) -> usize;
42
43    /// Pushes a raw driver handle into the encoder.
44    #[doc(hidden)]
45    fn push_raw_driver_handle(&mut self, _raw_driver_handle: u32) -> Result<(), EncodeError> {
46        Err(EncodeError::DriverHandlesUnsupported)
47    }
48}