- Type Parameters:
T- the type of the data object
public interface ByteAccess<T>
Strategy to access contiguous bytes of a data object.
It is recommended to override the default implementations of at least getInt(Object, long) and getLong(Object, long) for best performance.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidcopyToByteArray(T data, long idx, byte[] array, int off, int len) Copies a given number of bytes from the data object into a givenbyte[]array.byteReturns the byte at a certain position from the given data object asbyte.default intgetByteAsUnsignedInt(T data, long idx) Returns the byte at a certain position from the given data object as non-negativeint.default longgetByteAsUnsignedLong(T data, long idx) Returns the byte at a certain position from the given data object as non-negativelong.default intReturns 4 subsequent bytes starting at a certain position from the given data object asint.default longgetIntAsUnsignedLong(T data, long idx) Returns 4 subsequent bytes starting at a certain position from the given data object as non-negativelong.default longReturns 8 subsequent bytes starting at a certain position from the given data object aslong.
-
Method Details
-
getByte
Returns the byte at a certain position from the given data object asbyte.- Parameters:
data- the data objectidx- the index- Returns:
- the byte
-
getByteAsUnsignedInt
Returns the byte at a certain position from the given data object as non-negativeint.This is equivalent to
getByte(data, idx) & 0xFF.- Parameters:
data- the data objectidx- the index- Returns:
- the byte as non-negative long
-
getByteAsUnsignedLong
Returns the byte at a certain position from the given data object as non-negativelong.This is equivalent to
getByte(data, idx) & 0xFFL.- Parameters:
data- the data objectidx- the index- Returns:
- the byte as non-negative long
-
getInt
Returns 4 subsequent bytes starting at a certain position from the given data object asint.This is equivalent to
(getByte(data, idx) & 0xFF) | ((getByte(data, idx + 1) & 0xFF) << 8) | ((getByte(data, idx + 2) & 0xFF) << 16) | ((int)getByte(data, idx+3) << 24).- Parameters:
data- the data objectidx- the index of the first byte- Returns:
- 4 bytes as integer
-
getIntAsUnsignedLong
Returns 4 subsequent bytes starting at a certain position from the given data object as non-negativelong.This is equivalent to
getInt(data, idx) & 0xFFFFFFFFL.- Parameters:
data- the data objectidx- the index of the first byte- Returns:
- 4 bytes as non-negative long
-
getLong
Returns 8 subsequent bytes starting at a certain position from the given data object aslong.This is equivalent to
getIntUnsigned(data, idx) | ((long) getInt(data, idx + 4) << 32).- Parameters:
data- the data objectidx- the index of the first byte- Returns:
- 8 bytes as long
-
copyToByteArray
Copies a given number of bytes from the data object into a givenbyte[]array.This is equivalent to
for(int i = 0; i < len; ++i) array[off + i] = getByte(data, idx + i).- Parameters:
data- the data objectidx- the index of the first bytearray- the target byte arrayoff- the target offsetlen- the number of bytes
-