encoding

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeMessagePackStr    = "msgp"
	TypeProtocolBufferStr = "protobuf"
	TypeJSONStr           = "json"
)

string versions of the Type enumeration values

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder interface {
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}

Encoder defines a universal interface that all EncodingType implementations have to adhere.

func NewEncoder

func NewEncoder(et Type) (Encoder, error)

NewEncoder creates an Encoder, using the standard Encoder implementation matched for the given Encoding Type.

type JSONEncoder

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

JSONEncoder defines the standard implementation for the JSON Encoding Type, using a single bytes.Buffer for all marshal calls, and using the Encoder type of the std encoding/json pkg internally.

func NewJSONEncoder

func NewJSONEncoder() *JSONEncoder

NewJSONEncoder creates a new JSONEncoder, allocating a new bytes buffer and a (std) JSON Encoder (encapsulating the buffer).

See JSONEncoder for more information.

func (JSONEncoder) Marshal

func (encoder JSONEncoder) Marshal(v interface{}) ([]byte, error)

Marshal implements Encoder.Marshal

func (JSONEncoder) Unmarshal

func (encoder JSONEncoder) Unmarshal(data []byte, v interface{}) error

Unmarshal implements encoder.Unmarshal

type MessagePackEncoder

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

MessagePackEncoder defines the standard implementation for the MessagePack Encoding Type, using a single bytes.Buffer for all marshal calls, and using a single shared instance of the Reader/Writer types of the github.com/tinylib/msgp/msgp pkg internally.

func NewMessagePackEncoder

func NewMessagePackEncoder() *MessagePackEncoder

NewMessagePackEncoder creates a new MessagePackEncoder, allocating a new bytes buffer and a MessagePack Writer (encapsulating the buffer).

See MessagePackEncoder for more information.

func (MessagePackEncoder) Marshal

func (encoder MessagePackEncoder) Marshal(v interface{}) ([]byte, error)

Marshal implements Encoder.Marshal

func (MessagePackEncoder) Unmarshal

func (encoder MessagePackEncoder) Unmarshal(data []byte, v interface{}) error

Unmarshal implements encoding.Unmarshal

type ProtocolBufferEncoder added in v0.2.0

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

ProtocolBufferEncoder defines the standard implementation for the ProtocolBuffer Encoding Type, using a single proto.Buffer for all marshal calls, of the github.com/gogo/protobuf/proto internally.

func NewProtocolBufferEncoder added in v0.2.0

func NewProtocolBufferEncoder() *ProtocolBufferEncoder

NewProtocolBufferEncoder creates a new ProtocolBufferEncoder, allocating a new proto buffer used for marshaling.

See ProtocolBufferEncoder for more information.

func (*ProtocolBufferEncoder) Marshal added in v0.2.0

func (encoder *ProtocolBufferEncoder) Marshal(v interface{}) ([]byte, error)

Marshal implements Encoder.Marshal

func (*ProtocolBufferEncoder) Unmarshal added in v0.2.0

func (encoder *ProtocolBufferEncoder) Unmarshal(data []byte, v interface{}) error

Unmarshal implements encoder.Unmarshal

type ProtocolBufferMarshaler added in v0.2.0

type ProtocolBufferMarshaler interface {
	ProtocolBufferMarshal(ProtocolBufferWriter) error
}

ProtocolBufferMarshaler is the interface implemented by types that know how to write themselves as ProtocolBuffer Messages into a given ProtocolBufferWriter.

type ProtocolBufferReader added in v0.2.0

type ProtocolBufferReader interface {
	Unmarshal(pb proto.Message) error
}

ProtocolBufferReader is used by ProtocolBufferUnmarshaler implementations to unmarshal (=read) their encoded form as a given ProtocolBuffer Message

type ProtocolBufferUnmarshaler added in v0.2.0

type ProtocolBufferUnmarshaler interface {
	ProtocolBufferUnmarshal(ProtocolBufferReader) error
}

ProtocolBufferUnmarshaler is the interface implemented by types that know how to read themselves as ProtocolBuffer Messages from a given ProtocolBufferReader.

type ProtocolBufferWriter added in v0.2.0

type ProtocolBufferWriter interface {
	Marshal(pb proto.Message) error
}

ProtocolBufferWriter is used by ProtocolBufferMarshaler implementations to marshal (=write) themselves as a ProtocolBuffer Message.

type Type

type Type uint8

Type identifies a type of Encoder

const (
	TypeMessagePack Type = iota
	TypeProtocolBuffer
	TypeJSON
)

the Type enumeration values

func (*Type) LoadString

func (et *Type) LoadString(str string) error

LoadString implements StringLoader.LoadString, piggy-backing on the flag.Value.Set implementation of this type.

func (*Type) Set

func (et *Type) Set(str string) error

Set implements flag.Value.Set

func (Type) String

func (et Type) String() string

String implements flag.Value.String and fmt.Stringer.String

func (Type) Type

func (et Type) Type() string

Type implements pflag.Value.Type

Jump to

Keyboard shortcuts

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