in codec/src/main/java/org/apache/mina/codec/delimited/ints/VarInt.java [115:152]
public Integer decode(IoBuffer input) {
int origpos = input.position();
try {
byte tmp = input.get();
if (tmp >= 0) {
return (int) tmp;
}
int result = tmp & 0x7f;
if ((tmp = input.get()) >= 0) {
result |= tmp << 7;
} else {
result |= (tmp & 0x7f) << 7;
if ((tmp = input.get()) >= 0) {
result |= tmp << 14;
} else {
result |= (tmp & 0x7f) << 14;
if ((tmp = input.get()) >= 0) {
result |= tmp << 21;
} else {
result |= (tmp & 0x7f) << 21;
// check that there are at most 3 significant bits available
if (((tmp = input.get()) & ~0x7) == 0) {
result |= tmp << 28;
} else {
throw new ProtocolDecoderException("Not the varint representation of a signed int32");
}
}
}
}
return result;
} catch (BufferUnderflowException bue) {
input.position(origpos);
}
return null;
}