T
- the type of the object to accesspublic interface Access<T>
T
class instances as ordered byte
sequence. All getXXX(input, offset)
should be consistent to each other in terms of
ordered byte sequence each T
instance represents. For example, if some Access
implementation returns ByteOrder.LITTLE_ENDIAN
on byteOrder(input)
call, the following expressions should always have the same value:
getLong(input, 0)
getUnsignedInt(input, 0) | (getUnsignedInt(input, 4) << 32)
getUnsignedInt(input, 0) |
((long) getUnsignedShort(input, 4) << 32) |
((long) getUnsignedByte(input, 6) << 48) |
((long) getUnsignedByte(input, 7) << 56)
getXXX(input, offset)
methods could throw unchecked exceptions when requested bytes
range is outside of the bounds of the byte sequence, represented by the given input
.
However, they could omit checks for better performance.
Access
API is designed for inputs, that actually represent byte sequences that lay
continuously in memory. Theoretically Access
strategy could be implemented for
non-continuous byte sequences, or abstractions which aren't actually present in memory as they
are accessed, but this should be awkward, and hashing using such Access
is expected to
be slow.
Modifier and Type | Method and Description |
---|---|
ByteOrder |
byteOrder(T input)
The byte order in which all multi-byte
getXXX() reads from the given input
are performed. |
int |
getByte(T input,
long offset)
Reads a single byte at the given
offset in the byte sequence represented by the given
input , returned widened to int . |
int |
getInt(T input,
long offset)
Reads
[offset, offset + 3] bytes of the byte sequence represented by the given
input as a single int value. |
long |
getLong(T input,
long offset)
Reads
[offset, offset + 7] bytes of the byte sequence represented by the given
input as a single long value. |
int |
getShort(T input,
long offset)
Reads
[offset, offset + 1] bytes of the byte sequence represented by the given
input as a single short value, returned widened to int . |
int |
getUnsignedByte(T input,
long offset)
Shortcut for
getByte(input, offset) & 0xFF . |
long |
getUnsignedInt(T input,
long offset)
Shortcut for
getInt(input, offset) & 0xFFFFFFFFL . |
int |
getUnsignedShort(T input,
long offset)
Shortcut for
getShort(input, offset) & 0xFFFF . |
long getLong(T input, long offset)
[offset, offset + 7]
bytes of the byte sequence represented by the given
input
as a single long
value.input
- the object to accessoffset
- offset to the first byte to read within the byte sequence represented
by the given objectlong
value, in the expected
orderlong getUnsignedInt(T input, long offset)
getInt(input, offset) & 0xFFFFFFFFL
. Could be implemented more
efficiently.input
- the object to accessoffset
- offset to the first byte to read within the byte sequence represented
by the given objectint getInt(T input, long offset)
[offset, offset + 3]
bytes of the byte sequence represented by the given
input
as a single int
value.input
- the object to accessoffset
- offset to the first byte to read within the byte sequence represented
by the given objectint
value, in the expected
orderint getUnsignedShort(T input, long offset)
getShort(input, offset) & 0xFFFF
. Could be implemented more
efficiently.input
- the object to accessoffset
- offset to the first byte to read within the byte sequence represented
by the given objectint getShort(T input, long offset)
[offset, offset + 1]
bytes of the byte sequence represented by the given
input
as a single short
value, returned widened to int
.input
- the object to accessoffset
- offset to the first byte to read within the byte sequence represented
by the given objectshort
value, in the expected
order, widened to int
int getUnsignedByte(T input, long offset)
getByte(input, offset) & 0xFF
. Could be implemented more efficiently.input
- the object to accessoffset
- offset to the byte to read within the byte sequence represented
by the given objectoffset
, interpreted as unsignedint getByte(T input, long offset)
offset
in the byte sequence represented by the given
input
, returned widened to int
.input
- the object to accessoffset
- offset to the byte to read within the byte sequence represented
by the given objectoffset
, widened to int
Copyright © 2015. All rights reserved.