Skip to content

feat(c-api): #28 Phase 6.2 — advanced + streaming + dictionary C FFI surface #127

Description

@polaz

Progress

Landed via the C ABI core + CDict work (PRs #386, #387): ZSTD_createCDict / ZSTD_createCDict_byReference / ZSTD_freeCDict / ZSTD_sizeof_CDict / ZSTD_compress_usingCDict / ZSTD_getDictID_fromCDict, the full DDict mirror, and the simple/context/frame/error surface (39 symbols total). Remaining in this issue: the advanced parameter API (ZSTD_CCtx_setParameter family, ZSTD_compress2, ZSTD_compressStream2, estimates), the streaming ZSTD_CStream/ZSTD_DStream surface, and the _advanced dictionary variants + *_usingDict one-shots.

Summary

Phase 6.2 of #28: complete the v1.5.7 advanced/streaming/dictionary C API surface on top of the FFI foundation from #126 (Phase 6.1). After this issue lands, libzstd.so.1 produced by c-api/ is symbol-complete vs upstream v1.5.7 except for multi-threaded compression (Phase 6.4 / #64) and legacy decoders (Phase 6.5/6.6 / #65/#66).

Deliverables

1. Advanced parameter API (ZSTD_CCtx_setParameter family)

Requires #27 (configurable parameters API) to be merged first — that issue exposes the Rust-side parameter struct this FFI layer wraps.

Wrappers:

  • ZSTD_CCtx_setParameter, ZSTD_CCtx_getParameter, ZSTD_CCtx_setPledgedSrcSize
  • ZSTD_DCtx_setParameter, ZSTD_DCtx_getParameter
  • ZSTD_cParam_getBounds, ZSTD_dParam_getBounds
  • ZSTD_CCtx_reset, ZSTD_DCtx_reset
  • ZSTD_compress2, ZSTD_compressStream2
  • ZSTD_estimateCCtxSize, ZSTD_estimateDCtxSize, ZSTD_estimateCCtxSize_usingCParams, ZSTD_estimateCStreamSize, ZSTD_estimateDStreamSize

Parameter enum (ZSTD_cParameter, ZSTD_dParameter) covers all v1.5.7 entries:

2. Streaming API

ZSTD_CStream / ZSTD_DStream are aliases for ZSTD_CCtx / ZSTD_DCtx per v1.5.x design. The streaming functions ride on top of the same opaque contexts.

Wrappers:

  • ZSTD_createCStream, ZSTD_freeCStream, ZSTD_initCStream, ZSTD_compressStream, ZSTD_flushStream, ZSTD_endStream, ZSTD_CStreamInSize, ZSTD_CStreamOutSize
  • ZSTD_createDStream, ZSTD_freeDStream, ZSTD_initDStream, ZSTD_decompressStream, ZSTD_DStreamInSize, ZSTD_DStreamOutSize
  • ZSTD_inBuffer / ZSTD_outBuffer structs are #[repr(C)] aliases of our streaming buffer types.

3. Dictionary API

Compression-side (ZSTD_CDict):

  • ZSTD_createCDict, ZSTD_createCDict_byReference, ZSTD_createCDict_advanced
  • ZSTD_freeCDict, ZSTD_sizeof_CDict
  • ZSTD_compress_usingCDict, ZSTD_compress_usingCDict_advanced
  • ZSTD_CCtx_loadDictionary, ZSTD_CCtx_loadDictionary_byReference, ZSTD_CCtx_loadDictionary_advanced
  • ZSTD_CCtx_refCDict, ZSTD_CCtx_refPrefix, ZSTD_CCtx_refPrefix_advanced

Decompression-side (ZSTD_DDict):

  • ZSTD_createDDict, ZSTD_createDDict_byReference, ZSTD_createDDict_advanced
  • ZSTD_freeDDict, ZSTD_sizeof_DDict
  • ZSTD_decompress_usingDDict
  • ZSTD_DCtx_loadDictionary, ZSTD_DCtx_refDDict, ZSTD_DCtx_refPrefix
  • ZSTD_getDictID_fromCDict, ZSTD_getDictID_fromDDict, ZSTD_getDictID_fromDict, ZSTD_getDictID_fromFrame

zdict.h training API:

  • ZDICT_trainFromBuffer
  • ZDICT_optimizeTrainFromBuffer_fastCover
  • ZDICT_trainFromBuffer_fastCover
  • ZDICT_finalizeDictionary
  • ZDICT_isError, ZDICT_getErrorName
  • ZDICT_getDictHeaderSize, ZDICT_getDictID

4. ABI invariants

  • ZSTD_inBuffer / ZSTD_outBuffer size_of snapshots match upstream sizeof(ZSTD_inBuffer) (= 24 bytes on 64-bit per upstream zstd.h).
  • ZSTD_cParameter / ZSTD_dParameter enum discriminants match upstream numeric values byte-for-byte (asserted via the vendored header diff in feat(c-api): #28 Phase 6.1 — C ABI core (cdylib + vendored headers + simple/context/error wrappers) #126 plus static_assertions in abi.rs).
  • Streaming ZSTD_CStreamInSize() / ZSTD_CStreamOutSize() return the same values upstream does (matches ZSTD_BLOCKSIZE_MAX).

Out of scope

Acceptance criteria

Estimate

~10-12 working days (~60 wrappers including ABI tests).

Blocked by

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumMedium priority — important improvementenhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions