parser

package
Version: v0.0.0-...-309e9be Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2017 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteUserBody

func WriteUserBody(writer io.Writer, message UserBody) error

func WriteUserHeader

func WriteUserHeader(writer io.Writer, message UserHeader) error

Types

type Cancel

type Cancel struct {
	UserHeader
	RequestUid [16]byte
}

Cancel frame

func (Cancel) GetType

func (this Cancel) GetType() FrameType

func (*Cancel) Parse

func (this *Cancel) Parse(buffer io.Reader) error

func (*Cancel) Serialize

func (this *Cancel) Serialize(writer io.Writer) error

type CloseCode

type CloseCode uint8
const (
	CLOSE_UNKNOWN               CloseCode = 0x00
	CLOSE_VERSION_NOT_SUPPORTED CloseCode = 0x01
	CLOSE_TIMEOUT               CloseCode = 0x02
	CLOSE_REDIRECT              CloseCode = 0x03
)

type Event

type Event struct {
	UserHeader
	UserBody
}

Event frame

func (*Event) GetType

func (this *Event) GetType() FrameType

func (*Event) Parse

func (this *Event) Parse(buffer io.Reader) error

func (*Event) Serialize

func (this *Event) Serialize(writer io.Writer) error

type Frame

type Frame interface {

	// Returns frame type
	GetType() FrameType

	// Parse itself from reader
	Parse(reader io.Reader) error

	// Write itself to writer
	Serialize(writer io.Writer) error
}

Frame is transferred frame with concrete type

type FrameType

type FrameType uint8

Frame type represents specific frame

const CANCEL FrameType = 0x12
const EVENT FrameType = 0x10
const REQUEST FrameType = 0x11
const RESPONSE FrameType = 0x13
const SYSTEM_CLOSE FrameType = 0x01
const SYSTEM_HANDSHAKE FrameType = 0x00
const SYSTEM_PING FrameType = 0x02

type Parser

type Parser struct {

	// Channel to push parsed frames
	Frames chan Frame

	// Error to push reason of parser stop
	Error chan error
	// contains filtered or unexported fields
}

Frames Parser

func NewParser

func NewParser(reader io.Reader) *Parser

Creates new instance of Parser and starts parsing loop

type Request

type Request struct {
	UserHeader
	UserBody
}

Request frame

func (Request) GetType

func (this Request) GetType() FrameType

func (*Request) Parse

func (this *Request) Parse(buffer io.Reader) error

func (*Request) Serialize

func (this *Request) Serialize(writer io.Writer) error

type Response

type Response struct {
	UserHeader
	RequestUid [16]byte
	Type       ResponseType
	UserBody
}

Response frame

func (Response) GetType

func (this Response) GetType() FrameType

func (*Response) Parse

func (this *Response) Parse(buffer io.Reader) error

func (*Response) Serialize

func (this *Response) Serialize(writer io.Writer) error

type ResponseType

type ResponseType uint8
const (
	RESPONSE_DONE      ResponseType = 0x00
	RESPONSE_ERROR     ResponseType = 0x01
	RESPONSE_PROGRESS  ResponseType = 0x02
	RESPONSE_CANCELLED ResponseType = 0x03
)

type SystemClose

type SystemClose struct {
	Code    CloseCode
	Message string
}

SystemClose frame

func (*SystemClose) GetType

func (this *SystemClose) GetType() FrameType

func (*SystemClose) Parse

func (this *SystemClose) Parse(buffer io.Reader) error

func (*SystemClose) Serialize

func (this *SystemClose) Serialize(writer io.Writer) error

type SystemHandshake

type SystemHandshake struct {
	Version uint16
}

SystemHandshake frame

func (*SystemHandshake) GetType

func (this *SystemHandshake) GetType() FrameType

func (*SystemHandshake) Parse

func (this *SystemHandshake) Parse(buffer io.Reader) error

func (*SystemHandshake) Serialize

func (this *SystemHandshake) Serialize(writer io.Writer) error

type SystemPing

type SystemPing struct {
	Ack     bool
	Payload string
}

SystemPing frame

func (*SystemPing) GetType

func (this *SystemPing) GetType() FrameType

func (*SystemPing) Parse

func (this *SystemPing) Parse(buffer io.Reader) error

func (*SystemPing) Serialize

func (this *SystemPing) Serialize(writer io.Writer) error

type UserBody

type UserBody struct {
	Body []byte
}

UserBody frame part

func ParseUserBody

func ParseUserBody(buffer io.Reader) (*UserBody, error)

type UserHeader

type UserHeader struct {
	Uid [16]byte
	Uri string
}

UserHeader frame part

func ParseUserHeader

func ParseUserHeader(buffer io.Reader) (*UserHeader, error)

Jump to

Keyboard shortcuts

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