Documentation
¶
Overview ¶
Package bytes provides byte-oriented encoding helpers and adapters used by go-service.
Start with the package-level constructors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encoder ¶
type Encoder struct{}
Encoder encodes and decodes values by delegating to io.WriterTo and io.ReaderFrom.
This encoder does not perform any framing, escaping, or format conversion. It simply forwards the Encode/Decode call to the value itself.
func NewEncoder ¶
func NewEncoder() *Encoder
NewEncoder constructs a passthrough encoder for stream-capable types.
This encoder is intended for values that can write themselves to an io.Writer and/or read themselves from an io.Reader via the shared go-service io package aliases:
- io.WriterTo for Encode
- io.ReaderFrom for Decode
It is useful when you want to treat a value as its own codec (for example when caching or transporting pre-serialized payloads) while still satisfying the go-service encoding.Encoder interface.
func (*Encoder) Decode ¶
Decode reads from r into v when v implements io.ReaderFrom.
If v does not implement io.ReaderFrom, Decode returns github.com/alexfalkowski/go-service/v2/encoding/errors.ErrInvalidType. If v also implements io.Resetter, Decode resets it before reading so the destination is repopulated rather than appended to. Any error returned by ReadFrom is returned.
func (*Encoder) Encode ¶
Encode writes v to w when v implements io.WriterTo.
If v does not implement io.WriterTo, Encode returns github.com/alexfalkowski/go-service/v2/encoding/errors.ErrInvalidType. Any error returned by WriteTo is returned.