I made this fix per your request. You can now use getEnum/putEnum enums
with an ordinal value > 127 for bytes and enums with an ordinal value >
65535 for shorts.
Thanks for the fix.
-Mike
Stuart Scott wrote:
> I noticed that the various getEnum/putEnum methods in IoBuffer use the
> signed values of the various data types. As Enums cannot have negative
> ordinals would it not be more useful to use the unsigned version of the
> data type?
>
> This would be useless for getEnumInt/putEnumInt as an Enum can't be that
> large but it might be useful for getEnumShort/putEnumShort and
> getEnum/putEnum.
>
> For example:
>
> @Override
> public <E extends Enum<E>> E getEnum(Class<E> enumClass) {
> return toEnum(enumClass, getUnsigned());
> }
>
> @Override
> public <E extends Enum<E>> E getEnum(int index, Class<E> enumClass) {
> return toEnum(enumClass, getUnsigned(index));
> }
>
> @Override
> public <E extends Enum<E>> E getEnumShort(Class<E> enumClass) {
> return toEnum(enumClass, getUnsignedShort());
> }
>
> @Override
> public <E extends Enum<E>> E getEnumShort(int index, Class<E> enumClass) {
> return toEnum(enumClass, getUnsignedShort(index));
> }
>
> @Override
> public IoBuffer putEnum(Enum<?> e) {
> if (e.ordinal() > 0xff) {
> throw new IllegalArgumentException(enumConversionErrorMessage(e,
> "byte"));
> }
> return put((byte) e.ordinal());
> }
>
> @Override
> public IoBuffer putEnum(int index, Enum<?> e) {
> if (e.ordinal() > 0xff) {
> throw new IllegalArgumentException(enumConversionErrorMessage(e,
> "byte"));
> }
> return put(index, (byte) e.ordinal());
> }
>
> @Override
> public IoBuffer putEnumShort(Enum<?> e) {
> if (e.ordinal() > 0xffff) {
> throw new IllegalArgumentException(enumConversionErrorMessage(e,
> "short"));
> }
> return putShort((short) e.ordinal());
> }
>
> @Override
> public IoBuffer putEnumShort(int index, Enum<?> e) {
> if (e.ordinal() > 0xffff) {
> throw new IllegalArgumentException(enumConversionErrorMessage(e,
> "short"));
> }
> return putShort(index, (short) e.ordinal());
> }
>
> Stuart
>