encoding

package
v0.0.0-...-3e87057 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MarshalTypeProtobuf is the enum value which identifies,
	// the protobuf (un)marshalling functions pair provided by the proto subpackage.
	//
	// It makes use of the (slick) gogoprotobuf generator,
	// to generate the code used to marshal/unmarshal
	// metadata using this (un)marshalling pair.
	//
	// It is also the default Marshal type and the one recommended to be used,
	// as it is fast, lightweight and produces a compact output to top it all off.
	MarshalTypeProtobuf MarshalType = iota

	// DefaultMarshalType represents the default (un)marshalling format,
	// promoted by this package. Currently this is using Protobuf.
	//
	// This package reserves the right to change the
	// underlying algorithm at any time,
	// but this constant will always be available and up to date.
	DefaultMarshalType = MarshalTypeProtobuf

	// MaxStandardMarshalType defines the (un)marshalling type,
	// which has the greatest defined/used enum value.
	// When defining your custom MarshalType you can do so as follows:
	//
	//    const (
	//         MyMarshalType = iota + MaxStandardMarshalType + 1
	//         MyOtherMarshalType
	//         // ...
	//    )
	//
	// Or when you only have one custom Marshal Type you can simply do:
	//
	//    const MyMarshalType = MaxStandardMarshalType + 1
	//
	// Just make sure that you don't use the same value for 2 different
	// marshal type constants, as that would mean you'll overwrite
	// a previous registered hash when registering a (un)marshalling pair
	// using this "duplicate" constant.
	//
	// The maximum allowed value of a custom hash type is 255,
	// due to the underlying uint8 type.
	MaxStandardMarshalType = MarshalTypeProtobuf
)

Variables

This section is empty.

Functions

func RegisterMarshalFuncPair

func RegisterMarshalFuncPair(mt MarshalType, str string, pair MarshalFuncPair)

RegisterMarshalFuncPair registers a new or overwrite an existing marshal/unmarshal pair of functions, used to (un)marshal metadata. The given str will be used in a case-insensitive manner, if the registered marshal type however overwrites an existing marshal type, the str parameter will be ignored and instead the already used string version will be used. This is intended to be called from the init function in packages that implement marshal functions.

Types

type MarshalFuncPair

type MarshalFuncPair struct {
	Marshal   MarshalMetadata
	Unmarshal UnmarshalMetadata
}

MarshalFuncPair composes a pair of MarshalMetadata and UnmarshalMetadata functions which are meant to be used together.

func NewMarshalFuncPair

func NewMarshalFuncPair(mt MarshalType) (*MarshalFuncPair, error)

NewMarshalFuncPair returns a registered MarshalFuncPair, for a given MarshalType.

An error is returned in case, and only if, there was no MarshalFuncPair registered for the given MarshalType.

type MarshalMetadata

type MarshalMetadata func(md metatypes.Metadata) ([]byte, error)

MarshalMetadata returns the encoding of the metadata parameter. It is important to use this function with a matching `UnmarshalMetadata` function.

type MarshalType

type MarshalType uint8

MarshalType represents the type of a pair of Marshal/Unmarshal Metadata functions.

func (MarshalType) MarshalText

func (mt MarshalType) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.MarshalText

func (MarshalType) String

func (mt MarshalType) String() string

String implements Stringer.String

func (*MarshalType) UnmarshalText

func (mt *MarshalType) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText

type UnmarshalMetadata

type UnmarshalMetadata func(b []byte, md *metatypes.Metadata) error

UnmarshalMetadata parses the encoded metadata and stores the result in the value pointed to by the data parameter. It is important to use this function with a matching `MashalMetadata` function.

Directories

Path Synopsis
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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