protobuf-codec
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -139,3 +139,3 @@ const assert = require('nanoassert') | ||
const bigint = BigInt(int) | ||
varint.encode(BigInt.asIntN(64, bigint), buf, byteOffset) | ||
varint.encode(BigInt.asUintN(64, bigint), buf, byteOffset) | ||
this.encode.bytes = varint.encode.bytes | ||
@@ -147,3 +147,3 @@ return buf.subarray(byteOffset, byteOffset + this.encode.bytes) | ||
assert(int <= this.MAX_VALUE, 'int exceeds MAX_VALUE') | ||
return varint.encodingLength(int) | ||
return varint.encodingLength(BigInt.asUintN(64, BigInt(int))) | ||
}, | ||
@@ -196,3 +196,3 @@ MIN_VALUE: -(1n << 63n), | ||
const bigint = BigInt(int) | ||
varint.encode(BigInt.asIntN(32, bigint), buf, byteOffset) | ||
varint.encode(BigInt.asUintN(32, bigint), buf, byteOffset) | ||
this.encode.bytes = varint.encode.bytes | ||
@@ -204,3 +204,3 @@ return buf.subarray(byteOffset, byteOffset + this.encode.bytes) | ||
assert(int <= this.MAX_VALUE, 'int exceeds MAX_VALUE') | ||
return varint.encodingLength(int) | ||
return varint.encodingLength(BigInt.asUintN(32, BigInt(int))) | ||
}, | ||
@@ -207,0 +207,0 @@ MIN_VALUE: -(1n << 31n), |
{ | ||
"name": "protobuf-codec", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Minimal Protocol Buffers wire encoding/decoding", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -76,1 +76,30 @@ const test = require('tape') | ||
}) | ||
test('int64 indentity', assert => { | ||
const cases = [ | ||
encode.int64.MIN_VALUE, | ||
encode.int64.MAX_VALUE, | ||
0n, | ||
1n, | ||
-1n, | ||
2n, | ||
-2n, | ||
63n, | ||
-64n, | ||
64n, | ||
-65n, | ||
2n ** 31n - 1n, | ||
-(2n ** 31n), | ||
2n ** 31n, | ||
-(2n ** 31n - 1n), | ||
// Two Number values | ||
0, | ||
1 | ||
] | ||
cases.forEach(n => { | ||
assert.equal(decode.int64(decodeWire.varint(encode.int64.encode(n))), BigInt(n)) | ||
}) | ||
assert.end() | ||
}) |
27430
706