refactor: migrate all encode/decode to stream-based APIs#66
Merged
Conversation
…eredReader API Replace the functional bytes-based encoding approach with a stream-based API using io.Writer (write) and io.BufferedReader (read). This eliminates O(n^2) byte concatenation and simplifies call sites. Changes: - All encode() methods now take io.Writer and return None - All decode() classmethods now take io.BufferedReader and return the value directly (no more tuple unwrapping) - Updated abstract base classes (Signature, PublicKey) - Updated crypto types (Hash, Address, BLS/Ed25519/Secp256k1 sig/pub) - Updated simple types (Height, Round, Amount) - Updated transaction payloads - Updated Transaction, Block, Header, Certificate - Updated all tests to match the new API - Fixed lint issues with ruff
Block.decode was the only remaining decode() method that took raw bytes and wrapped them internally. Now it takes io.BufferedReader directly, consistent with every other decode() in the codebase.
themantre
approved these changes
Jul 2, 2026
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.
Replace the functional bytes-based encoding approach with a stream-based
API using
io.Writer(write) andio.BufferedReader(read).Why
buf += dataon immutablebytesval, buf = read_uint8(buf)→val = read_uint8(buf)_read()helperWhat changed
encode()methods now takeio.Writerand returnNonedecode()classmethods now takeio.BufferedReaderand return the value directly (no more tuple unwrapping)Signature,PublicKey)Hash,Address, BLS/Ed25519/Secp256k1 sig/pub)Height,Round,Amount)Transaction,Block,Header,CertificateAmount