Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: no-allocation hex-encoding using HexWriter #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

elsirion
Copy link

HexWriter allows to directly hex-encode binary data to a std::fmt::Write object from any source that can write to a std::io::Write object. This saves between one and two allocations depending on the use case.

Let's assume a function Foo::encode(&self, writer: std::io::Write) -> Result<(), std::io::Error>:

  • Writing a Foo object to Formatter as hex would require 2 allocations: one to encode bytes into a Vec<u8> and a second to encode the bytes into a String before writing it to the Formatter. Here we can save 2 allocations.
  • Writing a Foo struct as hex into a String, here we only save 1 allocation (the intermediate byte step)
  • Writing a Vec<u8> as hex to a Formatter: 1 allocation saved (String)

@elsirion
Copy link
Author

elsirion commented Mar 1, 2024

@dpc this project might be unmaintained, should we just publish a fork?

@dpc
Copy link

dpc commented Mar 1, 2024

@elsirion Rust Bitcoin has a separate hex crate now or something. Maybe we can just add it there. Maintaining creates is a lot of ungrateful work. 🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants