encoding

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProtobufMediaType is the Protobuf serialization format media type.
	ProtobufMediaType = "application/x-protobuf"
	// JSONMediaType is the JSON serialiation format media type.
	JSONMediaType = "application/json"
)

Variables

View Source
var (
	// ProtobufCodec is the Mesos scheduler API Protobufs codec.
	ProtobufCodec = Codec{
		Name:       "protobuf",
		MediaTypes: [2]string{ProtobufMediaType, ProtobufMediaType},
		NewEncoder: NewProtobufEncoder,
		NewDecoder: NewProtobufDecoder,
	}
	// JSONCodec is the Mesos scheduler API JSON codec.
	JSONCodec = Codec{
		Name:       "json",
		MediaTypes: [2]string{JSONMediaType, JSONMediaType},
		NewEncoder: NewJSONEncoder,
		NewDecoder: NewJSONDecoder,
	}
)

Functions

This section is empty.

Types

type Codec

type Codec struct {
	// Name holds the codec name.
	Name string
	// MediaTypes holds the media types of the codec encoding and decoding
	// formats, respectively.
	MediaTypes [2]string
	// NewEncoder returns a new encoder for the defined media type.
	NewEncoder func(io.Writer) Encoder
	// NewDecoder returns a new decoder for the defined media type.
	NewDecoder func(framing.Reader) Decoder
}

A Codec composes encoding and decoding of a serialization format.

func (*Codec) String

func (c *Codec) String() string

String implements the fmt.Stringer interface.

type Decoder

type Decoder interface {
	Decode(Unmarshaler) error
}

A Decoder decodes a given Unmarshaler or returns an error in case of failure.

func NewJSONDecoder

func NewJSONDecoder(r framing.Reader) Decoder

NewJSONDecoder returns a new Decoder of JSON messages read from the given io.Reader to Events.

func NewProtobufDecoder

func NewProtobufDecoder(r framing.Reader) Decoder

NewProtobufDecoder returns a new Decoder of Protobuf messages read from the given io.Reader to Events.

type DecoderFunc

type DecoderFunc func(Unmarshaler) error

DecoderFunc is the functional adapter for Decoder

func (DecoderFunc) Decode

func (f DecoderFunc) Decode(u Unmarshaler) error

Decode implements the Decoder interface

type Encoder

type Encoder interface {
	Encode(Marshaler) error
}

An Encoder encodes a given Marshaler or returns an error in case of failure.

func NewJSONEncoder

func NewJSONEncoder(w io.Writer) Encoder

NewJSONEncoder returns a new Encoder of Calls to JSON messages written to the given io.Writer.

func NewProtobufEncoder

func NewProtobufEncoder(w io.Writer) Encoder

NewProtobufEncoder returns a new Encoder of Calls to Protobuf messages written to the given io.Writer.

type EncoderFunc

type EncoderFunc func(Marshaler) error

EncoderFunc is the functional adapter for Encoder

func (EncoderFunc) Encode

func (f EncoderFunc) Encode(m Marshaler) error

Encode implements the Encoder interface

type Marshaler

type Marshaler interface {
	pb.Marshaler
	json.Marshaler
}

Marshaler composes the supported marshaling formats.

type Unmarshaler

type Unmarshaler interface {
	pb.Unmarshaler
	json.Unmarshaler
}

Unmarshaler composes the supporter unmarshaling formats.

Directories

Path Synopsis
Package proto implements protobuf utilities such as functional options to construct complex structs and encoders and decoders composable with io.ReadWriters.
Package proto implements protobuf utilities such as functional options to construct complex structs and encoders and decoders composable with io.ReadWriters.

Jump to

Keyboard shortcuts

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