Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discrepancy between protobuf.js and various other encoders #581

Closed
ghost opened this issue Dec 22, 2016 · 1 comment
Closed

discrepancy between protobuf.js and various other encoders #581

ghost opened this issue Dec 22, 2016 · 1 comment
Labels

Comments

@ghost
Copy link

ghost commented Dec 22, 2016

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
@ghost
Copy link
Author

ghost commented Dec 22, 2016

Tested with the latest commit, works as expected.
Thanks for the fast response!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant