consensus_encoding: Refactor BytesEncoder, ScriptEncoder, SliceEncoder & ArrayEncoder#5104
Closed
jrakibi wants to merge 3 commits intorust-bitcoin:masterfrom
Closed
consensus_encoding: Refactor BytesEncoder, ScriptEncoder, SliceEncoder & ArrayEncoder#5104jrakibi wants to merge 3 commits intorust-bitcoin:masterfrom
jrakibi wants to merge 3 commits intorust-bitcoin:masterfrom
Conversation
This is the first step in simplifying the encoder API to use composition with CompactSizeEncoder. We remove with_length_prefix() and without_length_prefix() methods and replace with single new() constructor. We also pdate ScriptEncoder to use BytesEncoder::new() with composition
ArrayEncoder only has `without_length_prefix()`, so we can use the `new()` constructor directly to keep consistency with other encoders
remove `with_length_prefix()` method from SliceEncoder. and add `new()` constructor. If length prefix is needed, we can use composition with `CompactSizeEncoder` This completes the refactor to use composition-based length prefixing.
Member
|
Oh were we dancing on each others toes? |
Contributor
Author
Haha, I think so |
Member
|
I kinda wish we'd kept this one, which is fairly complete. Other than the name |
Member
|
I went back over this with fresh eyes after reading your comment and I now agree, reverting my previous belief. The usage of @jrakibi want to push these two changes up again? Sorry for my original hesitation on this. |
apoelstra
added a commit
that referenced
this pull request
Oct 10, 2025
63bbe12 Remove length prefix from SliceEncoder (Tobin C. Harding) Pull request description: Currently we hide the length prefix inside the `SliceEncoder`. While technically correct the usage of the `SliceEncoder` can be made more clear by forcing users to combine a compact size encoder and a slice encoder using an `Encoder2` instead of the current abstraction. Original idea from jrakibi in #5104. I gave you a co-developed-by tag mate. Pushing this up because I'm itching to get `primitives 1.0.0-rc.0` out. ACKs for top commit: apoelstra: ACK 63bbe12; successfully ran local tests Tree-SHA512: befe9b25a35644195834fdf0fec137d9250278416277409828cca2cd888ec69d4d29309f4fc761fe95790046131e58d743a724075c6b1092e86a564627bc3f67
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.
Refactor the encoder API by removing
with_length_prefix/without_length_prefixand replacing it with a singlenew()constructor across all encoders.Length prefixing is now handled through composition with
CompactSizeEncoder