Class PackedInteger
Most applications should use the classes in the com.sleepycat.bind.tuple package rather than using this class directly.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum number of bytes needed to store an int value (5).static final intThe maximum number of bytes needed to store a long value (9). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intgetReadIntLength(byte[] buf, int off) Returns the number of bytes that would be read byreadInt(byte[], int).static intgetReadLongLength(byte[] buf, int off) Returns the number of bytes that would be read byreadLong(byte[], int).static intgetReadSortedIntLength(byte[] buf, int off) Returns the number of bytes that would be read byreadSortedInt(byte[], int).static intgetReadSortedLongLength(byte[] buf, int off) Returns the number of bytes that would be read byreadSortedLong(byte[], int).static intgetWriteIntLength(int value) Returns the number of bytes that would be written bywriteInt(byte[], int, int).static intgetWriteLongLength(long value) Returns the number of bytes that would be written bywriteLong(byte[], int, long).static intgetWriteSortedIntLength(int value) Returns the number of bytes that would be written bywriteSortedInt(byte[], int, int).static intgetWriteSortedLongLength(long value) Returns the number of bytes that would be written bywriteSortedLong(byte[], int, long).static intreadInt(byte[] buf, int off) Reads a packed integer at the given buffer offset and returns it.static longreadLong(byte[] buf, int off) Reads a packed long integer at the given buffer offset and returns it.static intreadSortedInt(byte[] buf, int off) Reads a sorted packed integer at the given buffer offset and returns it.static longreadSortedLong(byte[] buf, int off) Reads a sorted packed long integer at the given buffer offset and returns it.static intwriteInt(byte[] buf, int offset, int value) Writes a packed integer starting at the given buffer offset and returns the next offset to be written.static intwriteLong(byte[] buf, int offset, long value) Writes a packed long integer starting at the given buffer offset and returns the next offset to be written.static intwriteSortedInt(byte[] buf, int offset, int value) Writes a packed sorted integer starting at the given buffer offset and returns the next offset to be written.static intwriteSortedLong(byte[] buf, int offset, long value) Writes a packed sorted long integer starting at the given buffer offset and returns the next offset to be written.
-
Field Details
-
MAX_LENGTH
public static final int MAX_LENGTHThe maximum number of bytes needed to store an int value (5).- See Also:
-
MAX_LONG_LENGTH
public static final int MAX_LONG_LENGTHThe maximum number of bytes needed to store a long value (9).- See Also:
-
-
Constructor Details
-
PackedInteger
public PackedInteger()
-
-
Method Details
-
readInt
public static int readInt(byte[] buf, int off) Reads a packed integer at the given buffer offset and returns it.- Parameters:
buf- the buffer to read from.off- the offset in the buffer at which to start reading.- Returns:
- the integer that was read.
-
readLong
public static long readLong(byte[] buf, int off) Reads a packed long integer at the given buffer offset and returns it.- Parameters:
buf- the buffer to read from.off- the offset in the buffer at which to start reading.- Returns:
- the long integer that was read.
-
getReadIntLength
public static int getReadIntLength(byte[] buf, int off) Returns the number of bytes that would be read byreadInt(byte[], int).Because the length is stored in the first byte, this method may be called with only the first byte of the packed integer in the given buffer. This method only accesses one byte at the given offset.
- Parameters:
buf- the buffer to read from.off- the offset in the buffer at which to start reading.- Returns:
- the number of bytes that would be read.
-
getReadLongLength
public static int getReadLongLength(byte[] buf, int off) Returns the number of bytes that would be read byreadLong(byte[], int).Because the length is stored in the first byte, this method may be called with only the first byte of the packed integer in the given buffer. This method only accesses one byte at the given offset.
- Parameters:
buf- the buffer to read from.off- the offset in the buffer at which to start reading.- Returns:
- the number of bytes that would be read.
-
writeInt
public static int writeInt(byte[] buf, int offset, int value) Writes a packed integer starting at the given buffer offset and returns the next offset to be written.- Parameters:
buf- the buffer to write to.offset- the offset in the buffer at which to start writing.value- the integer to be written.- Returns:
- the offset past the bytes written.
-
writeLong
public static int writeLong(byte[] buf, int offset, long value) Writes a packed long integer starting at the given buffer offset and returns the next offset to be written.- Parameters:
buf- the buffer to write to.offset- the offset in the buffer at which to start writing.value- the long integer to be written.- Returns:
- the offset past the bytes written.
-
getWriteIntLength
public static int getWriteIntLength(int value) Returns the number of bytes that would be written bywriteInt(byte[], int, int).- Parameters:
value- the integer to be written.- Returns:
- the number of bytes that would be used to write the given integer.
-
getWriteLongLength
public static int getWriteLongLength(long value) Returns the number of bytes that would be written bywriteLong(byte[], int, long).- Parameters:
value- the long integer to be written.- Returns:
- the number of bytes that would be used to write the given long integer.
-
readSortedInt
public static int readSortedInt(byte[] buf, int off) Reads a sorted packed integer at the given buffer offset and returns it.- Parameters:
buf- the buffer to read from.off- the offset in the buffer at which to start reading.- Returns:
- the integer that was read.
-
readSortedLong
public static long readSortedLong(byte[] buf, int off) Reads a sorted packed long integer at the given buffer offset and returns it.- Parameters:
buf- the buffer to read from.off- the offset in the buffer at which to start reading.- Returns:
- the long integer that was read.
-
getReadSortedIntLength
public static int getReadSortedIntLength(byte[] buf, int off) Returns the number of bytes that would be read byreadSortedInt(byte[], int).Because the length is stored in the first byte, this method may be called with only the first byte of the packed integer in the given buffer. This method only accesses one byte at the given offset.
- Parameters:
buf- the buffer to read from.off- the offset in the buffer at which to start reading.- Returns:
- the number of bytes that would be read.
-
getReadSortedLongLength
public static int getReadSortedLongLength(byte[] buf, int off) Returns the number of bytes that would be read byreadSortedLong(byte[], int).Because the length is stored in the first byte, this method may be called with only the first byte of the packed integer in the given buffer. This method only accesses one byte at the given offset.
- Parameters:
buf- the buffer to read from.off- the offset in the buffer at which to start reading.- Returns:
- the number of bytes that would be read.
-
writeSortedInt
public static int writeSortedInt(byte[] buf, int offset, int value) Writes a packed sorted integer starting at the given buffer offset and returns the next offset to be written.- Parameters:
buf- the buffer to write to.offset- the offset in the buffer at which to start writing.value- the integer to be written.- Returns:
- the offset past the bytes written.
-
writeSortedLong
public static int writeSortedLong(byte[] buf, int offset, long value) Writes a packed sorted long integer starting at the given buffer offset and returns the next offset to be written.- Parameters:
buf- the buffer to write to.offset- the offset in the buffer at which to start writing.value- the long integer to be written.- Returns:
- the offset past the bytes written.
-
getWriteSortedIntLength
public static int getWriteSortedIntLength(int value) Returns the number of bytes that would be written bywriteSortedInt(byte[], int, int).- Parameters:
value- the integer to be written.- Returns:
- the number of bytes that would be used to write the given integer.
-
getWriteSortedLongLength
public static int getWriteSortedLongLength(long value) Returns the number of bytes that would be written bywriteSortedLong(byte[], int, long).- Parameters:
value- the long integer to be written.- Returns:
- the number of bytes that would be used to write the given long integer.
-