stream

package
v0.0.0-...-6dfdce2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind byte

Kind represents the kind of the section.

const (
	// Field kind
	Field Kind = iota + 1

	// Record kind
	Record
)

type Reader

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

Reader provides services to objects that parse streams.

Example
r := NewReader(strings.NewReader(`a{} a{b{c: "value"}}`))
var parse func(r *Reader)
parse = func(r *Reader) {
	for r.Next() {
		switch r.Kind() {
		case Field:
			fmt.Println(r.Name(), r.StringField())
		case Record:
			name := r.Name()
			fmt.Println("record", name)
			parse(r.Record())
			fmt.Println("end", name)
		}
	}
}
parse(r)
Output:

record a
end a
record a
record b
c value
end b
end a

func NewReader

func NewReader(src io.Reader) *Reader

NewReader creates a new reader from an io.Reader.

func (*Reader) BoolField

func (p *Reader) BoolField() bool

BoolField reads a field and interprets it as a boolean. If the current section is not a field containing a boolean then an error is signalled.

func (*Reader) Err

func (p *Reader) Err() error

Err gives the error that has been set, if any.

func (*Reader) ExpectEOF

func (p *Reader) ExpectEOF()

ExpectEOF asserts that the entire file was parsed.

func (*Reader) IntField

func (p *Reader) IntField() int

IntField reads a field and interprets it as an integer. If the current section is not a field containing an integer then an error is signalled.

func (*Reader) Kind

func (p *Reader) Kind() Kind

Kind gives the kind of the section under consideration, either Field or Record. If it returns anything other than one of these values, the reader is in a bad state and it would be unwise to continue parsing.

func (*Reader) Name

func (p *Reader) Name() string

Name gives the name of the current section under consideration. Note that if Kind() does not return Field or Value then this value is undefined.

func (*Reader) Next

func (p *Reader) Next() bool

Next moves to the next named section (field or record) of the input. It returns whether progress can be made by a consumer.

If Next is called twice without a call to either a Field() method or the Record() method in between then an error is signalled and the second Next() returns false.

func (*Reader) Record

func (p *Reader) Record() *Reader

Record uses the provided parser to parse a record. An error will be signalled if the current section is not a record.

func (*Reader) StringField

func (p *Reader) StringField() string

StringField reads a field and interprets it as a string. If the current section is not a field then an error is signalled.

type Writer

type Writer struct {
	Indent, LineEnd string
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(dest io.Writer) *Writer

func (*Writer) BoolField

func (w *Writer) BoolField(name string, value bool)

func (*Writer) Err

func (w *Writer) Err() error

func (*Writer) IntField

func (w *Writer) IntField(name string, value int)

func (*Writer) Record

func (w *Writer) Record(name string, emitter func(*Writer))

func (*Writer) StringField

func (w *Writer) StringField(name, value string)

Jump to

Keyboard shortcuts

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