|
|
@ -12,16 +12,13 @@ type parser struct {
|
|
|
|
// the source of replay bytes. Must NOT be compressed.
|
|
|
|
// the source of replay bytes. Must NOT be compressed.
|
|
|
|
source *bufio.Reader
|
|
|
|
source *bufio.Reader
|
|
|
|
|
|
|
|
|
|
|
|
// re-useable scratch buffer. Contents never guaranteed to be clean.
|
|
|
|
|
|
|
|
scratch []byte
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dumpMessages bool
|
|
|
|
dumpMessages bool
|
|
|
|
dumpPackets bool
|
|
|
|
dumpPackets bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newParser(r io.Reader) *parser {
|
|
|
|
func newParser(r io.Reader) *parser {
|
|
|
|
br := bufio.NewReaderSize(r, 1<<16)
|
|
|
|
br := bufio.NewReaderSize(r, 1<<16)
|
|
|
|
return &parser{source: br, scratch: make([]byte, 1<<10)}
|
|
|
|
return &parser{source: br}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p *parser) start() error {
|
|
|
|
func (p *parser) start() error {
|
|
|
@ -56,13 +53,6 @@ func (p *parser) run() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// grows the scratch buffer until it is at least n bytes wide
|
|
|
|
|
|
|
|
func (p *parser) growScratch(n int) {
|
|
|
|
|
|
|
|
for len(p.scratch) < n {
|
|
|
|
|
|
|
|
p.scratch = make([]byte, 2*len(p.scratch))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DecodeVarint reads a varint-encoded integer from the source reader.
|
|
|
|
// DecodeVarint reads a varint-encoded integer from the source reader.
|
|
|
|
// It returns the value as a uin64 and any errors encountered. The reader will
|
|
|
|
// It returns the value as a uin64 and any errors encountered. The reader will
|
|
|
|
// be advanced by the number of bytes needed to consume this value. On error,
|
|
|
|
// be advanced by the number of bytes needed to consume this value. On error,
|
|
|
@ -102,8 +92,7 @@ func (p *parser) decodeVarint() (uint64, error) {
|
|
|
|
// the beginning of the scratch buffer. it will be corrupted on the next call
|
|
|
|
// the beginning of the scratch buffer. it will be corrupted on the next call
|
|
|
|
// to readn or the next operation that utilizes the scratch buffer.
|
|
|
|
// to readn or the next operation that utilizes the scratch buffer.
|
|
|
|
func (p *parser) readn(n int) ([]byte, error) {
|
|
|
|
func (p *parser) readn(n int) ([]byte, error) {
|
|
|
|
p.growScratch(n)
|
|
|
|
buf := make([]byte, n)
|
|
|
|
buf := p.scratch[:n]
|
|
|
|
|
|
|
|
if _, err := io.ReadFull(p.source, buf); err != nil {
|
|
|
|
if _, err := io.ReadFull(p.source, buf); err != nil {
|
|
|
|
return nil, wrap(err, "error reading %d bytes", n)
|
|
|
|
return nil, wrap(err, "error reading %d bytes", n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|