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.
45use fidl_next_codec::{
6 Decode, DecodeError, Encodable, Encode, EncodeError, Slot, WireU32, WireU64, ZeroPadding,
7};
89use zerocopy::IntoBytes;
1011/// A FIDL protocol message header
12#[derive(Clone, Copy, Debug, IntoBytes)]
13#[repr(C)]
14pub struct WireMessageHeader {
15/// The transaction ID of the message header
16pub txid: WireU32,
17/// Flags
18pub flags: [u8; 3],
19/// Magic number
20pub magic_number: u8,
21/// The ordinal of the message following this header
22pub ordinal: WireU64,
23}
2425unsafe impl ZeroPadding for WireMessageHeader {
26#[inline]
27unsafe fn zero_padding(_: *mut Self) {
28// Wire message headers have no padding
29}
30}
3132/// The flag 0 bit indicating that the wire format is v2.
33pub const FLAG_0_WIRE_FORMAT_V2_BIT: u8 = 0b0000_0010;
3435/// The magic number indicating FIDL protocol compatibility.
36pub const MAGIC_NUMBER: u8 = 0x01;
3738impl Encodable for WireMessageHeader {
39type Encoded = WireMessageHeader;
40}
4142impl<E: ?Sized> Encode<E> for WireMessageHeader {
43#[inline]
44fn encode(&mut self, _: &mut E, mut slot: Slot<'_, Self::Encoded>) -> Result<(), EncodeError> {
45 slot.write(*self);
46Ok(())
47 }
48}
4950unsafe impl<D: ?Sized> Decode<D> for WireMessageHeader {
51#[inline]
52fn decode(_: Slot<'_, Self>, _: &mut D) -> Result<(), DecodeError> {
53Ok(())
54 }
55}