/** * Gets an unsigned data type from the buffer with the specified order and transformation. * * @param type The data type. * @param order The byte order. * @param transformation The data transformation. * @return The value. * @throws IllegalStateException If this reader is not in byte access mode. * @throws IllegalArgumentException If the combination is invalid. */ public long getUnsigned(DataType type, DataOrder order, DataTransformation transformation) { long longValue = get(type, order, transformation); Preconditions.checkArgument(type != DataType.LONG, "Longs must be read as a signed type."); return longValue & 0xFFFFFFFFFFFFFFFFL; }
/** * Gets a signed data type from the buffer with the specified order and transformation. * * @param type The data type. * @param order The byte order. * @param transformation The data transformation. * @return The value. * @throws IllegalStateException If this reader is not in byte access mode. * @throws IllegalArgumentException If the combination is invalid. */ public long getSigned(DataType type, DataOrder order, DataTransformation transformation) { long longValue = get(type, order, transformation); if (type != DataType.LONG) { int max = (int) (Math.pow(2, type.getBytes() * 8 - 1) - 1); if (longValue > max) { longValue -= (max + 1) * 2; } } return longValue; }