mirror of https://github.com/goccy/go-json.git
Fix calculating of length for stream decoder
This commit is contained in:
parent
3ec642d31f
commit
23081eadad
|
@ -68,10 +68,7 @@ func (d *mapDecoder) decodeStream(s *stream, depth int64, p unsafe.Pointer) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.skipWhiteSpace()
|
s.skipWhiteSpace()
|
||||||
if s.char() == nul {
|
if !s.equalChar(':') {
|
||||||
s.read()
|
|
||||||
}
|
|
||||||
if s.char() != ':' {
|
|
||||||
return errExpected("colon after object key", s.totalOffset())
|
return errExpected("colon after object key", s.totalOffset())
|
||||||
}
|
}
|
||||||
s.cursor++
|
s.cursor++
|
||||||
|
@ -81,15 +78,12 @@ func (d *mapDecoder) decodeStream(s *stream, depth int64, p unsafe.Pointer) erro
|
||||||
}
|
}
|
||||||
mapassign(d.mapType, mapValue, k, v)
|
mapassign(d.mapType, mapValue, k, v)
|
||||||
s.skipWhiteSpace()
|
s.skipWhiteSpace()
|
||||||
if s.char() == nul {
|
if s.equalChar('}') {
|
||||||
s.read()
|
|
||||||
}
|
|
||||||
if s.char() == '}' {
|
|
||||||
**(**unsafe.Pointer)(unsafe.Pointer(&p)) = mapValue
|
**(**unsafe.Pointer)(unsafe.Pointer(&p)) = mapValue
|
||||||
s.cursor++
|
s.cursor++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if s.char() != ',' {
|
if !s.equalChar(',') {
|
||||||
return errExpected("comma after object value", s.totalOffset())
|
return errExpected("comma after object value", s.totalOffset())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,15 @@ func (s *stream) char() byte {
|
||||||
return s.buf[s.cursor]
|
return s.buf[s.cursor]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *stream) equalChar(c byte) bool {
|
||||||
|
cur := s.buf[s.cursor]
|
||||||
|
if cur == nul {
|
||||||
|
s.read()
|
||||||
|
cur = s.buf[s.cursor]
|
||||||
|
}
|
||||||
|
return cur == c
|
||||||
|
}
|
||||||
|
|
||||||
func (s *stream) stat() ([]byte, int64, unsafe.Pointer) {
|
func (s *stream) stat() ([]byte, int64, unsafe.Pointer) {
|
||||||
return s.buf, s.cursor, (*sliceHeader)(unsafe.Pointer(&s.buf)).data
|
return s.buf, s.cursor, (*sliceHeader)(unsafe.Pointer(&s.buf)).data
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,8 @@ func decodeUnicode(s *stream) error {
|
||||||
unicode := []byte(string(r))
|
unicode := []byte(string(r))
|
||||||
unicodeLen := int64(len(unicode))
|
unicodeLen := int64(len(unicode))
|
||||||
s.buf = append(append(s.buf[:s.cursor-1], unicode...), s.buf[s.cursor+offset:]...)
|
s.buf = append(append(s.buf[:s.cursor-1], unicode...), s.buf[s.cursor+offset:]...)
|
||||||
s.length = int64(len(s.buf))
|
unicodeOrgLen := offset - 1
|
||||||
|
s.length = s.length - (backSlashAndULen + (unicodeOrgLen - unicodeLen))
|
||||||
s.cursor = s.cursor - backSlashAndULen + unicodeLen
|
s.cursor = s.cursor - backSlashAndULen + unicodeLen
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -163,6 +164,7 @@ RETRY:
|
||||||
return errUnexpectedEndOfJSON("string", s.totalOffset())
|
return errUnexpectedEndOfJSON("string", s.totalOffset())
|
||||||
}
|
}
|
||||||
s.buf = append(s.buf[:s.cursor-1], s.buf[s.cursor:]...)
|
s.buf = append(s.buf[:s.cursor-1], s.buf[s.cursor:]...)
|
||||||
|
s.length--
|
||||||
s.cursor--
|
s.cursor--
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue