No reason to re-implement all that stuff yourself....
# announcements
d
No reason to re-implement all that stuff yourself. There are good solutions for reading primitive values from a byte stream. NIO `ByteBuffer`s are one, there is
ByteArrayDataInput
from Guava, etc.
m
About Guava, Are there real benefits using unsignedBytes instead of simply promoting byte to int? I've to work with a lot of unsigned values
d
Well, there is a difference.
0xFF.toByte().toInt() == -1
But
UnsignedBytes.toInt(UnsignedBytes.checkedCast(0xFF)) == 255
.
m
Well, 0xFF.toByte().toInt() and 0xFF == 255
d
No,
0xFF.toByte().toInt() == -1
.
m
Yes, but You've to add a bitwise AND
d
Yes, which is what
UnsignedBytes
does.