Gogo support?
maros7 opened this issue · comments
Hi, would you consider adding official support for https://github.com/gogo/protobuf? Using inprocgrpc causes panic when .proto
s are compiled with gogo/protobuf and not golang/protobuf. I can of course create my own version of inprocgrpc, but would be good I guess to have it in this repository. I can look into submitting a PR.
I do not want to add any dependency from packages in this repo to gogo/protobuf -- that is just dependency baggage/bloat for people that use golang/protobuf.
One option would be to make the message cloning pluggable. That way your code could provide a custom cloner that used gogo/protobuf without adding it as a dependency to inprocgrpc itself. I'll look into that.
Also note that this will likely be addressed in the future: one of the objectives of the v2 API of the protobuf runtime is to support other kinds of proto messages -- such as those generated by gogo's protoc plugin, or even dynamic messages.
Fair enough. And thanks for the detailed answer. I’ll just create a custom channel for now.
@maros7, can you try pull down my branch for #22 and verify whether that works for you?
I think you'll need a custom cloner that looks basically likes like so:
import (
"fmt"
"reflect"
"github.com/gogo/protobuf/proto"
)
type gogoCloner struct{}
func (gogoCloner) Copy(out, in interface{}) error {
if reflect.TypeOf(in) != reflect.TypeOf(out) {
return fmt.Errorf("type mismatch: %T != %T", in, out)
}
if reflect.ValueOf(out).IsNil() {
return fmt.Errorf("out must not be nil")
}
inM := in.(proto.Message)
outM := out.(proto.Message)
outM.Reset()
proto.Merge(outM, inM)
return nil
}
func (gogoCloner) Clone(in interface{}) (interface{}, error) {
return proto.Clone(in.(proto.Message)), nil
}
Thanks. I will try this and get back to you.
Hey. Yes, this solves my issue. Thanks!
@maros7, I just merged that branch. But be aware that I made some non-trivial changes to the Cloner
interface. I revised the example above so that it should work -- just make sure you grab the latest changes to that gogo example. (Most urgently, I swapped the order of args to the Copy
method, so its signature is now consistent with the copy
builtin.)