package encoding

import "github.com/mesos/mesos-go/api/v1/lib/encoding"

Index

Constants

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

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,
	}
)

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.

Source Files

codec.go

Directories

PathSynopsis
api/v1/lib/encoding/framing
api/v1/lib/encoding/protoPackage proto implements protobuf utilities such as functional options to construct complex structs and encoders and decoders composable with io.ReadWriters.
Version
v0.0.3
Published
Jun 19, 2017
Platform
linux/amd64
Imports
5 packages
Last checked
2 hours ago

Tools for package owners.