stream

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

string stream protocol package provides a simple and efficient way to parse lab device communication streams

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongResSyntax = errors.New("illegal syntax in response")
	ErrWrongReqSyntax = errors.New("illegal syntax in request")
)

Functions

func NewParser

func NewParser(vdfile *vdfile.VDFile) (protocol.Protocol, error)

Constructor, returns parser struct with processed commands patterns that are used while parsing incoming data.

Types

type CommandPattern

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

Keeps request and response tokens

type Item

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

Main structure that keeps token type and its value.

func ItemsFromConfig

func ItemsFromConfig(input string) []Item

Convert string input to set of Items config

func (Item) String

func (i Item) String() string

To string representation

func (Item) Type

func (i Item) Type() ItemType

Item type

func (Item) Value

func (i Item) Value() string

Value setter

type ItemType

type ItemType int
const (
	ItemError ItemType = iota

	ItemCommand

	ItemNumberValuePlaceholder
	ItemStringValuePlaceholder

	ItemWhiteSpace

	ItemLeftMeta
	ItemParam
	ItemRightMeta

	ItemNumber

	ItemEOF
	ItemIllegal
	ItemEscape
)

func (ItemType) String

func (i ItemType) String() string

To string representation

type Lexer

type Lexer struct {
	Input string //the input string being scanned

	ItemsCh chan Item //channel of scanned items
	State   StateFn   //current state of the state machine
	// contains filtered or unexported fields
}

Define the lexer struct

func NewConfig

func NewConfig(input string) *Lexer

Create a new lexer with config mode

func NewData

func NewData(input string) *Lexer

Create a new lexer with data mode

func (*Lexer) Items

func (l *Lexer) Items() []Item

Returns the set of items for a lexer define structure

func (*Lexer) NextItem

func (l *Lexer) NextItem() Item

Process the next item when available

type Parser

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

Main parser structure, based on vdfile generates map of commands, and then parses incoming messages

func (*Parser) Decode

func (p *Parser) Decode(data []byte) ([]protocol.Transaction, error)

Method that fullfils main Protocol interface, all logic is implemented here. Based on byte input it returns transactions to be processed.

func (*Parser) Encode

func (p *Parser) Encode(txs []protocol.Transaction) ([]byte, error)

Method that fulfils Protocol interface. Based on received transactions it generates byte response/

func (*Parser) Trigger

func (p *Parser) Trigger(cmdName string) protocol.Transaction

Method that fulfils Protocol interface. It enforces processing of the specified command

type StateFn

type StateFn func(*Lexer) StateFn

Stage function callback

Jump to

Keyboard shortcuts

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