org.apache.mina.codec.delimited.ints

## Class VarInt

- java.lang.Object
- - org.apache.mina.codec.delimited.ints.VarInt

- All Implemented Interfaces:
    IntTranscoder

      public final class VarInt
      extends Object
      implements IntTranscoder

  Class providing a variable length representation of integers.

  ## Base 128 Varints serializer

  This serializer is efficient in terms of computing costs as well as bandwith/memory usage.

  The average memory usage overall the range 0 to `Integer.MAX_VALUE` is 4.87 bytes per number which is not far from the canonical form (`RawInt32`), however varints are an interesting solution since the small values (which are supposed to be more frequent) are using less bytes.

  All bytes forming a varint except the last one have the most significant bit (MSB) set. The lower 7 bits of each byte contains the actual representation of the two's complement representation of the number (least significant group first).

  n.b. This serializer is fully compatible with the 128 Varint mechanism shipped with the Google Protocol Buffer stack as default representation of messages sizes.

  ## On-wire representation

  Encoding of the value 812 1001 1100 0000 0110 ↑ ↑ 1 0 // the most significant bit being unset designs the last byte ___↑____ ___↑____ 001 1100 000 0110 // the remaining bits defines the value itself → 44 6 // 44 + 128 * 6 = 812

  n.b. This class doesn't have any dependency against Google Protocol Buffer or any other library in order to provide this convenient integer serialization module to any software using FramedMINA.

  Author:
    Apache MINA Project

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `VarInt()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `IoBufferDecoder<Integer>` | `getDecoder()`
    `ByteBufferEncoder<Integer>` | `getEncoder()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### VarInt

          public VarInt()

  - ### Method Detail

    - #### getDecoder

          public IoBufferDecoder<Integer> getDecoder()

      Specified by:
        `getDecoder` in interface `IntTranscoder`

    - #### getEncoder

          public ByteBufferEncoder<Integer> getEncoder()

      Specified by:
        `getEncoder` in interface `IntTranscoder`

Copyright © 2009–2013 Apache MINA Project. All rights reserved.