Class NBitIntegerDecoder


  • public class NBitIntegerDecoder
    extends java.lang.Object
    Used to decode integers as described in RFC7541.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int decodeInt​(java.nio.ByteBuffer buffer)
      Decode an integer from the buffer.
      long decodeLong​(java.nio.ByteBuffer buffer)
      Decode a long from the buffer.
      void reset()
      Reset the internal state of the parser.
      void setPrefix​(int prefix)
      Set the prefix length in of the integer representation in bits.
      • Methods inherited from class java.lang.Object

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

      • NBitIntegerDecoder

        public NBitIntegerDecoder()
    • Method Detail

      • setPrefix

        public void setPrefix​(int prefix)
        Set the prefix length in of the integer representation in bits. A prefix of 6 means the integer representation starts after the first 2 bits.
        Parameters:
        prefix - the number of bits in the integer prefix.
      • decodeInt

        public int decodeInt​(java.nio.ByteBuffer buffer)
        Decode an integer from the buffer. If the buffer does not contain the complete integer representation a value of -1 is returned to indicate that more data is needed to complete parsing. This should be only after the prefix has been set with setPrefix(int).
        Parameters:
        buffer - the buffer containing the encoded integer.
        Returns:
        the decoded integer or -1 to indicate that more data is needed.
        Throws:
        java.lang.ArithmeticException - if the value overflows a int.
      • decodeLong

        public long decodeLong​(java.nio.ByteBuffer buffer)
        Decode a long from the buffer. If the buffer does not contain the complete integer representation a value of -1 is returned to indicate that more data is needed to complete parsing. This should be only after the prefix has been set with setPrefix(int).
        Parameters:
        buffer - the buffer containing the encoded integer.
        Returns:
        the decoded long or -1 to indicate that more data is needed.
        Throws:
        java.lang.ArithmeticException - if the value overflows a long.
      • reset

        public void reset()
        Reset the internal state of the parser.