diff --git a/packages/protons-runtime/package.json b/packages/protons-runtime/package.json index 37207a4..4a44260 100644 --- a/packages/protons-runtime/package.json +++ b/packages/protons-runtime/package.json @@ -126,6 +126,7 @@ "release": "aegir release" }, "dependencies": { + "uint8-varint": "^2.0.2", "uint8arraylist": "^2.4.3", "uint8arrays": "^4.0.6" }, diff --git a/packages/protons-runtime/src/utils/reader.ts b/packages/protons-runtime/src/utils/reader.ts index a594c01..abb9767 100644 --- a/packages/protons-runtime/src/utils/reader.ts +++ b/packages/protons-runtime/src/utils/reader.ts @@ -1,3 +1,4 @@ +import { decodeUint8Array, encodingLength } from 'uint8-varint' import { readFloatLE, readDoubleLE } from './float.js' import { LongBits } from './longbits.js' import * as utf8 from './utf8.js' @@ -304,7 +305,9 @@ export class Uint8ArrayReader implements Reader { * JavaScript number */ uint64Number (): number { - return this.readLongVarint().toNumber(true) + const value = decodeUint8Array(this.buf, this.pos) + this.pos += encodingLength(value) + return value } /** diff --git a/packages/protons-runtime/src/utils/writer.ts b/packages/protons-runtime/src/utils/writer.ts index 9ebc6d5..1842024 100644 --- a/packages/protons-runtime/src/utils/writer.ts +++ b/packages/protons-runtime/src/utils/writer.ts @@ -1,3 +1,4 @@ +import { encodeUint8Array, encodingLength } from 'uint8-varint' import { allocUnsafe } from 'uint8arrays/alloc' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { writeFloatLE, writeDoubleLE } from './float.js' @@ -186,8 +187,7 @@ class Uint8ArrayWriter implements Writer { * Writes an unsigned 64 bit value as a varint */ uint64Number (value: number): this { - const bits = LongBits.fromNumber(value) - return this._push(writeVarint64, bits.length(), bits) + return this._push(encodeUint8Array, encodingLength(value), value) } /**