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

Feature request: bytesRead, bytesWritten #8

Closed
hallettj opened this issue Oct 20, 2012 · 6 comments
Closed

Feature request: bytesRead, bytesWritten #8

hallettj opened this issue Oct 20, 2012 · 6 comments

Comments

@hallettj
Copy link

It would be helpful for me to have a bytesRead function, like the one in binary, that produces a count of the number of bytes that have been consumed from input. This would be useful for deserializing formats that refer to previous byte offsets in the input, such as DNS messages that contain compressed domain names.

A complementary bytesWritten function would also be helpful for writing such formats. I have not been able to find a bytesWritten feature in any serialization library that I have looked at.

Also, I want to say thank you for publishing such a useful library!

@elliottt
Copy link
Contributor

I'm glad that you're finding it a useful library :)

The easiest way to implement this would be some additional bookkeeping in the state of the Get monad, though I'm not sure what the performance implications of that would be. If you'd like to experiment, I'd be happy to accept a patch.

I like the idea of bytesWritten, and could see that being invaluable when rendering out data. We've been contemplating a rewrite of the Put monad, so this could be a good opportunity to add that in!

@hallettj
Copy link
Author

Thank you for the quick response.

I may submit a patch. I looked at the Get code earlier; but I was not sure if it would be better to add an argument to the Get type or to add another field to the Incomplete constructor of the More type.

In the meantime I have my own code set up using StateT to track a byte offset counter, which I am incrementing by hand. It works fine - but requires careful testing to make sure that my bookkeeping is correct. Which is some motivation for me to work on a patch.

@elliottt
Copy link
Contributor

I think that adding another field to the Result structure would probably be the way to go. I hadn't realized how close binary and cereal had gotten, so we could basically mirror their Decoder structure in our Result type.

@elliottt
Copy link
Contributor

(I'm closing this as it looks like you'll submit a pull request when this feature is ready :)

@relrod
Copy link

relrod commented Nov 23, 2014

@hallettj two years late, but have you come up with anything for this? I would like bytesRead as well (mostly so I can add it to ekmett/bytes for both Binary and Cereal). I might try to give it a go, but if you have something laying around, I don't want to duplicate effort.

Alternatively if @elliottt has any more advice on how to go about this, that would be useful ;) - not sure what all (if anything) has changed since the comments above, or if they still apply.

@elliottt
Copy link
Contributor

Not much has changed since my previous comments, and I think the recommendations still make sense. If you come up with something that works well, I'm happy to look it over :)

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

No branches or pull requests

3 participants