codec

package
v0.0.0-...-831f302 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMessageAlreadyRegistered = errors.New("Message already registered")
	ErrMessageNotRegistered     = errors.New("Message not registered")
	ErrCannotWriteMessage       = errors.New("Cannot write message")
)

Functions

This section is empty.

Types

type Codec

type Codec interface {
	// Register registers a message so that the
	// codec can identify the message when reading
	// the TCP connection.
	Register(msg proto.Message)
	// WriteMsg encodes a message to bytes and
	// writes it to the io.Writer
	WriteMsg(msg proto.Message, w io.Writer) error
	// ReadMsg reads bytes from the io.Reader
	// and decodes it to a message.
	ReadMsg(r io.Reader) (proto.Message, error)
}

Codec describes the codec interface, which encodes/decodes protobuf messages from/to an io.Reader/Writer

type ProtobufCodec

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

ProtobufCodec implements the codec interface.

func NewProtobufCodec

func NewProtobufCodec() *ProtobufCodec

NewProtobufCodec creates and returns a ProtobufCodec.

func (*ProtobufCodec) ReadMsg

func (pc *ProtobufCodec) ReadMsg(r io.Reader) (msg proto.Message, err error)

ReadMsg reads bytes from an io.Reader and decode it to a message.

func (*ProtobufCodec) Register

func (pc *ProtobufCodec) Register(msg proto.Message)

Register registers a message. Note this is not concurrent-safe.

func (*ProtobufCodec) WriteMsg

func (pc *ProtobufCodec) WriteMsg(msg proto.Message, w io.Writer) error

WriteMsg encodes a message to bytes and writes it to the io.Writer.

Jump to

Keyboard shortcuts

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