protomime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BinaryMediaTypes = []string{
	"application/vnd.google.protobuf",
	"application/x-protobuf",
}

BinaryMediaTypes is the set of media types that refer to the standard binary Protocol Buffers encoding.

View Source
var JSONMediaTypes = []string{
	"application/json",
}

JSONMediaTypes is the set of media types that refer to the JSON Protocol Buffers encoding.

View Source
var MediaTypes []string

MediaTypes is the set of all media types that can be used for marshaling and unmarshaling Protocol Buffers messages, in order of preference.

View Source
var TextMediaTypes = []string{
	"text/plain",
}

TextMediaTypes is the set of media types that refer to the text-based Protocol Buffers encoding.

Functions

func FormatMediaType

func FormatMediaType(mediaType string, m proto.Message) string

FormatMediaType formats a complete media type, including parameters, to use when marshaling m.

func IsBinary

func IsBinary(mediaType string) bool

IsBinary returns true if the given media-type refers to the standard binary Protocol Buffers encoding.

func IsJSON

func IsJSON(mediaType string) bool

IsJSON returns true if the given media-type refers to the JSON Protocol Buffers encoding.

func IsSupportedMediaType

func IsSupportedMediaType(mediaType string) bool

IsSupportedMediaType if the given media-type is supported.

func IsText

func IsText(mediaType string) bool

IsText returns true if the given media-type refers to the text-based Protocol Buffers encoding.

Types

type Marshaler

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

Marshaler is an interface for marshaling Protocol Buffers messages to a byte slice.

var (
	// BinaryMarshaler is a Marshaler that marshals messages to the binary
	// Protocol Buffers encoding.
	BinaryMarshaler Marshaler = proto.MarshalOptions{}

	// JSONMarshaler is a Marshaler that marshals messages to the JSON Protocol
	// Buffers encoding.
	JSONMarshaler Marshaler = protojson.MarshalOptions{}

	// TextMarshaler is a Marshaler that marshals messages to the text-based
	// Protocol Buffers encoding.
	TextMarshaler Marshaler = prototext.MarshalOptions{
		Multiline: true,
		Indent:    "  ",
	}
)

func MarshalerForMediaType

func MarshalerForMediaType(mediaType string) (Marshaler, bool)

MarshalerForMediaType returns the marshaler to use for the given media type.

type Unmarshaler

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

Unmarshaler is an interface for unmarshaling Protocol Buffers messages from a byte slice.

var (
	// BinaryUnmarshaler is an Unmarshaler that unmarshals messages from the
	// binary Protocol Buffers encoding.
	BinaryUnmarshaler Unmarshaler = proto.UnmarshalOptions{}

	// JSONUnmarshaler is an Unmarshaler that unmarshals messages from the JSON
	// Protocol Buffers encoding.
	JSONUnmarshaler Unmarshaler = protojson.UnmarshalOptions{}

	// TextUnmarshaler is an Unmarshaler that unmarshals messages from the
	// text-based Protocol Buffers encoding.
	TextUnmarshaler Unmarshaler = prototext.UnmarshalOptions{}
)

func UnmarshalerForMediaType

func UnmarshalerForMediaType(mediaType string) (Unmarshaler, bool)

UnmarshalerForMediaType returns the unmarshaler to use for the given media type.

Jump to

Keyboard shortcuts

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