-
Notifications
You must be signed in to change notification settings - Fork 57
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
Export an eof
getter that spits out the remaining bytestring
#102
Comments
I'm looking at this sort of relation (pseudocode using my own definitions): bs :: B.ByteString -- for any bytestring, including empty
-- runPut bs == bs
-- runGet (runPut bs) == Right (bs, "") cereal doesn't provide the top law because it (correctly) serializes bytestrings with length prefixes. My library handles that in a different way, so I'd like provide a "bad" instance for |
What about combining |
A shortcut that doesn't do the counting or copying would still be nice (though maybe the copying is important?). getByteStringEOF :: Get B.ByteString
getByteStringEOF =
Get (\s b m w _ k -> k B.empty emptyBuffer m w (s `B.append` bufferBytes b)) |
The copying is important mainly so that you don't hold on to the entire input just to keep around the result of |
Yes, that would be useful! |
Thanks for cereal, I'm using it in a set of binary representation libraries with alternate typeclasses, and it's super handy.
I've found myself needing a dual to
Put.putByteString
for getters, where there's no length prefix, so all you can do is consume the whole remaining bytestring and spit it back out.Data.Serialize.Get
doesn't export some of the underlying types or helpers needed for writing this, so users aren't able to define it themselves (efficiently, anyway).I've forked and written something that apparently works, but I don't know how the buffer and other parts function.
Would it be useful to for
Data.Serialize.Get
to export something like this? It wouldn't be used in the typeclass-- or anywhere else, but it's convenient to piggyback off cereal's efficient internal parser rather than write my own.The text was updated successfully, but these errors were encountered: