From 684aff713150538f63fab3afe363d9549e944527 Mon Sep 17 00:00:00 2001 From: Lisoveliy Date: Thu, 24 Jul 2025 02:24:17 +0300 Subject: [PATCH] fix: fix of BigInt issue of protobuf decoder (special thanks: silver.zepp) --- lib/protobuf-decoder/varintUtils.js | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/protobuf-decoder/varintUtils.js b/lib/protobuf-decoder/varintUtils.js index 9a5bfad..b3a8a98 100644 --- a/lib/protobuf-decoder/varintUtils.js +++ b/lib/protobuf-decoder/varintUtils.js @@ -1,23 +1,23 @@ export function decodeVarint(buffer, offset) { - let res = 0; - let shift = 0; - let byte = 0; + let res = 0; + let shift = 0; + let byte = 0; - do { - if (offset >= buffer.length) { - throw new RangeError("Index out of bound decoding varint"); - } + do { + if (offset >= buffer.length) { + throw new RangeError("Index out of bound decoding varint"); + } - byte = buffer[offset++]; + byte = buffer[offset++]; - const multiplier = 2 ** shift; - const thisByteValue = (byte & 0x7f) * multiplier; - shift += 7; - res = res + thisByteValue; - } while (byte >= 0x80); + const multiplier = 2 ** shift; + const thisByteValue = (byte & 0x7f) * multiplier; + shift += 7; + res = res + thisByteValue; + } while (byte >= 0x80); - return { - value: res, - length: shift / 7 - }; + return { + value: res, + length: shift / 7 + }; }