gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

stream_parser.go (793B)


      1 package pgdialect
      2 
      3 import (
      4 	"fmt"
      5 	"io"
      6 )
      7 
      8 type streamParser struct {
      9 	b []byte
     10 	i int
     11 
     12 	buf []byte
     13 }
     14 
     15 func newStreamParser(b []byte, start int) *streamParser {
     16 	return &streamParser{
     17 		b: b,
     18 		i: start,
     19 	}
     20 }
     21 
     22 func (p *streamParser) valid() bool {
     23 	return p.i < len(p.b)
     24 }
     25 
     26 func (p *streamParser) skipByte(skip byte) error {
     27 	c, err := p.readByte()
     28 	if err != nil {
     29 		return err
     30 	}
     31 	if c == skip {
     32 		return nil
     33 	}
     34 	p.unreadByte()
     35 	return fmt.Errorf("got %q, wanted %q", c, skip)
     36 }
     37 
     38 func (p *streamParser) readByte() (byte, error) {
     39 	if p.valid() {
     40 		c := p.b[p.i]
     41 		p.i++
     42 		return c, nil
     43 	}
     44 	return 0, io.EOF
     45 }
     46 
     47 func (p *streamParser) unreadByte() {
     48 	p.i--
     49 }
     50 
     51 func (p *streamParser) peek() byte {
     52 	if p.valid() {
     53 		return p.b[p.i]
     54 	}
     55 	return 0
     56 }
     57 
     58 func (p *streamParser) skipNext() {
     59 	p.i++
     60 }