parser

package
v0.0.0-...-b4c6dbb Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: BSD-3-Clause, BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Protocol = 3

Variables

View Source
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) Close

func (d *PacketDecoder) Close() error

Close closes the decoder.

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.

func (*PacketEncoder) Close

func (e *PacketEncoder) Close() error

Close closes the encoder.

func (*PacketEncoder) Write

func (e *PacketEncoder) Write(p []byte) (int, error)

Write writes bytes p.

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)

func (PacketType) Byte

func (t PacketType) Byte() byte

Byte return the byte of type

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.

Jump to

Keyboard shortcuts

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