public final class VarInt extends Object implements IntTranscoder
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.
Encoding of the value 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.
Constructor and Description |
---|
VarInt() |
Modifier and Type | Method and Description |
---|---|
IoBufferDecoder<Integer> |
getDecoder() |
ByteBufferEncoder<Integer> |
getEncoder() |
public IoBufferDecoder<Integer> getDecoder()
getDecoder
in interface IntTranscoder
public ByteBufferEncoder<Integer> getEncoder()
getEncoder
in interface IntTranscoder
Copyright © 2009–2013 Apache MINA Project. All rights reserved.