| 365 | }; |
| 366 | |
| 367 | let readProtoVarint = function (bytes, offset) { |
| 368 | let result = 0n; |
| 369 | let shift = 0n; |
| 370 | let current = offset; |
| 371 | while (current < bytes.length) { |
| 372 | let byte = bytes[current++]; |
| 373 | result |= BigInt(byte & 0x7f) << shift; |
| 374 | if ((byte & 0x80) === 0) { |
| 375 | return { value: result, next: current }; |
| 376 | } |
| 377 | shift += 7n; |
| 378 | if (shift > 70n) { |
| 379 | throw new Error('Protobuf varint 过长或格式异常'); |
| 380 | } |
| 381 | } |
| 382 | throw new Error('Protobuf varint 未完整结束'); |
| 383 | }; |
| 384 | |
| 385 | let decodeUtf8Bytes = function (bytes) { |
| 386 | try { |