Documentation
¶
Index ¶
- Variables
- func Parse(w io.Writer, r io.Reader) error
- func ParseFromTemplate(w io.Writer, r io.Reader) error
- func ParseHexBytes(s string) ([]byte, error)
- func ParseString(s string) ([]byte, error)
- type CommandSpec
- type ControlCode
- type DecodeError
- type Entry
- type Interpreter
- type ParseFunc
- type SubCommands
- type Subcommand
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoSpec = errors.New("no command spec found") ErrArgCountMismatch = errors.New("argument count mismatch") ErrPayloadSizeMismatch = errors.New("payload size mismatch") ErrEmptyData = errors.New("empty data entry") ErrInvalidCommand = errors.New("invalid command") )
var GenericCommandSpecs []CommandSpec
var ( // SenddatOutput is the default senddat output stream SenddatOutput = os.Stderr )
Functions ¶
func ParseHexBytes ¶ added in v0.0.2
ParseHexBytes is an alternative parser for command prefixes, which expects a string of hex bytes separated by spaces, e.g. "1B 40" for ESC @. TODO: wire it to CLI flags.
func ParseString ¶ added in v0.0.2
ParseString parses the string, like 'ESC "@"' and returns bytes.
Types ¶
type CommandSpec ¶ added in v0.0.2
type CommandSpec struct {
Prefix []byte
Name string
ArgCount int
ArgNames []string
// Ignore indicates that this command should be ignored during processing.
// Possibly, read to the next known command.
Ignore bool
// contains filtered or unexported fields
}
func LoadCommandSpecsWithSubcommands ¶ added in v0.0.2
func LoadCommandSpecsWithSubcommands(cmdCSV, subCSV string) ([]CommandSpec, error)
func (CommandSpec) ArgValues ¶ added in v0.0.2
func (cs CommandSpec) ArgValues(args []byte) (map[string]uint8, error)
ArgValues returns a map of argument names to their values based on the provided args.
func (CommandSpec) String ¶ added in v0.0.2
func (cs CommandSpec) String() string
type ControlCode ¶
type ControlCode byte
ControlCode represents a control code used in the ESC/P, ESC/POS, and ESC/P2 protocols.
func (ControlCode) String ¶
func (i ControlCode) String() string
type DecodeError ¶ added in v0.0.2
func (*DecodeError) Error ¶ added in v0.0.2
func (e *DecodeError) Error() string
func (*DecodeError) Unwrap ¶ added in v0.0.2
func (e *DecodeError) Unwrap() error
type Entry ¶ added in v0.0.2
type Entry struct {
// Position in the input stream where the command or data starts.
Offset int
// Spec is the command specification.
Spec *CommandSpec
// Data is the raw bytes read from the stream. If the command is known,
// it will be empty.
Data []byte
// Args is the optional arguments for commands that have them. i.e. for ESC
// J n, will contain the value of n
Args []byte
// Payload is the optional payload data for commands that have it, like:
// ESC * m nL nH data
Payload []byte
}
Entry represents a single command entry in the PRN stream.
type Interpreter ¶ added in v0.0.2
type Interpreter struct {
// contains filtered or unexported fields
}
func NewInterpreter ¶ added in v0.0.2
func NewInterpreter(r io.Reader, spec []CommandSpec) (*Interpreter, error)
func (*Interpreter) Next ¶ added in v0.0.2
func (p *Interpreter) Next(ignoreUnknown bool) (*Entry, error)
Next reads the next command or raw data entry from the input stream. It returns an Entry containing the command specification, arguments, and payload if applicable, or raw data if no command is recognized. If ignoreUnknown is true, it will skip unknown commands and continue reading.
func (*Interpreter) ReadByte ¶ added in v0.0.2
func (p *Interpreter) ReadByte() (byte, error)
func (*Interpreter) UnreadByte ¶ added in v0.0.2
func (p *Interpreter) UnreadByte() error
type ParseFunc ¶ added in v0.0.2
var ParseFn ParseFunc = ParseString
ParseFn is the default parsing function for commands. There are two currently to choose from:
- ParseString - parses expressions like `ESC "@"'
- parseHexBytes - parses hex bytes, i.e. `1B 40'
type SubCommands ¶ added in v0.0.2
type SubCommands map[string]Subcommand