Documentation ¶
Index ¶
Constants ¶
const Protocol = 3
Variables ¶
var WriterLocker sync.RWMutex
Functions ¶
This section is empty.
Types ¶
type PacketDecoder ¶
type PacketDecoder struct {
// contains filtered or unexported fields
}
packetDecoder is the decoder which decode data to packet.
func NewDecoder ¶
func NewDecoder(r io.Reader) (*PacketDecoder, error)
NewDecoder return the decoder which decode from reader r.
func (*PacketDecoder) MessageType ¶
func (d *PacketDecoder) MessageType() message.MessageType
MessageType returns the type of message, binary or string.
func (*PacketDecoder) Read ¶
func (d *PacketDecoder) Read(p []byte) (int, error)
Read reads packet data to bytes p.
func (*PacketDecoder) Type ¶
func (d *PacketDecoder) Type() PacketType
Type returns the type of packet.
type PacketEncoder ¶
type PacketEncoder struct {
// contains filtered or unexported fields
}
packetEncoder is the encoder which encode the packet.
func NewB64Encoder ¶
func NewB64Encoder(w io.Writer, t PacketType) (*PacketEncoder, error)
NewB64Encoder return the encoder which encode type t to writer w, as string. When write binary, it uses base64.
func NewBinaryEncoder ¶
func NewBinaryEncoder(w io.Writer, t PacketType) (*PacketEncoder, error)
NewBinaryEncoder return the encoder which encode type t to writer w, as binary.
func NewStringEncoder ¶
func NewStringEncoder(w io.Writer, t PacketType) (*PacketEncoder, error)
NewStringEncoder return the encoder which encode type t to writer w, as string.
type PacketType ¶
type PacketType string
PacketType is the type of packet
const ( OPEN PacketType = "open" CLOSE PacketType = "close" PING PacketType = "ping" PONG PacketType = "pong" MESSAGE PacketType = "message" UPGRADE PacketType = "upgrade" NOOP PacketType = "noop" )
func ByteToType ¶
func ByteToType(b byte) (PacketType, error)
type PayloadDecoder ¶
type PayloadDecoder struct {
// contains filtered or unexported fields
}
payloadDecoder is the decoder to decode payload.
func NewPayloadDecoder ¶
func NewPayloadDecoder(r io.Reader) *PayloadDecoder
NewPaylaodDecoder returns the payload decoder which read from reader r.
func (*PayloadDecoder) Next ¶
func (d *PayloadDecoder) Next() (*PacketDecoder, error)
Next returns the packet decoder. Make sure it will be closed after used.
type PayloadEncoder ¶
type PayloadEncoder struct {
// contains filtered or unexported fields
}
payloadEncoder is the encoder to encode packets as payload. It can be used in multi-thread.
func NewBinaryPayloadEncoder ¶
func NewBinaryPayloadEncoder() *PayloadEncoder
NewStringPayloadEncoder returns the encoder which encode as binary.
func NewStringPayloadEncoder ¶
func NewStringPayloadEncoder() *PayloadEncoder
NewStringPayloadEncoder returns the encoder which encode as string.
func (*PayloadEncoder) EncodeTo ¶
func (e *PayloadEncoder) EncodeTo(w io.Writer) error
EncodeTo writes encoded payload to writer w. It will clear the buffer of encoder.
func (*PayloadEncoder) IsString ¶
func (e *PayloadEncoder) IsString() bool
IsString returns true if payload encode to string, otherwise returns false.
func (*PayloadEncoder) NextBinary ¶
func (e *PayloadEncoder) NextBinary(t PacketType) (io.WriteCloser, error)
NextBinary returns the encoder with packet type t and encode as binary.
func (*PayloadEncoder) NextString ¶
func (e *PayloadEncoder) NextString(t PacketType) (io.WriteCloser, error)
NextString returns the encoder with packet type t and encode as string.