Documentation ¶
Index ¶
- type Codec
- func (*Codec) ContentType(_ interface{}) string
- func (c *Codec) Delimiter() []byte
- func (c *Codec) Marshal(v interface{}) ([]byte, error)
- func (c *Codec) NewDecoder(r io.Reader) codec.Decoder
- func (c *Codec) NewEncoder(w io.Writer) codec.Encoder
- func (c *Codec) Unmarshal(data []byte, v interface{}) error
- type DecoderWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec struct { protojson.MarshalOptions protojson.UnmarshalOptions }
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 ¶
ContentType always Returns "application/json; charset=utf-8".
func (*Codec) NewDecoder ¶
NewDecoder returns a Decoder which reads JSON stream from "r".
func (*Codec) NewEncoder ¶
NewEncoder returns an Encoder which writes JSON stream into "w".
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 interface{}) error
Decode wraps the embedded decoder's Decode method to support protos using a jsonpb.Unmarshaler.