Class VarLenInt

java.lang.Object
org.eclipse.jetty.quic.util.VarLenInt

public class VarLenInt extends Object

Encodes and decodes long values as specified by QUIC.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The max number of bytes used to encode long values.
    static final long
    The max value supported by this variable-length codec, 2^62-1.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    decodeInt(ByteBuffer byteBuffer)
    Decodes an int value from the given ByteBuffer.
    static long
    decodeLong(ByteBuffer byteBuffer)
    Decodes a long value from the given ByteBuffer.
    static void
    encode(ByteBuffer byteBuffer, long value)
    Variable-length encodes the given long value into the given ByteBuffer, starting at its current position.
    static int
    length(long value)
    Returns the number of bytes necessary to variable-length encode the given long value.
    boolean
    tryDecode(ByteBuffer byteBuffer, LongConsumer consumer)
    Tries to decode a variable-length long from the given ByteBuffer.
    boolean
    Tries to decode a variable-length long from the given ByteBuffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_VALUE

      public static final long MAX_VALUE
      The max value supported by this variable-length codec, 2^62-1.
      See Also:
    • MAX_LENGTH

      public static final int MAX_LENGTH
      The max number of bytes used to encode long values.
      See Also:
  • Constructor Details

    • VarLenInt

      public VarLenInt()
  • Method Details

    • tryDecode

      public boolean tryDecode(ByteBuffer byteBuffer, LongConsumer consumer)

      Tries to decode a variable-length long from the given ByteBuffer.

      If there are enough bytes to decode the long value, the given Consumer is invoked with the value, and this method returns true. Otherwise, there are not enough bytes to decode the long value, and this method returns false.

      Parameters:
      byteBuffer - the ByteBuffer to decode from
      consumer - the LongConsumer to invoke when the decoding is complete
      Returns:
      whether the decoding was complete
    • tryDecode

      public boolean tryDecode(ByteBuffer byteBuffer, VarLenInt.IntLongConsumer consumer)

      Tries to decode a variable-length long from the given ByteBuffer.

      If there are enough bytes to decode the long value, the given IntLongConsumer is invoked with the number of bytes consumed and the value, and this method returns true. Otherwise, there are not enough bytes to decode the long value, and this method returns false.

      Parameters:
      byteBuffer - the ByteBuffer to decode from
      consumer - the LongConsumer to invoke when the decoding is complete
      Returns:
      whether the decoding was complete
    • decodeInt

      public static int decodeInt(ByteBuffer byteBuffer)

      Decodes an int value from the given ByteBuffer.

      Parameters:
      byteBuffer - the ByteBuffer to decode from
      Returns:
      the decoded int value
    • decodeLong

      public static long decodeLong(ByteBuffer byteBuffer)

      Decodes a long value from the given ByteBuffer.

      Parameters:
      byteBuffer - the ByteBuffer to decode from
      Returns:
      the decoded long value
    • encode

      public static void encode(ByteBuffer byteBuffer, long value)

      Variable-length encodes the given long value into the given ByteBuffer, starting at its current position.

      Parameters:
      byteBuffer - the ByteBuffer to encode into
      value - the long value to encode
    • length

      public static int length(long value)

      Returns the number of bytes necessary to variable-length encode the given long value.

      Parameters:
      value - the long value to encode
      Returns:
      the number of bytes necessary to variable-length encode the given long value