proto

package
v2.679.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 6 Imported by: 0

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

func (e *Binary) Decode(r io.Reader, v any) error

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

func (e *Binary) Encode(w io.Writer, v any) error

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

func (e *JSON) Decode(r io.Reader, v any) error

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

func (e *JSON) Encode(w io.Writer, v any) error

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 Message added in v2.654.0

type Message = proto.Message

Message is an alias for proto.Message.

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

func (e *Text) Decode(r io.Reader, v any) error

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

func (e *Text) Encode(w io.Writer, v any) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL