framer: fix 32 and 64 bit support for varint().

Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
Christopher Jeffrey 2014-05-17 09:50:45 -05:00 committed by Fedor Indutny
parent e89eb925e6
commit 5c5762a000

View File

@ -105,14 +105,18 @@ function varint(arr, value, off) {
arr[off + 2] = value >>> 8;
return 3;
} else if (value <= 0xffffffff) {
arr[off] = 0xfd;
arr[off + 3] = value & 0xff;
arr[off + 4] = (value >>> 8) & 0xff;
arr[off + 5] = (value >>> 16) & 0xff;
arr[off + 6] = value >>> 24;
arr[off] = 0xfe;
arr[off + 1] = value & 0xff;
arr[off + 2] = (value >>> 8) & 0xff;
arr[off + 3] = (value >>> 16) & 0xff;
arr[off + 4] = value >>> 24;
return 5;
} else if (peers.length <= 0xffffffffffffffff) {
p[off] = 0xff;
utils.writeU64(arr, value, off + 1);
return 9;
} else {
throw new Error('64bit varint not supported yet');
throw new Error('>64bit varint not supported yet');
}
}