Package com.sleepycat.util

## Class PackedInteger

- java.lang.Object
- - com.sleepycat.util.PackedInteger

-     public class PackedInteger
      extends java.lang.Object

  Static methods for reading and writing packed integers.

  Most applications should use the classes in the `com.sleepycat.bind.tuple` package rather than using this class directly.

  See Also:
    Integer Formats

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `MAX_LENGTH` | The maximum number of bytes needed to store an int value (5).
    `static int` | `MAX_LONG_LENGTH` | The maximum number of bytes needed to store a long value (9).

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `PackedInteger()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static int` | `getReadIntLength​(byte[] buf, int off)` | Returns the number of bytes that would be read by `readInt(byte[], int)`.
    `static int` | `getReadLongLength​(byte[] buf, int off)` | Returns the number of bytes that would be read by `readLong(byte[], int)`.
    `static int` | `getReadSortedIntLength​(byte[] buf, int off)` | Returns the number of bytes that would be read by `readSortedInt(byte[], int)`.
    `static int` | `getReadSortedLongLength​(byte[] buf, int off)` | Returns the number of bytes that would be read by `readSortedLong(byte[], int)`.
    `static int` | `getWriteIntLength​(int value)` | Returns the number of bytes that would be written by `writeInt(byte[], int, int)`.
    `static int` | `getWriteLongLength​(long value)` | Returns the number of bytes that would be written by `writeLong(byte[], int, long)`.
    `static int` | `getWriteSortedIntLength​(int value)` | Returns the number of bytes that would be written by `writeSortedInt(byte[], int, int)`.
    `static int` | `getWriteSortedLongLength​(long value)` | Returns the number of bytes that would be written by `writeSortedLong(byte[], int, long)`.
    `static int` | `readInt​(byte[] buf, int off)` | Reads a packed integer at the given buffer offset and returns it.
    `static long` | `readLong​(byte[] buf, int off)` | Reads a packed long integer at the given buffer offset and returns it.
    `static int` | `readSortedInt​(byte[] buf, int off)` | Reads a sorted packed integer at the given buffer offset and returns it.
    `static long` | `readSortedLong​(byte[] buf, int off)` | Reads a sorted packed long integer at the given buffer offset and returns it.
    `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.
    `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.
    `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.
    `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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MAX_LENGTH

          public static final int MAX_LENGTH

      The maximum number of bytes needed to store an int value (5).
      See Also:
        Constant Field Values

    - #### MAX_LONG_LENGTH

          public static final int MAX_LONG_LENGTH

      The maximum number of bytes needed to store a long value (9).
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### PackedInteger

          public PackedInteger()

  - ### Method Detail

    - #### 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 by `readInt(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 by `readLong(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 by `writeInt(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 by `writeLong(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 by `readSortedInt(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 by `readSortedLong(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 by `writeSortedInt(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 by `writeSortedLong(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.

Copyright (c) 1996, 2020 Oracle and/or its affiliates. All rights reserved.