marshaling

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package marshaling provides utilities for marshaling and unmarshaling messages and other types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalMessageType

func MarshalMessageType(ma *Marshaler, mt message.Type) (string, error)

MarshalMessageType marshals a message type to its portable representation.

func UnmarshalMessage

func UnmarshalMessage(ma *Marshaler, p Packet) (dogma.Message, error)

UnmarshalMessage returns a message from its binary representation.

func UnmarshalMessageType

func UnmarshalMessageType(ma *Marshaler, n string) (message.Type, error)

UnmarshalMessageType unmarshals a message type from its portable representation.

func UnmarshalMessageTypeFromMediaType

func UnmarshalMessageTypeFromMediaType(ma *Marshaler, mt string) (message.Type, error)

UnmarshalMessageTypeFromMediaType unmarshals a message type from a MIME media-type.

Types

type Codec

type Codec interface {
	// Query returns the capabilities of the codec for the given types.
	Query(types []reflect.Type) CodecCapabilities

	// MediaType returns the media-type used to identify values encoded by this
	// codec.
	MediaType() string

	// Marshal returns the binary representation of v.
	Marshal(v interface{}) ([]byte, error)

	// Unmarshal decodes a binary representation into v.
	Unmarshal(data []byte, v interface{}) error
}

Codec is an interface for encoding and decoding values.

type CodecCapabilities

type CodecCapabilities struct {
	// Types is a map of the support types to their portable type name.
	Types map[reflect.Type]string
}

CodecCapabilities describes the capabilities of a codec as it relates to specific Go types.

type Marshaler

type Marshaler struct {
	// contains filtered or unexported fields
}

Marshaler uses a set of codecs to marshal and unmarshal values.

func NewMarshaler

func NewMarshaler(
	types []reflect.Type,
	codecs []Codec,
) (*Marshaler, error)

NewMarshaler returns a new marshaler that uses the given set of codecs to marshal and unmarshal values.

The codecs are given in order of preference.

func NewMarshalerForApplication

func NewMarshalerForApplication(
	cfg *config.ApplicationConfig,
	codecs []Codec,
) (*Marshaler, error)

NewMarshalerForApplication returns a new marshaler for the given application config.

func (*Marshaler) Marshal

func (m *Marshaler) Marshal(v interface{}) (Packet, error)

Marshal returns a binary representation of v.

func (*Marshaler) MarshalType

func (m *Marshaler) MarshalType(rt reflect.Type) (string, error)

MarshalType marshals a type to its portable representation.

func (*Marshaler) Unmarshal

func (m *Marshaler) Unmarshal(p Packet) (interface{}, error)

Unmarshal produces a value from its binary representation.

func (*Marshaler) UnmarshalType

func (m *Marshaler) UnmarshalType(n string) (reflect.Type, error)

UnmarshalType marshals a type from its portable representation.

func (*Marshaler) UnmarshalTypeFromMediaType

func (m *Marshaler) UnmarshalTypeFromMediaType(mt string) (reflect.Type, error)

UnmarshalTypeFromMediaType unmarshals a type from a MIME media-type.

type Packet

type Packet struct {
	// MediaType is a MIME media-type describing the content and encoding of the
	// binary data.
	MediaType string

	// Data is the marshaled binary data.
	Data []byte
}

Packet is a container of marshaled data and its related meta-data.

func MarshalMessage

func MarshalMessage(ma *Marshaler, m dogma.Message) (Packet, error)

MarshalMessage returns a binary representation of a message.

func MustMarshalMessage

func MustMarshalMessage(ma *Marshaler, m dogma.Message) Packet

MustMarshalMessage returns a binary representation of a message. It panics if marshaling fails.

Directories

Path Synopsis
internal
Package json contains marshaler implementations that use Go's standard JSON marshaling.
Package json contains marshaler implementations that use Go's standard JSON marshaling.
Package protobuf contains marshaler implemenentations for protocol buffers types.
Package protobuf contains marshaler implemenentations for protocol buffers types.

Jump to

Keyboard shortcuts

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