use crate::{Key, UuidBytes, constants::CSUM_SIZE};
use num_enum::{IntoPrimitive, TryFromPrimitive};
use static_assertions::const_assert_eq;
use strum::EnumIter;
use zerocopy::little_endian::{U32 as U32LE, U64 as U64LE};
use zerocopy_derive::*;
#[derive(Clone, Debug, IntoBytes, TryFromBytes, Unaligned, KnownLayout)]
#[repr(C, packed)]
pub struct Header {
pub csum: [u8; CSUM_SIZE],
pub fs_uuid: UuidBytes,
pub logical_address: U64LE,
pub flags: [u8; 7],
pub backref_rev: BackrefRevision,
pub chunk_tree_uuid: UuidBytes,
pub generation: U64LE,
pub tree_id: U64LE,
pub num_items: U32LE,
pub level: u8,
}
const_assert_eq!(core::mem::size_of::<Header>(), 101);
#[derive(Copy, Clone, Debug, IntoBytes, FromBytes, Unaligned, KnownLayout)]
#[repr(C, packed)]
pub struct KeyPointer {
pub key: Key,
pub block_pointer: U64LE,
pub generation: U64LE,
}
const_assert_eq!(core::mem::size_of::<KeyPointer>(), 33);
#[derive(Copy, Clone, Debug, IntoBytes, FromBytes, Unaligned, KnownLayout)]
#[repr(C, packed)]
pub struct Item {
pub key: Key,
pub offset: U32LE,
pub size: U32LE,
}
const_assert_eq!(core::mem::size_of::<Item>(), 25);
#[derive(
Copy,
Clone,
Debug,
Hash,
PartialEq,
EnumIter,
IntoPrimitive,
TryFromPrimitive,
IntoBytes,
TryFromBytes,
Unaligned,
KnownLayout,
)]
#[repr(u8)]
pub enum BackrefRevision {
Old = 0,
Mixed = 1,
}
const_assert_eq!(core::mem::size_of::<BackrefRevision>(), 1);