Skip to main content

fidl_next_codec/
chunk.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
5use crate::wire::Uint64;
6
7/// FIDL alignment, used for buffer alignment to ensure decoding in-place is
8/// possible.
9pub const CHUNK_SIZE: usize = 8;
10
11/// A group of eight bytes, aligned to an 8-byte boundary.
12pub type Chunk = Uint64;
13
14/// Returns an array of chunks with the same bytewise value as the given bytes.
15#[macro_export]
16macro_rules! chunks {
17    () => { [$crate::wire::Uint64(0); 0] };
18    ($(
19        $b0:literal, $b1:literal, $b2:literal, $b3:literal,
20        $b4:literal, $b5:literal, $b6:literal, $b7:literal
21    ),* $(,)?) => {
22        [
23            $($crate::wire::Uint64(u64::from_le_bytes([
24                $b0, $b1, $b2, $b3, $b4, $b5, $b6, $b7,
25            ])),)*
26        ]
27    };
28}