Fix stream decoder

This commit is contained in:
Masaaki Goshima 2021-05-08 01:56:58 +09:00
parent ab068b0858
commit f3167760ff
2 changed files with 10 additions and 1 deletions

View File

@ -82,7 +82,14 @@ func (s *stream) readBuf() []byte {
copy(s.buf, remainBuf) copy(s.buf, remainBuf)
} }
remainLen := s.length - s.cursor remainLen := s.length - s.cursor
return s.buf[s.cursor+remainLen:] remainNotNulCharNum := int64(0)
for i := int64(0); i < remainLen; i++ {
if s.buf[s.cursor+i] == nul {
break
}
remainNotNulCharNum++
}
return s.buf[s.cursor+remainNotNulCharNum:]
} }
func (s *stream) read() bool { func (s *stream) read() bool {

View File

@ -213,6 +213,7 @@ func stringBytes(s *stream) ([]byte, error) {
s.buf = append(append(append([]byte{}, s.buf[:cursor]...), runeErrBytes...), s.buf[cursor+1:]...) s.buf = append(append(append([]byte{}, s.buf[:cursor]...), runeErrBytes...), s.buf[cursor+1:]...)
_, _, p = s.stat() _, _, p = s.stat()
cursor += runeErrBytesLen cursor += runeErrBytesLen
s.length += runeErrBytesLen
continue continue
case nul: case nul:
s.cursor = cursor s.cursor = cursor
@ -238,6 +239,7 @@ func stringBytes(s *stream) ([]byte, error) {
_, _, p = s.stat() _, _, p = s.stat()
} }
cursor += int64(len(b)) cursor += int64(len(b))
s.length += int64(len(b))
continue continue
} }
cursor++ cursor++