hi,
with the following .proto file:
message Message {
oneof c {
int32 a = 1;
int32 b = 2;
}
}
compiled into a static-module (that's just what i'm using, but i expect other code paths will have the same issue), and invoked thus:
const Root = require('./awesome_pb.js');
let message = new Root.Message();
message.a = 0;
let bytes = Root.Message.encode(message).finish();
console.log(bytes)
bytes ends up an empty buffer.
this is understandable, because 0 is the default value for a, but it also means that whenever a oneof is set to it's default, it is no longer possible to determine which value was set.
i don't think the google protobuf documentation is clear on what the correct behaviour here is (but i haven't had a very good look), but the behaviour of the google protobuf is to encode the zero value (which i think makes sense).
what do you think? i'm happy to create a PR for it.
hi,
with the following .proto file:
compiled into a
static-module(that's just what i'm using, but i expect other code paths will have the same issue), and invoked thus:bytesends up an empty buffer.this is understandable, because 0 is the default value for
a, but it also means that whenever a oneof is set to it's default, it is no longer possible to determine which value was set.i don't think the google protobuf documentation is clear on what the correct behaviour here is (but i haven't had a very good look), but the behaviour of the google protobuf is to encode the zero value (which i think makes sense).
what do you think? i'm happy to create a PR for it.