octets: add generic Huffman encoding writer#2502
Open
ghedo wants to merge 2 commits into
Open
Conversation
LPardue
reviewed
Jun 4, 2026
Move the public API tests out of src/lib.rs into octets/tests so the crate code no longer carries a large inline test module. Keep the Huffman-specific coverage in its own feature-gated test file.
jrouviere
reviewed
Jun 4, 2026
| pending -= 64; | ||
| // Take only the bits that fit. | ||
| bits |= code >> pending; | ||
| write(&bits.to_be_bytes())?; |
Contributor
There was a problem hiding this comment.
I'm guessing that the write function needs to be retryable safely?
For instance it's not ok to write directly to the network with it, since huffman_encode_with might fail after writing some partial data.
Member
Author
There was a problem hiding this comment.
Yeah, basically the same assumption (the underlying sink has enough capacity) applies, so either an error is returned or there needs to be some buffering within the writer itself.
Contributor
There was a problem hiding this comment.
Sounds good. Might be worth mentioning explicitly in the docs, otherwise I feel like that could be a footgun.
Users might be tempted to write a sink that eagerly sends on the network, but the sink cannot return an error in that case.
Move HPACK Huffman output behind a small writer trait so callers can reuse the encoder with sinks other than OctetsMut. Keep the existing OctetsMut API by delegating through the trait implementation and add tests for custom sink output and error propagation. This makes the encoder useful for streaming or segmented output where building one contiguous temporary buffer would be unnecessary (e.g. for HTTP/2 HEADERS+CONTINUATION frames).
6b3fac6 to
7de8df7
Compare
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.
Move HPACK Huffman output behind a small writer trait so callers can reuse the encoder with sinks other than OctetsMut. Keep the existing OctetsMut API by delegating through the trait implementation and add tests for custom sink output and error propagation.
This makes the encoder useful for streaming or segmented output where building one contiguous temporary buffer would be unnecessary (e.g. for HTTP/2 HEADERS+CONTINUATION frames).