diff --git a/decode_stream.go b/decode_stream.go index c5009a3..da75e8f 100644 --- a/decode_stream.go +++ b/decode_stream.go @@ -82,7 +82,14 @@ func (s *stream) readBuf() []byte { copy(s.buf, remainBuf) } 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 { diff --git a/decode_string.go b/decode_string.go index fc9aae2..8f1b0e5 100644 --- a/decode_string.go +++ b/decode_string.go @@ -213,6 +213,7 @@ func stringBytes(s *stream) ([]byte, error) { s.buf = append(append(append([]byte{}, s.buf[:cursor]...), runeErrBytes...), s.buf[cursor+1:]...) _, _, p = s.stat() cursor += runeErrBytesLen + s.length += runeErrBytesLen continue case nul: s.cursor = cursor @@ -238,6 +239,7 @@ func stringBytes(s *stream) ([]byte, error) { _, _, p = s.stat() } cursor += int64(len(b)) + s.length += int64(len(b)) continue } cursor++