protobuf

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package protobuf contains codec implemenentations for protocol buffers types.

Index

Constants

View Source
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.

View Source
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.

View Source
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

View Source
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.

View Source
var DefaultJSONMarshaler = protojson.MarshalOptions{
	UseProtoNames: true,
}

DefaultJSONMarshaler is the marshaler used by DefaultJSONCodec.

View Source
var DefaultJSONUnmarshaler = protojson.UnmarshalOptions{
	DiscardUnknown: true,
}

DefaultJSONUnmarshaler is the unmarshaler used by DefaultJSONCodec.

View Source
var DefaultNativeCodec = Codec{}

DefaultNativeCodec is a marshalkit.Codec that marshals protocol buffers messages using the native protocol buffers wire format.

View Source
var DefaultNativeMarshaler = proto.MarshalOptions{}

DefaultNativeMarshaler is the marshaler used by DefaultNativeCodec, and by Codec if no marshaler is provided.

View Source
var DefaultNativeUnmarshaler = proto.UnmarshalOptions{}

DefaultNativeUnmarshaler is the unmarshaler used by DefaultNativeCodec, and by Codec if no unmarshaler is provided.

View Source
var DefaultTextCodec = Codec{
	MediaType:   TextBasicMediaType,
	Marshaler:   DefaultTextMarshaler,
	Unmarshaler: DefaultTextUnmarshaler,
}

DefaultTextCodec is a marshalkit.Codec that marshals protocol buffers messages in text format.

View Source
var DefaultTextMarshaler = prototext.MarshalOptions{
	Multiline: true,
}

DefaultTextMarshaler is the marshaler used by DefaultTextCodec.

View Source
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

func (c Codec) BasicMediaType() string

BasicMediaType returns the type and subtype portion of the media-type used to identify data encoded by this codec.

func (Codec) Marshal added in v0.7.0

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

Marshal returns the binary representation of v.

func (Codec) Query added in v0.7.0

func (Codec) Query(types []reflect.Type) codec.Capabilities

Query returns the capabilities of the codec for the given types.

func (Codec) Unmarshal added in v0.7.0

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

Unmarshal decodes a binary representation into v.

type Marshaler added in v0.7.0

type Marshaler interface {
	Marshal(proto.Message) ([]byte, error)
}

Marshaler is an interface for marshaling protocol buffers messages.

type Unmarshaler added in v0.7.0

type Unmarshaler interface {
	Unmarshal([]byte, proto.Message) error
}

Marshaler is an interface for unmarshaling protocol buffers messages.

Jump to

Keyboard shortcuts

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