encode method
Implementation
int encode(int x, bool right) {
var o = x & 255, n = 1;
var bytes = [o];
x = x >> 8;
o = x & 255;
while (o > 0) {
bytes = unshift(bytes, [o]);
x = x >> 8;
o = x & 255;
++n;
}
if (right) {
bytes.add(n);
} else {
bytes = unshift(bytes, [n]);
}
update(bytes);
return bytes.length;
}