coordinode-lsm-tree 5.0.0

Embedded LSM-tree storage engine: BuRR filters, zstd dictionary compression, MVCC, range tombstones, merge operators, K/V separation, AES-256-GCM at rest.
Documentation
// Copyright (c) 2025-present, fjall-rs
// This source code is licensed under both the Apache 2.0 and MIT License
// (found in the LICENSE-* files in the repository)

use crate::sfa::checksum::Checksum;
use byteorder::WriteBytesExt;

pub const TRAILER_MAGIC: &[u8] = b"SFA!";

pub struct TrailerWriter;

impl TrailerWriter {
    pub fn write_into<W: std::io::Write>(
        mut writer: W,
        toc_checksum: Checksum,
        toc_pos: u64,
        toc_len: u64,
    ) -> crate::sfa::Result<()> {
        use byteorder::LE;

        log::trace!("Writing trailer");

        writer.write_all(TRAILER_MAGIC)?;
        writer.write_u8(0x1)?; // Version
        writer.write_u8(0x0)?; // Checksum type, xxh3 = 0x0
        writer.write_u128::<LE>(toc_checksum.into_u128())?;
        writer.write_u64::<LE>(toc_pos)?;
        writer.write_u64::<LE>(toc_len)?;

        Ok(())
    }
}