-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
allow use of jsonpb for marshaling #79
Comments
Using it would be nice, but note that in my benchmarks, jsonpb is On Tuesday, December 29, 2015, Eric Chiang notifications@github.com wrote:
|
A lot of the overhead comes from checking to ensure the result is actually compliant with protobuf's defined JSON mapping. It's slower, but it's correct :) |
Ya, I know :) Ugh. Programming is no fun :) On Tuesday, December 29, 2015, Eric Chiang notifications@github.com wrote:
|
So, someone needs to build a codegen ala ffjson On Tue, Dec 29, 2015 at 11:24 PM Peter Edge notifications@github.com
|
@peter-edge Thank you for your information. I didn't know that it is that slower. I am thinking of a mechanism which allows users to register/overwrite marshaler per MIME type. |
@yugui can you sketch out what sort of approach you were thinking? I may hack on this soon. |
The |
@yugui @tmc @hbchai don't want to repeat work, but I'd propose what looks like (based on an overly-simple grep) a very small PR: For code generation:
For library code: var (
// DefaultJSONAdapter would wrap stdlib JSON functions
DefaultJSONAdapter = &defaultJSONAdapter{}
// JSONPBAdapter would wrap jsonpb
JSONPBAdapter = &jsonpbAdapter{}
globalJSONAdapter = DefaultJSONAdapter
)
// not trying too hard here with naming or interface definitions, just trying to show the concept
type JSONAdapter interface {
Marshal(proto.Message) ([]byte, error)
Unmarshal([]byte) (proto.Message, error)
}
func SetJSONAdapter(jsonAdapter JSONAdapter) {
globalJSONAdapter = jsonAdapter
}
func jsonMarshal(message proto.Message) ([]byte, error) {
return globalJSONAdapter.Marshal(message)
}
func jsonUnmarshal(data []byte) (proto.Message, error) {
return globalJSONAdapter.Unmarshal(data)
} |
@peter-edge It might make more sense for the choice of library to be a new option to the generated |
Ya actually that might be better :) |
this has implications for swagger specs doesn't it? Should this be described via a custom annotation? |
Is this completed? Can it be closed? |
Yep, see #144. |
github.com/golang/protobuf/jsonpb is a more compliant protobuf -> JSON package than
encoding/json
, and is the only way github.com/golang/protobuf plans to support JSON encoding in the future.See this comment
It would be great to be able to using this package for marshaling. It might even be wise to switch to it entirely.
The text was updated successfully, but these errors were encountered: