Releases: ameliaikeda/typhon
Protocol buffer support
This adds automatic protocol buffer support in Typhon.
Supports both "current" and "legacy" protobuf, but where possible for best results use "current":
- Current:
google.golang.org/protobuf/proto.Message
- Legacy:
github.com/golang/protobuf/proto.Message
If either proto.Message
is used, we only opt into wire format if:
Accept: application/protobuf
is set on the request; orContent-Type: application/protobuf
is on a response
If google.golang.org/protobuf/proto.Message
is used, we opt into protojson encoding if:
Accept: application/protobuf
is not set on a request; andContent-Type: application/protobuf
is not set on a response.
For backwards compatibility reasons, github.com/golang/protobuf/proto.Message
DOES NOT support protojson encoding.
encoding/protojson
Protocol buffers cannot be serialised directly to JSON. Instead, we use the
google.golang.org/protobuf/encoding/protojson
package. This package ensures we conform to the encoding requirements for protobuf.If using
google.golang.org/protobuf/proto.Message
, the following are backwards compatibility breaks:
- Field names will change to
camelCase
in JSON.- enums will change from
int
tostring
("DEFAULT"
instead of0
etc), but will accept either when unmarshalling.See https://developers.google.com/protocol-buffers/docs/proto3#json for more information.