-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Enums should default to first defined value not the one with tag = 0 #613
Comments
On the client side converting to buffer and parsing the buffer back yields the correct proto/json (1st one). Since the server side is using Google's protobuf library, I suspect protobufJS to be having the bug, but we could be wrong. |
{
"operation": "AND",
"valueSet": [{
"dimension": "DIMENSION_1",
"value": [ 2 ]
}]
} Buffer:
Looks ok to me. The optional enum defaults are most likely encoded on the wire because these are set as strings without using See: {
"operation": 0,
"valueSet": [{
"dimension": 0,
"value": [ 2 ]
}]
} Buffer:
Which is the same without optional enum defaults. Correct usage example: var protobuf = require("..");
var msg = {
operation: "AND",
valueSet: [{
dimension: "DIMENSION_1",
value: [2]
}]
};
var root = protobuf.loadSync(require.resolve("./issue.proto"));
var Filter = root.lookup("Filter");
var reason = Filter.verify(msg);
if (reason !== null)
console.log("message is invalid when calling just encode because: " + reason);
var buf = Filter.encode(Filter.from(msg)).finish();
console.log(buf); |
ha. it turns out the enum is a bit weird. number 18 is defined at the top and on the server side it is being defaulted to DIMENSION_18 when you call
enum Dimension {
DIMENSION_18 = 18;
DIMENSION_1 = 0;
} |
I see. Optional enums with default values are not encoded on the wire, so this seems to be the underlying issue. |
Hmm yeah, in this case there is no Or Google's internal java code could be tickling this bug, Oh dear! |
From Google's developer guide:
https://developers.google.com/protocol-buffers/docs/proto3#default Seems that the official implementation just takes the first defined, while protobuf.js uses 0. This still shouldn't result in an invalid wire format, though. Hmm. |
The enum issue is fixed on the server side by sorting our enum defs for now, but yes you should use the first defined as the default in js as well. The int64 wire type issue is red-herring, that seems to be a bug in our code which was sending wrong data. I will rename the bug |
On the client side I am encoding
On the server (in java) I am receiving
Here is the proto used. Stripped down for simplicity
The text was updated successfully, but these errors were encountered: