Using protobuf.js version: 6.2.1 (latest)
When encoding messages which only contain optional properties with default values or null values, the protobuf.js library strips the message from the wire and thus the generated output is different.
Proto definition:
message Message
{
optional messageA MessageA = 1;
optional messageB MessageB = 2;
}
message messageA
{
optional bool valueA = 1;
}
message messageB
{
optional bool valueB = 1;
}
Buffer message:
{
"MessageA": null,
"MessageB": {
"valueB": null
}
}
The binary output of the library is "" (empty buffer).
Expected binary output is "0001 0010 0000 0000" (0x1200)
Another way to duplicate the behaviour is to decode the 0x1200 message with the library and the provided proto and then encoding it again, the output differs from the input. How can we configure the library to generate the expected output (0x1200)
Code extract:
var testBuffer = Buffer.from('1200', 'hex');
var protoMsg = root.lookup('Message');
var message = protoMsg.decode(testBuffer); // Message contains subnodes MessageA and MessageB
var buffer = protoMsg.encode(message).finish(); // Buffer is empty after encoding
Using protobuf.js version: 6.2.1 (latest)
When encoding messages which only contain optional properties with default values or null values, the protobuf.js library strips the message from the wire and thus the generated output is different.
Proto definition:
Buffer message:
The binary output of the library is "" (empty buffer).
Expected binary output is "0001 0010 0000 0000" (0x1200)
Another way to duplicate the behaviour is to decode the 0x1200 message with the library and the provided proto and then encoding it again, the output differs from the input. How can we configure the library to generate the expected output (0x1200)
Code extract: