transport

package
v0.0.0-...-b800c40 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EncodingNone place holder.
	EncodingNone byte = 0x00
	// EncodingProtobuf uses protobuf as coding format.
	EncodingProtobuf byte = 0x10
)
View Source
const (
	// CompressionNone does not apply compression on the payload.
	CompressionNone byte = 0
	// CompressionSnappy apply snappy compression on payload.
	CompressionSnappy = 1
	// CompressionGzip apply gzip compression on payload.
	CompressionGzip = 2
	// CompressionBzip2 apply bzip2 compression on the payload.
	CompressionBzip2 = 3
)
View Source
const (
	MaxSendBufSize int = pktLenSize + pktFlagSize
)

packet field offset and size in bytes

Variables

View Source
var ErrorDecoderUnknown = errors.New("transport.decoderUnknown")

ErrorDecoderUnknown for unknown decoder.

View Source
var ErrorEncoderUnknown = errors.New("transport.encoderUnknown")

ErrorEncoderUnknown for unknown encoder.

View Source
var ErrorPacketOverflow = errors.New("transport.packetOverflow")

ErrorPacketOverflow is input packet overflows maximum configured packet size.

View Source
var ErrorPacketWrite = errors.New("transport.packetWrite")

ErrorPacketWrite is error writing packet on the wire.

Functions

func Send

func Send(conn transporter, buf []byte, flags TransportFlag, payload []byte) (err error)

func SendResponseEnd

func SendResponseEnd(conn transporter) error

Types

type Decoder

type Decoder func(data []byte) (payload interface{}, err error)

Decoder callback

type Encoder

type Encoder func(payload interface{}) (data []byte, err error)

Encoder callback

type TransportFlag

type TransportFlag uint16

TransportFlag tell packet encoding and compression formats.

func Receive

func Receive(conn transporter, buf []byte) (flags TransportFlag, payload []byte, err error)

func (TransportFlag) GetCompression

func (flags TransportFlag) GetCompression() byte

GetCompression returns the compression bits from flags

func (TransportFlag) GetEncoding

func (flags TransportFlag) GetEncoding() byte

GetEncoding will get the encoding bits from flags

func (TransportFlag) SetBzip2

func (flags TransportFlag) SetBzip2() TransportFlag

SetBzip2 will set packet compression to bzip2

func (TransportFlag) SetGzip

func (flags TransportFlag) SetGzip() TransportFlag

SetGzip will set packet compression to Gzip

func (TransportFlag) SetProtobuf

func (flags TransportFlag) SetProtobuf() TransportFlag

SetProtobuf will set packet encoding to protobuf

func (TransportFlag) SetSnappy

func (flags TransportFlag) SetSnappy() TransportFlag

SetSnappy will set packet compression to snappy

type TransportPacket

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

TransportPacket to send and receive mutation packets between router and downstream client.

func NewTransportPacket

func NewTransportPacket(maxlen int, flags TransportFlag) *TransportPacket

NewTransportPacket creates a new TransportPacket and return its reference. Typically application should call this once and reuse it while sending or receiving a sequence of packets, so that same buffer can be reused.

maxlen, maximum size of internal buffer used to marshal and unmarshal

packets.

flags, specifying encoding and compression.

func (*TransportPacket) Receive

func (pkt *TransportPacket) Receive(conn transporter) (payload interface{}, err error)

Receive payload from remote, decode, decompress the payload and return the payload.

func (*TransportPacket) Send

func (pkt *TransportPacket) Send(conn transporter, payload interface{}) (err error)

Send payload to the other end using sufficient encoding and compression.

func (*TransportPacket) SetDecoder

func (pkt *TransportPacket) SetDecoder(typ byte, callb Decoder) *TransportPacket

SetDecoder callback function for `type`.

func (*TransportPacket) SetEncoder

func (pkt *TransportPacket) SetEncoder(typ byte, callb Encoder) *TransportPacket

SetEncoder callback function for `type`.

Jump to

Keyboard shortcuts

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