Object Varint

  • All Implemented Interfaces:

    
    public class Varint
    
                        

    Object Varint contains utility functions to encode and decode integers using variable-length quantity (Varint). Varint is a method of serializing integers using one or more bytes; smaller integers use fewer bytes. Used by Multicodec (which is used for DidKey)

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static Varint INSTANCE
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final ByteArray encode(Integer inp) Encodes the given integer inp into a ByteArray using Varint encoding.
      final Pair<Integer, Integer> decode(ByteArray input) Decodes the given ByteArray input from Varint format to a Pair of Integers.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • encode

         final ByteArray encode(Integer inp)

        Encodes the given integer inp into a ByteArray using Varint encoding. The function supports encoding of Integers to Varint byte arrays, which are more efficient in representing smaller numbers using fewer bytes.

        Parameters:
        inp - The integer to be encoded.
        Returns:

        The ByteArray representing inp in Varint format.

      • decode

         final Pair<Integer, Integer> decode(ByteArray input)

        Decodes the given ByteArray input from Varint format to a Pair of Integers. The function extracts the integer represented by the Varint and the number of bytes read to decode the integer.

        Parameters:
        input - The ByteArray to be decoded, representing an integer in Varint format.
        Returns:

        A Pair where the first element is the decoded integer and the second element is the number of bytes read from input to decode the integer.