Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dump-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
Expand Down