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

protobufjs6, oneof and default values #542

Closed
jonathon-love opened this issue Dec 11, 2016 · 2 comments
Closed

protobufjs6, oneof and default values #542

jonathon-love opened this issue Dec 11, 2016 · 2 comments
Labels

Comments

@jonathon-love
Copy link
Contributor

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.

@dcodeIO
Copy link
Member

dcodeIO commented Dec 11, 2016

Oneof support is still a bit meh. This will require additional changes.

@dcodeIO
Copy link
Member

dcodeIO commented Dec 13, 2016

This should be working now.

@dcodeIO dcodeIO closed this as completed Dec 13, 2016
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

2 participants