func (p *StreamParser) LineNumber() int {
	return p.machine.LineNumber()
}
LineNumber returns the current line number.  Lines are counted based on the
regular expression `\r?\n`.
package protocol
import (
	"fmt"
	"io"
	"strings"
	"sync"
	"time"
)
const (
	maxErrorBufferSize = 1024
)
type TimeFunc func() time.Time
type ParseError struct {
	Offset     int
	LineOffset int
	LineNumber int
	Column     int
	msg        string
	buf        string
}
func (e *ParseError) Error() string {
	buffer := e.buf[e.LineOffset:]
	eol := strings.IndexAny(buffer, "\r\n")
	if eol >= 0 {
		buffer = buffer[:eol]
	}
	if len(buffer) > maxErrorBufferSize {
		buffer = buffer[:maxErrorBufferSize] + "..."
	}
	return fmt.Sprintf("metric parse error: %s at %d:%d: %q", e.msg, e.LineNumber, e.Column, buffer)
}
type Parser struct {
	DefaultTags map[string]string
	sync.Mutex
	*machine
	handler *MetricHandler
}
func NewParser(handler *MetricHandler) *Parser {
	return &Parser{
		machine: NewMachine(handler),
		handler: handler,
	}
}
func NewSeriesParser(handler *MetricHandler) *Parser {
	return &Parser{
		machine: NewSeriesMachine(handler),
		handler: handler,
	}
}
func (p *Parser) SetTimeFunc(f TimeFunc) {
	p.handler.SetTimeFunc(f)
}
func (p *Parser) Parse(input []byte) ([]Metric, error) {
	p.Lock()
	defer p.Unlock()
	metrics := make([]Metric, 0)
	p.machine.SetData(input)
	for {
		err := p.machine.Next()
		if err == EOF {
			break
		}
		if err != nil {
			return nil, &ParseError{
				Offset:     p.machine.Position(),
				LineOffset: p.machine.LineOffset(),
				LineNumber: p.machine.LineNumber(),
				Column:     p.machine.Column(),
				msg:        err.Error(),
				buf:        string(input),
			}
		}
		metric, err := p.handler.Metric()
		if err != nil {
			return nil, err
		}
		if metric == nil {
			continue
		}
		metrics = append(metrics, metric)
	}
	return metrics, nil
}
type StreamParser struct {
	machine *streamMachine
	handler *MetricHandler
}
func NewStreamParser(r io.Reader) *StreamParser {
	handler := NewMetricHandler()
	return &StreamParser{
		machine: NewStreamMachine(r, handler),
		handler: handler,
	}
}
func (p *StreamParser) SetTimeFunc(f TimeFunc) {
	p.handler.SetTimeFunc(f)
}
func (p *StreamParser) SetTimePrecision(u time.Duration) {
	p.handler.SetTimePrecision(u)
}
func (p *StreamParser) Next() (Metric, error) {
	err := p.machine.Next()
	if err == EOF {
		return nil, EOF
	}
	if err != nil {
		return nil, &ParseError{
			Offset:     p.machine.Position(),
			LineOffset: p.machine.LineOffset(),
			LineNumber: p.machine.LineNumber(),
			Column:     p.machine.Column(),
			msg:        err.Error(),
			buf:        p.machine.LineText(),
		}
	}
	metric, err := p.handler.Metric()
	if err != nil {
		return nil, err
	}
	return metric, nil
}
func (p *StreamParser) Position() int {
	return p.machine.Position()
}
func (p *StreamParser) LineOffset() int {
	return p.machine.LineOffset()
}