ImmutableByteArray?

651 views
Skip to first unread message

Dan Wyand

unread,
Jul 8, 2017, 12:23:54 PM7/8/17
to guava-discuss
What is the rationale for not including an ImmutableByteArray alongside Int, Long, and Double?

I fully understand not getting full coverage of the primitive types, and each one has to have its own implementation, but byte seems quite valuable to me. I do not know of a solution for an immutable, thread-safe chunk of binary data that would be better than an ImmutableByteArray.

There is obviously a cost for each primitive type array that gets implemented, but bytes seem particularly valuable to me. I think there are strong arguments against other primitive arrays:

- Booleans need implementation decisions (packed bits vs. element per value?) that may prevent a good one-size-fits-all implementation
- Char arrays may as well be strings
- Short and Float arrays carry a questionable value proposition over Int and Double

But, I can't come up with a reason to avoid bytes. Is there a place for immutable byte arrays in 23? Is there another structure I'm not thinking of that covers the immutable binary data use case?

Pat Farrell

unread,
Jul 8, 2017, 1:31:41 PM7/8/17
to Dan Wyand, guava-discuss
On Sat, Jul 8, 2017 at 12:23 PM, Dan Wyand <danw...@gmail.com> wrote:
What is the rationale for not including an ImmutableByteArray alongside Int, Long, and Double?

I don't know, but when you talk about byte, what exactly do you mean? Signed or unsigned?

In the networking world RFC's they avoid the confusion by talking about octets, which are by definition, 8 bits unsigned.
 

Louis Wasserman

unread,
Jul 8, 2017, 1:42:50 PM7/8/17
to Dan Wyand, guava-discuss
Bytes tend to be associated with I/O in a way that other primitives aren't.  Inside Google, we generally use https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/ByteString, which has many more features for those purposes than the ImmutableXyzArray types in Guava.

--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
 
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/2a187bc6-6a42-4c24-841a-a6cfd85e6373%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Benjamin Manes

unread,
Jul 8, 2017, 2:03:40 PM7/8/17
to Dan Wyand, Louis Wasserman, guava-discuss
Reply all
Reply to author
Forward
0 new messages