2021-09-10 12:42:14 +00:00
|
|
|
package decoder
|
2021-08-12 19:03:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-09-10 12:42:14 +00:00
|
|
|
"encoding/json"
|
2021-08-12 19:03:24 +00:00
|
|
|
"io"
|
2021-09-10 12:42:14 +00:00
|
|
|
"strconv"
|
2021-08-12 19:03:24 +00:00
|
|
|
"unsafe"
|
2021-09-10 12:42:14 +00:00
|
|
|
|
|
|
|
"github.com/goccy/go-json/internal/errors"
|
2021-08-12 19:03:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
initBufSize = 512
|
|
|
|
)
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
type Stream struct {
|
2021-08-12 19:03:24 +00:00
|
|
|
buf []byte
|
|
|
|
bufSize int64
|
|
|
|
length int64
|
|
|
|
r io.Reader
|
|
|
|
offset int64
|
|
|
|
cursor int64
|
|
|
|
filledBuffer bool
|
|
|
|
allRead bool
|
2021-09-10 12:42:14 +00:00
|
|
|
UseNumber bool
|
|
|
|
DisallowUnknownFields bool
|
|
|
|
Option *Option
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func NewStream(r io.Reader) *Stream {
|
|
|
|
return &Stream{
|
2021-08-12 19:03:24 +00:00
|
|
|
r: r,
|
|
|
|
bufSize: initBufSize,
|
2021-09-10 12:42:14 +00:00
|
|
|
buf: make([]byte, initBufSize),
|
|
|
|
Option: &Option{},
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) TotalOffset() int64 {
|
|
|
|
return s.totalOffset()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Stream) Buffered() io.Reader {
|
2021-08-12 19:03:24 +00:00
|
|
|
buflen := int64(len(s.buf))
|
|
|
|
for i := s.cursor; i < buflen; i++ {
|
|
|
|
if s.buf[i] == nul {
|
|
|
|
return bytes.NewReader(s.buf[s.cursor:i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bytes.NewReader(s.buf[s.cursor:])
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) PrepareForDecode() error {
|
|
|
|
for {
|
|
|
|
switch s.char() {
|
|
|
|
case ' ', '\t', '\r', '\n':
|
|
|
|
s.cursor++
|
|
|
|
continue
|
|
|
|
case ',', ':':
|
|
|
|
s.cursor++
|
|
|
|
return nil
|
|
|
|
case nul:
|
|
|
|
if s.read() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return io.EOF
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Stream) totalOffset() int64 {
|
2021-08-12 19:03:24 +00:00
|
|
|
return s.offset + s.cursor
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) char() byte {
|
2021-08-12 19:03:24 +00:00
|
|
|
return s.buf[s.cursor]
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) equalChar(c byte) bool {
|
2021-08-12 19:03:24 +00:00
|
|
|
cur := s.buf[s.cursor]
|
|
|
|
if cur == nul {
|
|
|
|
s.read()
|
|
|
|
cur = s.buf[s.cursor]
|
|
|
|
}
|
|
|
|
return cur == c
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) stat() ([]byte, int64, unsafe.Pointer) {
|
2021-08-12 19:03:24 +00:00
|
|
|
return s.buf, s.cursor, (*sliceHeader)(unsafe.Pointer(&s.buf)).data
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) bufptr() unsafe.Pointer {
|
|
|
|
return (*sliceHeader)(unsafe.Pointer(&s.buf)).data
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Stream) statForRetry() ([]byte, int64, unsafe.Pointer) {
|
2021-08-12 19:03:24 +00:00
|
|
|
s.cursor-- // for retry ( because caller progress cursor position in each loop )
|
|
|
|
return s.buf, s.cursor, (*sliceHeader)(unsafe.Pointer(&s.buf)).data
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) Reset() {
|
|
|
|
s.reset()
|
|
|
|
s.bufSize = initBufSize
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Stream) More() bool {
|
|
|
|
for {
|
|
|
|
switch s.char() {
|
|
|
|
case ' ', '\n', '\r', '\t':
|
|
|
|
s.cursor++
|
|
|
|
continue
|
|
|
|
case '}', ']':
|
|
|
|
return false
|
|
|
|
case nul:
|
|
|
|
if s.read() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Stream) Token() (interface{}, error) {
|
|
|
|
for {
|
|
|
|
c := s.char()
|
|
|
|
switch c {
|
|
|
|
case ' ', '\n', '\r', '\t':
|
|
|
|
s.cursor++
|
|
|
|
case '{', '[', ']', '}':
|
|
|
|
s.cursor++
|
|
|
|
return json.Delim(c), nil
|
|
|
|
case ',', ':':
|
|
|
|
s.cursor++
|
|
|
|
case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
|
|
|
bytes := floatBytes(s)
|
|
|
|
s := *(*string)(unsafe.Pointer(&bytes))
|
|
|
|
f64, err := strconv.ParseFloat(s, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return f64, nil
|
|
|
|
case '"':
|
|
|
|
bytes, err := stringBytes(s)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return string(bytes), nil
|
|
|
|
case 't':
|
|
|
|
if err := trueBytes(s); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
case 'f':
|
|
|
|
if err := falseBytes(s); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
case 'n':
|
|
|
|
if err := nullBytes(s); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
case nul:
|
|
|
|
if s.read() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
goto END
|
|
|
|
default:
|
|
|
|
return nil, errors.ErrInvalidCharacter(s.char(), "token", s.totalOffset())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
END:
|
|
|
|
return nil, io.EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Stream) reset() {
|
2021-08-12 19:03:24 +00:00
|
|
|
s.offset += s.cursor
|
|
|
|
s.buf = s.buf[s.cursor:]
|
|
|
|
s.length -= s.cursor
|
|
|
|
s.cursor = 0
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) readBuf() []byte {
|
2021-08-12 19:03:24 +00:00
|
|
|
if s.filledBuffer {
|
|
|
|
s.bufSize *= 2
|
|
|
|
remainBuf := s.buf
|
|
|
|
s.buf = make([]byte, s.bufSize)
|
|
|
|
copy(s.buf, remainBuf)
|
|
|
|
}
|
|
|
|
remainLen := s.length - s.cursor
|
|
|
|
remainNotNulCharNum := int64(0)
|
|
|
|
for i := int64(0); i < remainLen; i++ {
|
|
|
|
if s.buf[s.cursor+i] == nul {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
remainNotNulCharNum++
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
s.length = s.cursor + remainNotNulCharNum
|
2021-08-12 19:03:24 +00:00
|
|
|
return s.buf[s.cursor+remainNotNulCharNum:]
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) read() bool {
|
2021-08-12 19:03:24 +00:00
|
|
|
if s.allRead {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
buf := s.readBuf()
|
|
|
|
last := len(buf) - 1
|
|
|
|
buf[last] = nul
|
|
|
|
n, err := s.r.Read(buf[:last])
|
2021-09-10 12:42:14 +00:00
|
|
|
s.length += int64(n)
|
2021-08-12 19:03:24 +00:00
|
|
|
if n == last {
|
|
|
|
s.filledBuffer = true
|
|
|
|
} else {
|
|
|
|
s.filledBuffer = false
|
|
|
|
}
|
|
|
|
if err == io.EOF {
|
|
|
|
s.allRead = true
|
|
|
|
} else if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) skipWhiteSpace() byte {
|
|
|
|
p := s.bufptr()
|
2021-08-12 19:03:24 +00:00
|
|
|
LOOP:
|
2021-09-10 12:42:14 +00:00
|
|
|
c := char(p, s.cursor)
|
|
|
|
switch c {
|
2021-08-12 19:03:24 +00:00
|
|
|
case ' ', '\n', '\t', '\r':
|
|
|
|
s.cursor++
|
|
|
|
goto LOOP
|
|
|
|
case nul:
|
|
|
|
if s.read() {
|
2021-09-10 12:42:14 +00:00
|
|
|
p = s.bufptr()
|
2021-08-12 19:03:24 +00:00
|
|
|
goto LOOP
|
|
|
|
}
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return c
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) skipObject(depth int64) error {
|
2021-08-12 19:03:24 +00:00
|
|
|
braceCount := 1
|
|
|
|
_, cursor, p := s.stat()
|
|
|
|
for {
|
|
|
|
switch char(p, cursor) {
|
|
|
|
case '{':
|
|
|
|
braceCount++
|
|
|
|
depth++
|
|
|
|
if depth > maxDecodeNestingDepth {
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrExceededMaxDepth(s.char(), s.cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
case '}':
|
|
|
|
braceCount--
|
|
|
|
depth--
|
|
|
|
if braceCount == 0 {
|
|
|
|
s.cursor = cursor + 1
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case '[':
|
|
|
|
depth++
|
|
|
|
if depth > maxDecodeNestingDepth {
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrExceededMaxDepth(s.char(), s.cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
case ']':
|
|
|
|
depth--
|
|
|
|
case '"':
|
|
|
|
for {
|
|
|
|
cursor++
|
|
|
|
switch char(p, cursor) {
|
|
|
|
case '\\':
|
|
|
|
cursor++
|
|
|
|
if char(p, cursor) == nul {
|
|
|
|
s.cursor = cursor
|
|
|
|
if s.read() {
|
|
|
|
_, cursor, p = s.statForRetry()
|
|
|
|
continue
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
case '"':
|
|
|
|
goto SWITCH_OUT
|
|
|
|
case nul:
|
|
|
|
s.cursor = cursor
|
|
|
|
if s.read() {
|
|
|
|
_, cursor, p = s.statForRetry()
|
|
|
|
continue
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case nul:
|
|
|
|
s.cursor = cursor
|
|
|
|
if s.read() {
|
|
|
|
_, cursor, p = s.stat()
|
|
|
|
continue
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrUnexpectedEndOfJSON("object of object", cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
SWITCH_OUT:
|
|
|
|
cursor++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) skipArray(depth int64) error {
|
2021-08-12 19:03:24 +00:00
|
|
|
bracketCount := 1
|
|
|
|
_, cursor, p := s.stat()
|
|
|
|
for {
|
|
|
|
switch char(p, cursor) {
|
|
|
|
case '[':
|
|
|
|
bracketCount++
|
|
|
|
depth++
|
|
|
|
if depth > maxDecodeNestingDepth {
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrExceededMaxDepth(s.char(), s.cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
case ']':
|
|
|
|
bracketCount--
|
|
|
|
depth--
|
|
|
|
if bracketCount == 0 {
|
|
|
|
s.cursor = cursor + 1
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case '{':
|
|
|
|
depth++
|
|
|
|
if depth > maxDecodeNestingDepth {
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrExceededMaxDepth(s.char(), s.cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
case '}':
|
|
|
|
depth--
|
|
|
|
case '"':
|
|
|
|
for {
|
|
|
|
cursor++
|
|
|
|
switch char(p, cursor) {
|
|
|
|
case '\\':
|
|
|
|
cursor++
|
|
|
|
if char(p, cursor) == nul {
|
|
|
|
s.cursor = cursor
|
|
|
|
if s.read() {
|
|
|
|
_, cursor, p = s.statForRetry()
|
|
|
|
continue
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
case '"':
|
|
|
|
goto SWITCH_OUT
|
|
|
|
case nul:
|
|
|
|
s.cursor = cursor
|
|
|
|
if s.read() {
|
|
|
|
_, cursor, p = s.statForRetry()
|
|
|
|
continue
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrUnexpectedEndOfJSON("string of object", cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case nul:
|
|
|
|
s.cursor = cursor
|
|
|
|
if s.read() {
|
|
|
|
_, cursor, p = s.stat()
|
|
|
|
continue
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrUnexpectedEndOfJSON("array of object", cursor)
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
SWITCH_OUT:
|
|
|
|
cursor++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func (s *Stream) skipValue(depth int64) error {
|
2021-08-12 19:03:24 +00:00
|
|
|
_, cursor, p := s.stat()
|
|
|
|
for {
|
|
|
|
switch char(p, cursor) {
|
|
|
|
case ' ', '\n', '\t', '\r':
|
|
|
|
cursor++
|
|
|
|
continue
|
|
|
|
case nul:
|
|
|
|
s.cursor = cursor
|
|
|
|
if s.read() {
|
|
|
|
_, cursor, p = s.stat()
|
|
|
|
continue
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrUnexpectedEndOfJSON("value of object", s.totalOffset())
|
2021-08-12 19:03:24 +00:00
|
|
|
case '{':
|
|
|
|
s.cursor = cursor + 1
|
|
|
|
return s.skipObject(depth + 1)
|
|
|
|
case '[':
|
|
|
|
s.cursor = cursor + 1
|
|
|
|
return s.skipArray(depth + 1)
|
|
|
|
case '"':
|
|
|
|
for {
|
|
|
|
cursor++
|
|
|
|
switch char(p, cursor) {
|
|
|
|
case '\\':
|
|
|
|
cursor++
|
|
|
|
if char(p, cursor) == nul {
|
|
|
|
s.cursor = cursor
|
|
|
|
if s.read() {
|
|
|
|
_, cursor, p = s.statForRetry()
|
|
|
|
continue
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrUnexpectedEndOfJSON("value of string", s.totalOffset())
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
case '"':
|
|
|
|
s.cursor = cursor + 1
|
|
|
|
return nil
|
|
|
|
case nul:
|
|
|
|
s.cursor = cursor
|
|
|
|
if s.read() {
|
|
|
|
_, cursor, p = s.statForRetry()
|
|
|
|
continue
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrUnexpectedEndOfJSON("value of string", s.totalOffset())
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
|
|
|
for {
|
|
|
|
cursor++
|
|
|
|
c := char(p, cursor)
|
|
|
|
if floatTable[c] {
|
|
|
|
continue
|
|
|
|
} else if c == nul {
|
|
|
|
if s.read() {
|
|
|
|
s.cursor-- // for retry current character
|
|
|
|
_, cursor, p = s.stat()
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor = cursor
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case 't':
|
|
|
|
s.cursor = cursor
|
|
|
|
if err := trueBytes(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
case 'f':
|
|
|
|
s.cursor = cursor
|
|
|
|
if err := falseBytes(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
case 'n':
|
|
|
|
s.cursor = cursor
|
|
|
|
if err := nullBytes(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
cursor++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func nullBytes(s *Stream) error {
|
2021-08-12 19:03:24 +00:00
|
|
|
// current cursor's character is 'n'
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 'u' {
|
|
|
|
if err := retryReadNull(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 'l' {
|
|
|
|
if err := retryReadNull(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 'l' {
|
|
|
|
if err := retryReadNull(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func retryReadNull(s *Stream) error {
|
2021-08-12 19:03:24 +00:00
|
|
|
if s.char() == nul && s.read() {
|
|
|
|
return nil
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrInvalidCharacter(s.char(), "null", s.totalOffset())
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func trueBytes(s *Stream) error {
|
2021-08-12 19:03:24 +00:00
|
|
|
// current cursor's character is 't'
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 'r' {
|
|
|
|
if err := retryReadTrue(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 'u' {
|
|
|
|
if err := retryReadTrue(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 'e' {
|
|
|
|
if err := retryReadTrue(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func retryReadTrue(s *Stream) error {
|
2021-08-12 19:03:24 +00:00
|
|
|
if s.char() == nul && s.read() {
|
|
|
|
return nil
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrInvalidCharacter(s.char(), "bool(true)", s.totalOffset())
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func falseBytes(s *Stream) error {
|
2021-08-12 19:03:24 +00:00
|
|
|
// current cursor's character is 'f'
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 'a' {
|
|
|
|
if err := retryReadFalse(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 'l' {
|
|
|
|
if err := retryReadFalse(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 's' {
|
|
|
|
if err := retryReadFalse(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
if s.char() != 'e' {
|
|
|
|
if err := retryReadFalse(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.cursor++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:42:14 +00:00
|
|
|
func retryReadFalse(s *Stream) error {
|
2021-08-12 19:03:24 +00:00
|
|
|
if s.char() == nul && s.read() {
|
|
|
|
return nil
|
|
|
|
}
|
2021-09-10 12:42:14 +00:00
|
|
|
return errors.ErrInvalidCharacter(s.char(), "bool(false)", s.totalOffset())
|
2021-08-12 19:03:24 +00:00
|
|
|
}
|