Hi.
I added unsigned getters. Unsigned putters are not required because
we can just downcast values.
Cheers,
Trustin
On Wed, 12 Jan 2005 21:18:02 -0500, Enrique Rodriguez
<erodriguez@apache.org> wrote:
> Trustin,
>
> I'd like to suggest adding some convenience methods to the ByteBuffer
> impl in MINA to handle unsigned types in Java. The standard method for
> handling unsigned type in Java (since there isn't language support) is
> to use a type one size larger than the unsigned type. This technique
> appears across the net and is also in the O'Reilly NIO book.
>
> I have been using these as static methods in a utility class, but they
> would be nice to have in MINA's ByteBuffer. They are used pretty
> extensively in binary protocols. I have attached non-static versions,
> below, for your review.
>
> -enrique
>
> public short getUnsignedByte()
> {
> return ( (short)( buf.get() & 0xff ) );
> }
>
> public void putUnsignedByte( int value )
> {
> buf.put( (byte)( value & 0xff ) );
> }
>
> public short getUnsignedByte( int position )
> {
> return ( (short)( buf.get (position) & (short)0xff ) );
> }
>
> public void putUnsignedByte( int position, int value )
> {
> buf.put( position, (byte)( value & 0xff ) );
> }
>
> public int getUnsignedShort()
> {
> return ( buf.getShort() & 0xffff );
> }
>
> public void putUnsignedShort( int value )
> {
> buf.putShort( (short)( value & 0xffff ) );
> }
>
> public int getUnsignedShort( int position )
> {
> return ( buf.getShort( position ) & 0xffff );
> }
>
> public void putUnsignedShort( int position, int value )
> {
> buf.putShort( position, (short)( value & 0xffff ) );
> }
>
> public long getUnsignedInt()
> {
> return ( buf.getInt() & 0xffffffffL );
> }
>
> public void putUnsignedInt( long value )
> {
> buf.putInt( (int)( value & 0xffffffffL ) );
> }
>
> public long getUnsignedInt( int position )
> {
> return ( buf.getInt( position ) & 0xffffffffL );
> }
>
> public void putUnsignedInt( int position, long value )
> {
> buf.putInt( position, (int)( value & 0xffffffffL ) );
> }
>
>
--
what we call human nature is actually human habit
--
http://gleamynode.net/
|