occurrences = encode.remaining();
}
long ul = 0;
long ulmask = (0xfe << 56) & 0xffffffff;
RubyBignum big128 = RubyBignum.newBignum(runtime, 128);
int pos = encode.position();
while (occurrences > 0 && pos < encode.limit()) {
ul <<= 7;
ul |= encode.get(pos) & 0x7f;
if((encode.get(pos++) & 0x80) == 0) {
result.append(RubyFixnum.newFixnum(runtime, ul));
occurrences--;
ul = 0;
} else if((ul & ulmask) == 0) {
RubyBignum big = RubyBignum.newBignum(runtime, ul);
while(occurrences > 0 && pos < encode.limit()) {
IRubyObject mulResult = big.op_mul(runtime.getCurrentContext(), big128);
IRubyObject v = mulResult.callMethod(runtime.getCurrentContext(), "+",
RubyBignum.newBignum(runtime, encode.get(pos) & 0x7f));
if(v instanceof RubyFixnum) {
big = RubyBignum.newBignum(runtime, RubyNumeric.fix2long(v));
} else if (v instanceof RubyBignum) {
big = (RubyBignum)v;
}
if((encode.get(pos++) & 0x80) == 0) {
result.add(RubyBignum.bignorm(runtime, big.getValue()));
occurrences--;
ul = 0;
break;
}
}