feat(compress): move block header serialization to Rust

Keep the private writeBlockHeader signature and its debug logging in C while
moving the pure block-type, size, and 24-bit little-endian encoding behind a
narrow Rust ABI. The Rust leaf preserves the RLE blockSize path for cSize == 1
and the compressed cSize path for every other value.

Test Plan:
- `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression block_header -- --nocapture` -- passed
- `make -B -C lib -j2 lib` -- passed
- `make -C tests -j2 fuzzer` -- passed
- `./tests/fuzzer -s4560 -t47 -i48 -v` -- passed
- Required clippy, nightly fmt, and diff checks -- passed
This commit is contained in:
2026-07-18 08:52:42 +02:00
parent 9df7b55d8f
commit 934a589500
2 changed files with 47 additions and 4 deletions
+3 -4
View File
@@ -37,6 +37,8 @@ size_t ZSTD_rust_writeFrameHeader(void* dst, size_t dstCapacity,
int contentSizeFlag, int format,
U32 windowLog, U64 pledgedSrcSize,
U32 dictID);
void ZSTD_rust_writeBlockHeader(void* op, size_t cSize, size_t blockSize,
U32 lastBlock);
size_t ZSTD_rust_writeEpilogue(void* dst, size_t dstCapacity, int* stage,
int noDictIDFlag, int checksumFlag,
int contentSizeFlag, int format, U32 windowLog,
@@ -2592,10 +2594,7 @@ ZSTD_blockState_confirmRepcodesAndEntropyTables(ZSTD_blockState_t* const bs)
static void
writeBlockHeader(void* op, size_t cSize, size_t blockSize, U32 lastBlock)
{
U32 const cBlockHeader = cSize == 1 ?
lastBlock + (((U32)bt_rle)<<1) + (U32)(blockSize << 3) :
lastBlock + (((U32)bt_compressed)<<1) + (U32)(cSize << 3);
MEM_writeLE24(op, cBlockHeader);
ZSTD_rust_writeBlockHeader(op, cSize, blockSize, lastBlock);
DEBUGLOG(5, "writeBlockHeader: cSize: %zu blockSize: %zu lastBlock: %u", cSize, blockSize, lastBlock);
}