-
Notifications
You must be signed in to change notification settings - Fork 123
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
Use of ByteBuffer in Bufferable #192
Comments
Check out the com.twitter.io.Buf abstraction maybe? It needs a dependency On Wed, Dec 31, 2014, 20:30 P. Oscar Boykin [email protected]
|
Buf is not bad. Honestly, since we don't have anything like the ST monad here, I tend to think we should just own up to the fact that we are mutating the ByteBuffers/Arrays underlying any of these Buffers. Also, our goal is to use this in scalding, and I'm pretty reluctant to invite util into a diamond dependency with scalding. It's sad that the JVM module/dependency situation is what it is. |
Bufferable is a somewhat under used typeclass, but with macros, this could change. The idea was a composable binary serialization type that could be used in conjunction with Injections and Bijections which are often related.
The problem is ByteBuffer is mutable, and working with it is highly error prone. As a result, we do a lot of defensive copying.
We could instead have something like:
In this case, the underlying bytes array is clearly still mutable, but the pointer information around it is not. Maybe this is more confusing since there is the illusion of immutability but really the underlying object is mutable. If we come to this conclusion, perhaps we should change Bufferable from returning new ByteBuffers and have an explicit contract that it will mutate. If you don't want that, you call with
buf.duplicate
.The text was updated successfully, but these errors were encountered: