fidl_next/protocol/
wire.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2024 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use crate::{u32_le, u64_le, Decode, DecodeError, Encodable, Encode, EncodeError, IntoBytes, Slot};

/// A FIDL protocol message header
#[derive(Clone, Copy, Debug, IntoBytes)]
#[repr(C)]
pub struct WireMessageHeader {
    /// The transaction ID of the message header
    pub txid: u32_le,
    /// Flags
    pub flags: [u8; 3],
    /// Magic number
    pub magic_number: u8,
    /// The ordinal of the message following this header
    pub ordinal: u64_le,
}

/// The flag 0 bit indicating that the wire format is v2.
pub const FLAG_0_WIRE_FORMAT_V2_BIT: u8 = 0b0000_0010;

/// The magic number indicating FIDL protocol compatibility.
pub const MAGIC_NUMBER: u8 = 0x01;

impl Encodable for WireMessageHeader {
    type Encoded<'buf> = WireMessageHeader;
}

impl<E: ?Sized> Encode<E> for WireMessageHeader {
    #[inline]
    fn encode(
        &mut self,
        _: &mut E,
        mut slot: Slot<'_, Self::Encoded<'_>>,
    ) -> Result<(), EncodeError> {
        slot.write(*self);
        Ok(())
    }
}

unsafe impl<D: ?Sized> Decode<D> for WireMessageHeader {
    #[inline]
    fn decode(_: Slot<'_, Self>, _: &mut D) -> Result<(), DecodeError> {
        Ok(())
    }
}