From c4765dba833fe37e9842872a7a4a2c2045421783 Mon Sep 17 00:00:00 2001 From: Pedro Pedruzzi <240791+pedropedruzzi@users.noreply.github.com> Date: Wed, 9 Jul 2025 23:46:11 -0300 Subject: [PATCH] Fix protobuf parser for new WA fields and unknown ones --- dump-messages.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dump-messages.js b/dump-messages.js index 5ed6fd6..a0cbf68 100644 --- a/dump-messages.js +++ b/dump-messages.js @@ -38,13 +38,10 @@ function decodeProtobufWithState(spec, s) { const result = {}; while (s.cursor < s.length) { - const header = s.data.getUint8(s.cursor); s.cursor += 1; + const header = decodeVarint(s); const field = header >> 3; const wireType = header & 0x7; - const fieldSpec = spec[field]; - if (fieldSpec === undefined) { - throw `non-specced field ${field}`; - } + const fieldSpec = spec[field] ?? { type: "bytes", name: `unknown_${field}` }; let fieldValue = null; if (wireType == 0) { // varint (int32, int64, uint32, uint64, sint32, sint64, bool, enum) fieldValue = decodeVarint(s); @@ -63,6 +60,9 @@ if (fieldSpec.type === "string") { fieldValue = utf8Decoder.decode(new DataView(s.data.buffer, s.data.byteOffset + s.cursor, length)); s.cursor += length; + } else if (fieldSpec.type === "bytes") { + fieldValue = `(${length} bytes)`; + s.cursor += length; } else if (typeof fieldSpec.type === "object") { fieldValue = decodeProtobufWithState(fieldSpec.type, { data: new DataView(s.data.buffer, s.data.byteOffset + s.cursor, length),