bytes

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: 3 Imported by: 0

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:

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

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

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

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

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.

Jump to

Keyboard shortcuts

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