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

Support Write Interface For Bencode Encoding #131

Open
GGist opened this issue Oct 19, 2017 · 1 comment
Open

Support Write Interface For Bencode Encoding #131

GGist opened this issue Oct 19, 2017 · 1 comment

Comments

@GGist
Copy link
Owner

GGist commented Oct 19, 2017

Many times we have some data that we want to bencode right before we write out to the network (or right when we need to check what the size of the data on the wire will be...). Often times, we will have to encode to a buffer that the bip_bencode library allocates and hands back to us.

However, for most use cases (and at least for tokio), users will be using dedicated network buffers. What will happen is that they will encode to the Vec that we return, and then just copy the contents to the network buffer. Instead, we should support writing directly to types like this via Write.

An additional use case for this is determining how many bytes an encoded bencode structure will use before actually encoding. We can expose such a method, but internally calling the encode with a custom Write object that just keeps a counter of bytes written, and return that to the user. This would allow for a zero allocation method to determine the size.

@GGist GGist changed the title Support Writer Interface For Bencode Encoding Support Write Interface For Bencode Encoding Oct 19, 2017
@GGist
Copy link
Owner Author

GGist commented Oct 19, 2017

Update UtMetadata* messages to use this when available for things like caching the size of the bencode portion of the message.

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

No branches or pull requests

1 participant