Closed GoogleCodeExporter closed 9 years ago
How much mileage could you get out of simply using int? What are the edge cases
this would leave uncovered?
Original comment by fry@google.com
on 28 Jul 2011 at 5:36
You can't always use an int. In my case, I'm given a ByteBuffer full of bytes
read from a serial port. I need to read a 16-bit unsigned short from the
buffer. The only two methods available to me are ByteBuffer.getShort() and
ByteBuffer.get(byte[]).
If I had UnsignedShorts I'd simply invoke:
UnsignedShorts.toInt(ByteBuffer.getShort())
Original comment by cow...@bbs.darktech.org
on 8 Aug 2011 at 6:34
Here is a quick attempt at transforming UnsignedBytes to UnsignedShorts. I
replaced "byte" by "short" and 127 with 65535, etc.
Original comment by cow...@bbs.darktech.org
on 8 Aug 2011 at 7:13
Attachments:
I've been using the proposed patch for over a month now without any problems.
My only complaint is that there doesn't seem to be a way to suppress this
compiler error:
com/google/common/primitives/UnsignedShorts.java:[24,15] Unsafe is internal
proprietary API and may be removed in a future release
Original comment by cow...@bbs.darktech.org
on 9 Sep 2011 at 2:16
We're providing support for unsigned ints and longs, but shorts...I'm not sure
they're used enough to be worth it.
Original comment by wasserman.louis
on 29 Sep 2011 at 10:08
Louis,
Our company uses CRC-16 for embedded devices we develop. If you Google "CRC-16"
you will find that it brings up marginally less hits than "CRC-32" so I think
it's fair to say that it's a fairly common use-case (at least in the embedded
world). Besides, if you're already adding unsigned byte, int, and long support
you might as well add unsigned short support for completeness sake. And there's
also the fact that I've already provided a patch ;)
Original comment by cow...@bbs.darktech.org
on 30 Sep 2011 at 3:51
"Completeness' sake" is...a dangerous phrase. (There have been things that I
personally added to Guava for "completeness' sake," and now consider mistakes.
I don't trust it.)
That said, I think Kevin supports this, which is good enough for me.
I wrote my own patch (I totally forgot yours was there, I'm afraid) and sent it
for Kevin's review (at http://codereview.appspot.com/5271042/), which is
consistent with UnsignedInteger, etc. (In particular, it respects the wrapper
type/view primitives as unsigned distinction.)
Original comment by wasserman.louis
on 17 Oct 2011 at 5:30
Issue 717 has been merged into this issue.
Original comment by wasserman.louis
on 20 Oct 2011 at 8:36
Original comment by fry@google.com
on 10 Dec 2011 at 4:12
Original comment by fry@google.com
on 16 Feb 2012 at 7:17
Original comment by kevinb@google.com
on 30 May 2012 at 7:43
Original comment by kevinb@google.com
on 22 Jun 2012 at 6:16
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:18
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
cow...@bbs.darktech.org
on 26 Jul 2011 at 2:32