Documentation ¶
Index ¶
- Constants
- Variables
- func Send(conn transporter, buf []byte, flags TransportFlag, payload []byte) (err error)
- func SendResponseEnd(conn transporter) error
- type Decoder
- type Encoder
- type TransportFlag
- func (flags TransportFlag) GetCompression() byte
- func (flags TransportFlag) GetEncoding() byte
- func (flags TransportFlag) SetBzip2() TransportFlag
- func (flags TransportFlag) SetGzip() TransportFlag
- func (flags TransportFlag) SetProtobuf() TransportFlag
- func (flags TransportFlag) SetSnappy() TransportFlag
- type TransportPacket
- func (pkt *TransportPacket) Receive(conn transporter) (payload interface{}, err error)
- func (pkt *TransportPacket) Send(conn transporter, payload interface{}) (err error)
- func (pkt *TransportPacket) SetDecoder(typ byte, callb Decoder) *TransportPacket
- func (pkt *TransportPacket) SetEncoder(typ byte, callb Encoder) *TransportPacket
Constants ¶
const ( // EncodingNone place holder. EncodingNone byte = 0x00 // EncodingProtobuf uses protobuf as coding format. EncodingProtobuf byte = 0x10 )
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 )
const (
MaxSendBufSize int = pktLenSize + pktFlagSize
)
packet field offset and size in bytes
Variables ¶
var ErrorDecoderUnknown = errors.New("transport.decoderUnknown")
ErrorDecoderUnknown for unknown decoder.
var ErrorEncoderUnknown = errors.New("transport.encoderUnknown")
ErrorEncoderUnknown for unknown encoder.
var ErrorPacketOverflow = errors.New("transport.packetOverflow")
ErrorPacketOverflow is input packet overflows maximum configured packet size.
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 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`.