protojson

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrFieldNotHandled      = "field not handled on decoding: %s"
	ErrFieldNotProtoMessage = "field %s is not a proto message"
)

Variables

View Source
var (
	ErrDestinationNotProtoMessage = errors.New("destination is not a proto message")
	ErrNilReader                  = errors.New("nil reader")
	ErrNilMapper                  = errors.New("decoder mapper is nil")
	ErrNilDestinationInstance     = errors.New("nil destination instance")
	ErrNilDestination             = errors.New("nil destination")
)

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(options *Options) *Decoder

NewDecoder creates a new Decoder instance

Parameters:

  • options: the additional settings for the decoder implementation

Returns:

  • *Decoder: The decoder instance

func (Decoder) Decode

func (d Decoder) Decode(
	reader any,
	dest any,
) error

Decode decodes the JSON body from an any value and stores it in the destination

Parameters:

  • reader: The body to decode
  • dest: The destination to store the decoded body

Returns:

  • error: The error if any

func (Decoder) DecodeReader

func (d Decoder) DecodeReader(
	reader io.Reader,
	dest any,
) error

DecodeReader decodes a JSON body from a reader into a destination

Parameters:

  • reader: The io.Reader to read the body from
  • dest: The destination to decode the body into

Returns:

  • error: The error if any

type Mapper added in v0.2.0

type Mapper struct {
	// contains filtered or unexported fields
}

Mapper is the struct to hold precomputed marshal by reflection functions

func NewMapper added in v0.2.0

func NewMapper(
	destinationInstance any,
) (*Mapper, error)

NewMapper creates a new Mapper instance

Parameters:

- destinationInstance: the destination instance to create the mapper for

Returns:

- *Mapper: the new Mapper instance - error: the error if any

func (*Mapper) UnmarshalByReflection added in v0.2.0

func (m *Mapper) UnmarshalByReflection(
	body []byte,
	dest any,
	unmarshalOptions *protojson.UnmarshalOptions,
) error

UnmarshalByReflection unmarshal JSON data into a destination using reflection

Parameters:

  • body: The JSON data to unmarshal
  • dest: The destination to unmarshal the JSON data into
  • unmarshalOptions: Options for unmarshalling proto messages (optional, can be nil)

Returns:

  • error: The error if any

type Options added in v0.2.0

type Options struct {
	// contains filtered or unexported fields
}

Options are the additional settings for the decoder implementation

func NewOptions added in v0.2.0

func NewOptions(
	cache bool,
) *Options

NewOptions creates a new Options instance

Parameters:

  • cache: indicates whether to cache the precompute unmarshal by reflection functions

Returns:

- *Options: the new Options instance

Jump to

Keyboard shortcuts

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