Repository navigation
feat: add zstd and lz4 per-token compression codecs - #3028
Merged
Merged
Conversation
…atch Split the monolithic CompressedTokenEncoder/Decoder into a layered architecture: ZlibTokenEncoder/Decoder in zlib_codec.rs contain the zlib-specific compression logic, while encoder.rs/decoder.rs become thin enum wrappers that dispatch to the active codec. This prepares for adding zstd and lz4 per-token codecs as additional enum variants. The public API is unchanged - all existing call sites continue to work without modification. upstream: token.c uses a similar dispatch pattern with CPRES_ZLIB/CPRES_ZLIBX/CPRES_ZSTD/CPRES_LZ4 enum.
Add ZstdTokenEncoder/ZstdTokenDecoder (feature-gated on `zstd`) and Lz4TokenEncoder/Lz4TokenDecoder (feature-gated on `lz4`) implementing the per-token compression wire format matching upstream rsync's CPRES_ZSTD and CPRES_LZ4 modes. Key differences from zlib: - Zstd: persistent ZSTD_CCtx/DCtx, ZSTD_e_flush at boundaries, no sync marker stripping, see_token is noop - LZ4: stateless per-chunk compression via LZ4_compress_default, retry with halved input if output exceeds MAX_DATA_COUNT, see_token is noop Both codecs share the same wire framing (DEFLATED_DATA headers, token run encoding) as zlib. The algorithm-agnostic encoder/decoder dispatch via enum variants with new_zstd()/new_lz4() constructors. upstream: token.c:send_zstd_token(), recv_zstd_token(), send_compressed_token(SUPPORT_LZ4), recv_compressed_token(SUPPORT_LZ4)
3 tasks
oferchen
added a commit
that referenced
this pull request
May 1, 2026
* refactor: extract zlib codec into dedicated module for algorithm dispatch Split the monolithic CompressedTokenEncoder/Decoder into a layered architecture: ZlibTokenEncoder/Decoder in zlib_codec.rs contain the zlib-specific compression logic, while encoder.rs/decoder.rs become thin enum wrappers that dispatch to the active codec. This prepares for adding zstd and lz4 per-token codecs as additional enum variants. The public API is unchanged - all existing call sites continue to work without modification. upstream: token.c uses a similar dispatch pattern with CPRES_ZLIB/CPRES_ZLIBX/CPRES_ZSTD/CPRES_LZ4 enum. * feat: add zstd and lz4 per-token compression codecs Add ZstdTokenEncoder/ZstdTokenDecoder (feature-gated on `zstd`) and Lz4TokenEncoder/Lz4TokenDecoder (feature-gated on `lz4`) implementing the per-token compression wire format matching upstream rsync's CPRES_ZSTD and CPRES_LZ4 modes. Key differences from zlib: - Zstd: persistent ZSTD_CCtx/DCtx, ZSTD_e_flush at boundaries, no sync marker stripping, see_token is noop - LZ4: stateless per-chunk compression via LZ4_compress_default, retry with halved input if output exceeds MAX_DATA_COUNT, see_token is noop Both codecs share the same wire framing (DEFLATED_DATA headers, token run encoding) as zlib. The algorithm-agnostic encoder/decoder dispatch via enum variants with new_zstd()/new_lz4() constructors. upstream: token.c:send_zstd_token(), recv_zstd_token(), send_compressed_token(SUPPORT_LZ4), recv_compressed_token(SUPPORT_LZ4)
oferchen
added a commit
that referenced
this pull request
May 5, 2026
* refactor: extract zlib codec into dedicated module for algorithm dispatch Split the monolithic CompressedTokenEncoder/Decoder into a layered architecture: ZlibTokenEncoder/Decoder in zlib_codec.rs contain the zlib-specific compression logic, while encoder.rs/decoder.rs become thin enum wrappers that dispatch to the active codec. This prepares for adding zstd and lz4 per-token codecs as additional enum variants. The public API is unchanged - all existing call sites continue to work without modification. upstream: token.c uses a similar dispatch pattern with CPRES_ZLIB/CPRES_ZLIBX/CPRES_ZSTD/CPRES_LZ4 enum. * feat: add zstd and lz4 per-token compression codecs Add ZstdTokenEncoder/ZstdTokenDecoder (feature-gated on `zstd`) and Lz4TokenEncoder/Lz4TokenDecoder (feature-gated on `lz4`) implementing the per-token compression wire format matching upstream rsync's CPRES_ZSTD and CPRES_LZ4 modes. Key differences from zlib: - Zstd: persistent ZSTD_CCtx/DCtx, ZSTD_e_flush at boundaries, no sync marker stripping, see_token is noop - LZ4: stateless per-chunk compression via LZ4_compress_default, retry with halved input if output exceeds MAX_DATA_COUNT, see_token is noop Both codecs share the same wire framing (DEFLATED_DATA headers, token run encoding) as zlib. The algorithm-agnostic encoder/decoder dispatch via enum variants with new_zstd()/new_lz4() constructors. upstream: token.c:send_zstd_token(), recv_zstd_token(), send_compressed_token(SUPPORT_LZ4), recv_compressed_token(SUPPORT_LZ4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
zlib_codec.rsmodule withpub(super)visibility for strategy pattern dispatchZstdTokenEncoder/ZstdTokenDecoder(feature-gated onzstd) implementing upstream'sCPRES_ZSTDmode with persistentZSTD_CCtx/ZSTD_DCtxandZSTD_e_flushat token boundariesLz4TokenEncoder/Lz4TokenDecoder(feature-gated onlz4) implementing upstream'sCPRES_LZ4mode with stateless per-chunkLZ4_compress_default/LZ4_decompress_safeCompressedTokenEncoder/CompressedTokenDecodervia enum dispatch withnew_zstd()/new_lz4()constructorsTest plan
--all-features,--features zstd,--features lz4, and default features (zlib only)