Documentation ¶
Index ¶
- func Marshal(pb proto.Message, options ...MarshalerOption) ([]byte, error)
- func MarshalIndent(pb proto.Message, prefix, indent string, options ...MarshalerOption) ([]byte, error)
- func Unmarshal(data []byte, pb proto.Message, options ...UnmarshalerOption) error
- type EmptyMarshalerOption
- type EmptyUnmarshalerOption
- type Marshaler
- type MarshalerOption
- func WithMarshalAnyResolver(anyResolver jsonpb.AnyResolver) MarshalerOption
- func WithMarshalEmitDefaults(emitDefaults bool) MarshalerOption
- func WithMarshalEnumsAsInts(enumsAsInts bool) MarshalerOption
- func WithMarshalIndent(indent string) MarshalerOption
- func WithMarshalOrigName(origName bool) MarshalerOption
- type MarshalerOptionFunc
- type Unmarshaler
- type UnmarshalerOption
- type UnmarshalerOptionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
func Marshal(pb proto.Message, options ...MarshalerOption) ([]byte, error)
Marshal returns the JSON encoding of v.
func MarshalIndent ¶
func MarshalIndent(pb proto.Message, prefix, indent string, options ...MarshalerOption) ([]byte, error)
MarshalIndent is like Marshal but applies Indent to format the output. Each JSON element in the output will begin on a new line beginning with prefix followed by one or more copies of indent according to the indentation nesting.
Types ¶
type EmptyMarshalerOption ¶
type EmptyMarshalerOption struct{}
EmptyMarshalerOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EmptyUnmarshalerOption ¶
type EmptyUnmarshalerOption struct{}
EmptyUnmarshalerOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type Marshaler ¶
Marshaler is a configurable object for converting between protocol buffer objects and a JSON representation for them.
func (*Marshaler) ApplyOptions ¶
func (o *Marshaler) ApplyOptions(options ...MarshalerOption) *Marshaler
type MarshalerOption ¶
type MarshalerOption interface {
// contains filtered or unexported methods
}
A MarshalerOption sets options.
func WithMarshalAnyResolver ¶
func WithMarshalAnyResolver(anyResolver jsonpb.AnyResolver) MarshalerOption
A custom URL resolver to use when marshaling Any messages to JSON. If unset, the default resolution strategy is to extract the fully-qualified type name from the type URL and pass that to proto.MessageType(string).
func WithMarshalEmitDefaults ¶
func WithMarshalEmitDefaults(emitDefaults bool) MarshalerOption
Whether to render fields with zero values.
func WithMarshalEnumsAsInts ¶
func WithMarshalEnumsAsInts(enumsAsInts bool) MarshalerOption
Whether to render enum values as integers, as opposed to string values.
func WithMarshalIndent ¶
func WithMarshalIndent(indent string) MarshalerOption
A string to indent each level by. The presence of this field will also cause a space to appear between the field separator and value, and for newlines to be appear between fields and array elements.
func WithMarshalOrigName ¶
func WithMarshalOrigName(origName bool) MarshalerOption
Whether to use the original (.proto) name for fields.
type MarshalerOptionFunc ¶
type MarshalerOptionFunc func(*Marshaler)
MarshalerOptionFunc wraps a function that modifies Marshaler into an implementation of the MarshalerOption interface.
type Unmarshaler ¶
type Unmarshaler struct {
jsonpb.Unmarshaler
}
Unmarshaler is a configurable object for converting from a JSON representation to a protocol buffer object.
func (*Unmarshaler) ApplyOptions ¶
func (o *Unmarshaler) ApplyOptions(options ...UnmarshalerOption) *Unmarshaler
type UnmarshalerOption ¶
type UnmarshalerOption interface {
// contains filtered or unexported methods
}
A UnmarshalerOption sets options.
func WithUnmarshalAllowUnknownFields ¶
func WithUnmarshalAllowUnknownFields(allowUnknownFields bool) UnmarshalerOption
func WithUnmarshalAnyResolver ¶
func WithUnmarshalAnyResolver(anyResolver jsonpb.AnyResolver) UnmarshalerOption
A custom URL resolver to use when marshaling Any messages to JSON. If unset, the default resolution strategy is to extract the fully-qualified type name from the type URL and pass that to proto.MessageType(string).
type UnmarshalerOptionFunc ¶
type UnmarshalerOptionFunc func(*Unmarshaler)
UnmarshalerOptionFunc wraps a function that modifies Unmarshaler into an implementation of the UnmarshalerOption interface.