-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add more read_*
methods for big/little endian integers
#33
Comments
@dcsommer Borrowing this issue to advertise my crate which is extension to untrusted: https://crates.io/crates/untrustended It contains a trait to extend untrusted's There's also PR #14 to implement more methods directly into untrusted, but it's been slowly cooking do to lack of time. |
@oherrala thanks for the crate link. I noticed |
@dcsommer Yeah, you are right. I think I benchmarked the PR to be faster than |
I would hope that reading byte-by-byte wouldn't matter a huge amount. However, I imagine there is some performance impact and I think we should address that. Maybe we should have something like:
Where that would turn into basically a bounds check followed by a I think the above is not too terrible. I admit it isn't as nice as:
Although it's true that there are a lot of data formats that are just big- or little- endian encodings of bytes, I almost never write parsers for those formats. Usually some kind of unusual variable-length encoding is used in the formats I'm interested in. For example, ASN.1, QUIC, UTF-8, HPACK. Definitely we wouldn't put the decoding of all those formats into Further, what I've noticed in ring regarding simple endian-encoded values is that I usually want to read the next N bytes and get an |
A straightforward feature that would be quite useful for implementing network protocols would be additional methods on
Reader
for reading big and little endian integers. The API could be something like:Where
T
is some integer type. This is similar to the C++ library Cursor, from Folly and fits nicely at the level of pulling bytes safely from the buffer.The text was updated successfully, but these errors were encountered: