VIntCoding (apache-cassandra API)
Date: 2018-02-14

org.apache.cassandra.utils.vint

## Class VIntCoding

- java.lang.Object
- - org.apache.cassandra.utils.vint.VIntCoding

-     public class VIntCoding
      extends java.lang.Object

  Borrows idea from https://developers.google.com/protocol-buffers/docs/encoding#varints

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static io.netty.util.concurrent.FastThreadLocal<byte[]>` | `encodingBuffer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `VIntCoding()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `computeUnsignedVIntSize(long value)` Compute the number of bytes that would be needed to encode an unsigned varint.
    `static int` | `computeVIntSize(long param)` Compute the number of bytes that would be needed to encode a varint.
    `static long` | `decodeZigZag64(long n)` Decode a ZigZag-encoded 64-bit value.
    `static int` | `encodeExtraBytesToRead(int extraBytesToRead)`
    `static byte[]` | `encodeVInt(long value, int size)`
    `static long` | `encodeZigZag64(long n)` Encode a ZigZag-encoded 64-bit value.
    `static int` | `firstByteValueMask(int extraBytesToRead)`
    `static int` | `numberOfExtraBytesToRead(int firstByte)`
    `static long` | `readUnsignedVInt(java.io.DataInput input)`
    `static long` | `readVInt(java.io.DataInput input)`
    `static void` | `writeUnsignedVInt(long value, java.io.DataOutput output)`
    `static void` | `writeVInt(long value, java.io.DataOutput output)`

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

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

- - ### Field Detail

    - #### encodingBuffer

          protected static final io.netty.util.concurrent.FastThreadLocal<byte[]> encodingBuffer

  - ### Constructor Detail

    - #### VIntCoding

          public VIntCoding()

  - ### Method Detail

    - #### readUnsignedVInt

          public static long readUnsignedVInt(java.io.DataInput input)
                                       throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### readVInt

          public static long readVInt(java.io.DataInput input)
                               throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### firstByteValueMask

          public static int firstByteValueMask(int extraBytesToRead)

    - #### encodeExtraBytesToRead

          public static int encodeExtraBytesToRead(int extraBytesToRead)

    - #### numberOfExtraBytesToRead

          public static int numberOfExtraBytesToRead(int firstByte)

    - #### writeUnsignedVInt

          public static void writeUnsignedVInt(long value,
                                               java.io.DataOutput output)
                                        throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### encodeVInt

          @Inline
          public static byte[] encodeVInt(long value,
                                                  int size)

    - #### writeVInt

          public static void writeVInt(long value,
                                       java.io.DataOutput output)
                                throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### decodeZigZag64

          public static long decodeZigZag64(long n)

      Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, thus always taking 10 bytes on the wire.)
      Parameters:
        `n` - An unsigned 64-bit integer, stored in a signed int because Java has no explicit unsigned support.
      Returns:
        A signed 64-bit integer.

    - #### encodeZigZag64

          public static long encodeZigZag64(long n)

      Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, thus always taking 10 bytes on the wire.)
      Parameters:
        `n` - A signed 64-bit integer.
      Returns:
        An unsigned 64-bit integer, stored in a signed int because Java has no explicit unsigned support.

    - #### computeVIntSize

          public static int computeVIntSize(long param)

      Compute the number of bytes that would be needed to encode a varint.

    - #### computeUnsignedVIntSize

          public static int computeUnsignedVIntSize(long value)

      Compute the number of bytes that would be needed to encode an unsigned varint.

Copyright © 2018 The Apache Software Foundation