Skip to content

Releases: ameliaikeda/typhon

Protocol buffer support

13 Sep 10:40
da9c9e1
Compare
Choose a tag to compare

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; or
  • Content-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; and
  • Content-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 to string ("DEFAULT" instead of 0 etc), but will accept either when unmarshalling.

See https://developers.google.com/protocol-buffers/docs/proto3#json for more information.