Class ByteSource.VariableLengthInteger

  • All Implemented Interfaces:
    ByteSource
    Enclosing interface:
    ByteSource

    public static class ByteSource.VariableLengthInteger
    extends java.lang.Object
    implements ByteSource
    Variable-length encoding for signed integers. The encoding is based on the unsigned encoding above, where the first bit stored is the inverted sign, followed by as many matching bits as there are additional bytes in the encoding, followed by the two's complement of the number. Because of the inverted sign bit, negative numbers compare smaller than positives, and because the length bits match the sign, longer positive numbers compare greater and longer negative ones compare smaller. Examples: 0 encodes as 80 1 encodes as 81 -1 encodes as 7F 63 encodes as BF 64 encodes as C040 -64 encodes as 40 -65 encodes as 3FBF 2^20-1 encodes as EFFFFF 2^20 encodes as F0100000 -2^20 encodes as 100000 2^64-1 encodes as FFFFFFFFFFFFFFFFFF -2^64 encodes as 000000000000000000 As the number of bytes is specified in bits 2-9, no value is a prefix of another.
    • Constructor Detail

      • VariableLengthInteger

        public VariableLengthInteger​(long value)
    • Method Detail

      • next

        public int next()
        Description copied from interface: ByteSource
        Consume the next byte, unsigned. Must be between 0 and 255, or END_OF_STREAM if there are no more bytes.
        Specified by:
        next in interface ByteSource