Documentation
¶
Overview ¶
Package proto provides Protocol Buffers (protobuf) encoding helpers and adapters used by go-service.
This package integrates protobuf encoding/decoding behind the go-service encoding abstraction.
Start with the package-level constructors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binary ¶
type Binary struct{}
Binary implements protobuf binary encoding and decoding.
Encode expects v to implement proto.Message and writes the protobuf binary wire format to the writer. Decode expects v to implement proto.Message (typically a pointer to a generated message) and unmarshals the protobuf binary wire format from the reader into v.
func NewBinary ¶
func NewBinary() *Binary
NewBinary constructs a protobuf binary encoder.
This encoder is a thin adapter around google.golang.org/protobuf/proto Marshal/Unmarshal that satisfies github.com/alexfalkowski/go-service/v2/encoding.Encoder.
func (*Binary) Decode ¶
Decode reads protobuf binary (wire format) from r and unmarshals it into v.
If v does not implement proto.Message, Decode returns github.com/alexfalkowski/go-service/v2/encoding/errors.ErrInvalidType without reading from r.
Decode otherwise reads all remaining bytes from r (via io.ReadAll) before unmarshaling.
Any read error from io.ReadAll and any unmarshal error from proto.Unmarshal is returned.
func (*Binary) Encode ¶
Encode writes v as protobuf binary (wire format) to w.
If v does not implement proto.Message, Encode returns github.com/alexfalkowski/go-service/v2/encoding/errors.ErrInvalidType. Any marshaling error from proto.Marshal and any write error from w.Write is returned.
type JSON ¶
type JSON struct{}
JSON implements protobuf JSON encoding and decoding.
Encode expects v to implement proto.Message and writes protobuf JSON to the writer. Decode expects v to implement proto.Message (typically a pointer to a generated message) and unmarshals protobuf JSON from the reader into v.
func NewJSON ¶
func NewJSON() *JSON
NewJSON constructs a protobuf JSON encoder.
This encoder is a thin adapter around google.golang.org/protobuf/encoding/protojson Marshal/Unmarshal that satisfies github.com/alexfalkowski/go-service/v2/encoding.Encoder.
func (*JSON) Decode ¶
Decode reads protobuf JSON from r and unmarshals it into v.
If v does not implement proto.Message, Decode returns github.com/alexfalkowski/go-service/v2/encoding/errors.ErrInvalidType without reading from r.
Decode otherwise reads all remaining bytes from r (via io.ReadAll) before unmarshaling. Unknown protobuf JSON fields are discarded during unmarshal.
Any read error from io.ReadAll and any unmarshal error from protojson.UnmarshalOptions.Unmarshal is returned.
func (*JSON) Encode ¶
Encode writes v as protobuf JSON to w.
If v does not implement proto.Message, Encode returns github.com/alexfalkowski/go-service/v2/encoding/errors.ErrInvalidType. Any marshaling error from protojson.Marshal and any write error from w.Write is returned.
type Text ¶
type Text struct{}
Text implements protobuf text encoding and decoding.
Encode expects v to implement proto.Message and writes protobuf text format to the writer. Decode expects v to implement proto.Message (typically a pointer to a generated message) and unmarshals protobuf text format from the reader into v.
func NewText ¶
func NewText() *Text
NewText constructs a protobuf text encoder.
This encoder is a thin adapter around google.golang.org/protobuf/encoding/prototext Marshal/Unmarshal that satisfies github.com/alexfalkowski/go-service/v2/encoding.Encoder.
func (*Text) Decode ¶
Decode reads protobuf text format from r and unmarshals it into v.
If v does not implement proto.Message, Decode returns github.com/alexfalkowski/go-service/v2/encoding/errors.ErrInvalidType without reading from r.
Decode otherwise reads all remaining bytes from r (via io.ReadAll) before unmarshaling. Unknown protobuf text fields are discarded during unmarshal.
Any read error from io.ReadAll and any unmarshal error from prototext.UnmarshalOptions.Unmarshal is returned.
func (*Text) Encode ¶
Encode writes v as protobuf text format to w.
If v does not implement proto.Message, Encode returns github.com/alexfalkowski/go-service/v2/encoding/errors.ErrInvalidType. Any marshaling error from prototext.Marshal and any write error from w.Write is returned.