protobuf.js
protobuf.js copied to clipboard
Ext descriptor.proto util parses all proto2 fields as packed
protobuf.js version: 6.11.2
While trying to parse a proto2 message and convert it to its descriptor.proto format, all field descriptors are marked as packed = true. I would expect this to happen only for repeated fields, or even only those that are explicitly marked as packed in the equivalent .proto file
Example
comments.proto
syntax = "proto2";
message Test1 {
required string field1 = 1;
required uint32 field2 = 2;
required bool field3 = 3;
}
index.js
"use strict";
const protobuf = require('protobufjs');
const ext = require('protobufjs/ext/descriptor');
const main = async () => {
const root = await new protobuf.Root().load("comments.proto");
const Comment = root.lookupType('Test1');
const descriptor = Comment.toDescriptor('proto2').toJSON();
console.log(descriptor);
}
main()
Running the code above produces the following descriptor proto:
{
"name": "Test1",
"field": [
{
"name": "field1",
"number": 1,
"label": "LABEL_REQUIRED",
"type": "TYPE_STRING",
"options": {
"packed": true
}
},
{
"name": "field2",
"number": 2,
"label": "LABEL_REQUIRED",
"type": "TYPE_UINT32",
"options": {
"packed": true
}
},
{
"name": "field3",
"number": 3,
"label": "LABEL_REQUIRED",
"type": "TYPE_BOOL",
"options": {
"packed": true
}
}
]
}
packed option should not be set for given input file.
This is happening due to the outdated logic found here