org.xerial.db
Class VariableLengthInteger

java.lang.Object
  extended by org.xerial.db.VariableLengthInteger

public class VariableLengthInteger
extends Object

Variable length number representation. When the most significant bit (MSB) of a byte is 0, it means the termination of the value, when the MSB of a byte is 1, its following bytes must be read to compute the value. 0XXXXXXX : [0, 127 (= M1 - 1)] 1XXXXXXX 0XXXXXXX : [M1, M1 + 127 * 2^7 + 127 (= M2-1)] 1XXXXXXX 1XXXXXXX 0XXXXXXX : [M2, M2 + 127 * 2^14 + 127 * 2^7 + 127] [0, 0 + (2 ^ 7 - 1) = 127] [128, 128 + (2^14 - 1) = 16511] [16512, 16512 + (2^21 - 1) = 2113663]

Author:
leo

Constructor Summary
VariableLengthInteger(byte[] byteArray, int offset)
           
VariableLengthInteger(int value)
           
 
Method Summary
static int byteSize(byte[] buffer, int offset)
           
static int byteSize(int value)
          Gets the byte size of the value as an variable length integer
 byte[] getByte()
           
 int intValue()
           
static int readFrom(byte[] buffer, int offset)
           
static VariableLengthInteger readFrom(ByteArrayInputStream buffer)
           
 int size()
           
 int writeTo(BufferWriter writer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableLengthInteger

public VariableLengthInteger(int value)

VariableLengthInteger

public VariableLengthInteger(byte[] byteArray,
                             int offset)
                      throws DBException
Throws:
DBException
Method Detail

getByte

public byte[] getByte()

size

public int size()

intValue

public int intValue()

byteSize

public static int byteSize(byte[] buffer,
                           int offset)
                    throws DBException
Throws:
DBException

byteSize

public static int byteSize(int value)
Gets the byte size of the value as an variable length integer

Parameters:
value -
Returns:

readFrom

public static int readFrom(byte[] buffer,
                           int offset)
                    throws DBException
Throws:
DBException

readFrom

public static VariableLengthInteger readFrom(ByteArrayInputStream buffer)
                                      throws DBException
Throws:
DBException

writeTo

public int writeTo(BufferWriter writer)


Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.1 Japan License.