The QUIC variable-length encoding reserves the two most significant bits of the first byte to encode the size of the length value as a base 2 logarithm value. The length itself is then encoded on the remaining bits, in network byte order. This means that the length values will be encoded on 1, 2, 4, or 8 bytes and can encode 6-, 14-, 30-, or 62-bit values respectively, or a value within the range of 0 to 4611686018427387903 inclusive.
| Modifier and Type | Field and Description |
|---|---|
| public static final long | MAX_ENCODED_INTEGER
The maximum value a variable length integer can take. |
| public static final int | MAX_INTEGER_LENGTH
The maximum number of bytes on which a variable length integer can be encoded. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static long | Returns: the value. If an error occurs,-1 is returned and
the buffer position is left unchanged.the buffer)ByteBuffer that the length will be decoded fromDecode a variable length value from |
| public static long | Returns: the value. If an error occurs,-1 is returned and
the buffer position is left unchanged.the buffers)BuffersReader that the length will be decoded fromDecode a variable length value from |
| public static int | Returns: theposition of the bufferthe buffer, long ByteBuffer that the length will be encoded intothe variable length value value)Encode (a variable length) value into |
| public static int | Returns: the number of bytes needed to encode the given value as a variable length integer.the value to encode value)Returns the number of bytes needed to encode the given value as a variable length integer. |
| public static int | Returns: the base 2 logarithm of the number of bytes required to encode the value as a variable length integer.the value to encode value)Returns the variable length prefix. |
| public static long | Returns: the variable length value encoded at the given offset, or -1the buffer to read from buffer, int the offset in the buffer to start reading from offset)Peeks at a variable length value encoded at the given offset. |
| public static long | Returns: the variable length value encoded at the given offset, or -1the buffer to read from buffers, long the offset in the buffer to start reading from offset)Peeks at a variable length value encoded at the given offset. |
| public static int | Returns: the number of bytes on which the variable length value is encoded at the given offset, or -1the buffer to read from buffer, int the offset in the buffer to start reading from offset)Peeks at a variable length value encoded at the given offset, and return the number of bytes on which this value is encoded. |
| public static int | Returns: the number of bytes on which the variable length value is encoded at the given offset, or -1the buffers to read from buffers, long the offset in the buffer to start reading from offset)Peeks at a variable length value encoded at the given offset, and return the number of bytes on which this value is encoded. |
| MAX_ENCODED_INTEGER | back to summary |
|---|---|
| public static final long MAX_ENCODED_INTEGER The maximum value a variable length integer can take. | |
| MAX_INTEGER_LENGTH | back to summary |
|---|---|
| public static final int MAX_INTEGER_LENGTH The maximum number of bytes on which a variable length integer can be encoded. | |
| VariableLengthEncoder | back to summary |
|---|---|
| private VariableLengthEncoder() | |
| decode | back to summary |
|---|---|
| public static long decode(ByteBuffer buffer) Decode a variable length value from
| |
| decode | back to summary |
|---|---|
| public static long decode(BuffersReader buffers) Decode a variable length value from
| |
| encode | back to summary |
|---|---|
| public static int encode(ByteBuffer buffer, long value) throws IllegalArgumentException Encode (a variable length) value into
| |
| getEncodedSize | back to summary |
|---|---|
| public static int getEncodedSize(long value) throws IllegalArgumentException Returns the number of bytes needed to encode the given value as a variable length integer. This a number between 1 and 8.
| |
| getVariableLengthPrefix | back to summary |
|---|---|
| public static int getVariableLengthPrefix(long value) throws IllegalArgumentException Returns the variable length prefix. The variable length prefix is the base 2 logarithm of the number of bytes required to encode a positive value as a variable length integer: [0, 1, 2, 3] for [1, 2, 4, 8] bytes.
| |
| peekEncodedValue | back to summary |
|---|---|
| public static long peekEncodedValue(ByteBuffer buffer, int offset) Peeks at a variable length value encoded at the given offset. If the byte buffer doesn't contain enough bytes to read the variable length value, -1 is returned. This method doesn't advance the buffer position.
| |
| peekEncodedValue | back to summary |
|---|---|
| public static long peekEncodedValue(BuffersReader buffers, long offset) Peeks at a variable length value encoded at the given offset. If the byte buffer doesn't contain enough bytes to read the variable length value, -1 is returned. This method doesn't advance the buffer position.
| |
| peekEncodedValueSize | back to summary |
|---|---|
| public static int peekEncodedValueSize(ByteBuffer buffer, int offset) Peeks at a variable length value encoded at the given offset, and return the number of bytes on which this value is encoded. If the byte buffer is empty or the offset is past the limit -1 is returned. This method doesn't advance the buffer position.
| |
| peekEncodedValueSize | back to summary |
|---|---|
| public static int peekEncodedValueSize(BuffersReader buffers, long offset) Peeks at a variable length value encoded at the given offset, and return the number of bytes on which this value is encoded. If the byte buffer is empty or the offset is past the limit -1 is returned. This method doesn't advance the buffer position.
| |