jsonpb

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

Codec is a Marshaler which marshals/unmarshals into/from JSON with the "google.golang.org/protobuf/encoding/protojson" marshaler. It supports the full functionality of protobuf unlike JSONBuiltin.

The NewDecoder method returns a DecoderWrapper, so the underlying *json.Decoder methods can be used.

func (*Codec) ContentType

func (*Codec) ContentType(_ any) string

ContentType always Returns "application/json; charset=utf-8".

func (*Codec) Delimiter

func (c *Codec) Delimiter() []byte

Delimiter for newline encoded JSON streams.

func (*Codec) Marshal

func (c *Codec) Marshal(v any) ([]byte, error)

func (*Codec) NewDecoder

func (c *Codec) NewDecoder(r io.Reader) codec.Decoder

NewDecoder returns a Decoder which reads JSON stream from "r".

func (*Codec) NewEncoder

func (c *Codec) NewEncoder(w io.Writer) codec.Encoder

NewEncoder returns an Encoder which writes JSON stream into "w".

func (*Codec) Unmarshal

func (c *Codec) Unmarshal(data []byte, v any) error

Unmarshal unmarshals JSON "data" into "v"

type DecoderWrapper

type DecoderWrapper struct {
	*json.Decoder
	protojson.UnmarshalOptions
}

DecoderWrapper is a wrapper around a *json.Decoder that adds support for protos to the Decode method.

func (DecoderWrapper) Decode

func (d DecoderWrapper) Decode(v any) error

Decode wraps the embedded decoder's Decode method to support protos using a jsonpb.Unmarshaler.

Jump to

Keyboard shortcuts

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