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

gogofast generated proto files aren't compatible with "github.com/golang/protobuf/jsonpb" #188

Closed
gyuho opened this issue Jul 15, 2016 · 3 comments

Comments

@gyuho
Copy link

gyuho commented Jul 15, 2016

This code only works when WatchRequest is generated with gofast but doesn't work when it is generated with gogofast:

protoc --gofast_out=plugins=grpc:. \
    --proto_path=$GOPATH/src:$GOPATH/src/github.com/gogo/protobuf/protobuf:. \
    *.proto;

protoc --gogofast_out=plugins=grpc:. \
    --proto_path=$GOPATH/src:$GOPATH/src/github.com/gogo/protobuf/protobuf:. \
    *.proto;
syntax = "proto3";
package main;

import "github.com/gogo/protobuf/gogoproto/gogo.proto";

message WatchRequest {
  oneof request_union {
    WatchCreateRequest create_request = 1;
  }
}

message WatchCreateRequest {
  bytes key = 1;
}
import (
    "fmt"
    "log"

    "github.com/golang/protobuf/jsonpb"
)

func main() {
    const input = `{"create_request": {"key": "Zm9v"}}`
    var req WatchRequest
    if err := jsonpb.UnmarshalString(input, &req); err != nil {
        log.Fatal(err)
    }
    fmt.Printf("success with %+v\n", req.RequestUnion)
    // success with &{CreateRequest:key:"foo" } or unknown field "create_request" in main.WatchRequest
}

Here's the sample proto and generated files and script to reproduce this issue:

golang-vs-gogo-proto-issue.tar.gz

Reference

@awalterschulze
Copy link
Member

Does this fix your problem?
b5aec62

@gyuho
Copy link
Author

gyuho commented Jul 18, 2016

Yes it does. Found some other issue (etcd-io/etcd#5969), but I don't think it's related to gogo/protobuf.

Thanks a lot, @awalterschulze!

@gyuho gyuho closed this as completed Jul 18, 2016
@awalterschulze
Copy link
Member

My pleasure :)

Just a note: I only used your issue report (which was great) and not the zip. I tried using the zip file to help me debug and fix the issue, but it was not really useful. So you can save yourself the effort next time. If you really want to make an effort a pull request with a failing test (in the test folder) will help me the most, but your report was perfect and already a big help.

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

No branches or pull requests

2 participants