Documentation ¶
Overview ¶
Package protobuf contains codec implementations for protocol buffers types.
Index ¶
Constants ¶
const JSONBasicMediaType = "application/vnd.google.protobuf+json"
JSONBasicMediaType is the type and subtype portion of the media-type used to identify data encoded using JSON.
const NativeBasicMediaType = "application/vnd.google.protobuf"
NativeBasicMediaType is the type and subtype portion of the media-type used to identify data encoded using the native protocol buffers wire format.
const TextBasicMediaType = "text/vnd.google.protobuf"
TextBasicMediaType is the type and subtype portion of the media-type used to identify data encoded in the protocol buffers text format.
Variables ¶
var DefaultJSONCodec = Codec{ MediaType: JSONBasicMediaType, Marshaler: DefaultJSONMarshaler, Unmarshaler: DefaultJSONUnmarshaler, }
DefaultJSONCodec is a marshalkit.Codec that marshals protocol buffers messages in JSON format.
See https://developers.google.com/protocol-buffers/docs/proto3#json.
var DefaultJSONMarshaler = protojson.MarshalOptions{ UseProtoNames: true, }
DefaultJSONMarshaler is the marshaler used by DefaultJSONCodec.
var DefaultJSONUnmarshaler = protojson.UnmarshalOptions{ DiscardUnknown: true, }
DefaultJSONUnmarshaler is the unmarshaler used by DefaultJSONCodec.
var DefaultNativeCodec = Codec{}
DefaultNativeCodec is a marshalkit.Codec that marshals protocol buffers messages using the native protocol buffers wire format.
var DefaultNativeMarshaler = proto.MarshalOptions{}
DefaultNativeMarshaler is the marshaler used by DefaultNativeCodec, and by Codec if no marshaler is provided.
var DefaultNativeUnmarshaler = proto.UnmarshalOptions{}
DefaultNativeUnmarshaler is the unmarshaler used by DefaultNativeCodec, and by Codec if no unmarshaler is provided.
var DefaultTextCodec = Codec{ MediaType: TextBasicMediaType, Marshaler: DefaultTextMarshaler, Unmarshaler: DefaultTextUnmarshaler, }
DefaultTextCodec is a marshalkit.Codec that marshals protocol buffers messages in text format.
var DefaultTextMarshaler = prototext.MarshalOptions{ Multiline: true, }
DefaultTextMarshaler is the marshaler used by DefaultTextCodec.
var DefaultTextUnmarshaler = prototext.UnmarshalOptions{ DiscardUnknown: true, }
DefaultTextUnmarshaler is the unmarshaler used by DefaultTextCodec.
Functions ¶
This section is empty.
Types ¶
type Codec ¶ added in v0.7.0
type Codec struct { // MediaType is the type and subtype portion of the media-type used to // identify data encoded by this codec. If it is empty, NativeMediaType is // used. MediaType string // Marshaler is the marshaler used to marshal messages. // If it is nil, DefaultNativeMarshaler is used. Marshaler Marshaler // Unmarshaler is the JSON unmarshaler used to unmarshal messages. // If it is nil, DefaultNativeUnmarshaler is used. Unmarshaler Unmarshaler }
Codec is an implementation of marshalkit.Codec that encodes Protocol Buffers messages.
It supports three common protocol buffers formats, that is, the native binary format, the JSON "mapping", and the text-based encoding scheme.
See DefaultNativeCodec, DefaultJSONCodec and DefaultTextCodec, respectively.
func (Codec) BasicMediaType ¶ added in v0.7.0
BasicMediaType returns the type and subtype portion of the media-type used to identify data encoded by this codec.