From b7b99959761fc322c3135e2bf8e4d38f73597d49 Mon Sep 17 00:00:00 2001 From: zerosnake0 Date: Sun, 21 Mar 2021 12:43:05 +0800 Subject: [PATCH] fix error --- iterator_str.go | 8 ++++---- val_decoder_native_struct.go | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/iterator_str.go b/iterator_str.go index 211923d..eebe5c1 100644 --- a/iterator_str.go +++ b/iterator_str.go @@ -128,8 +128,7 @@ Retry: } // internal, call only after a '"' is consumed -// the result is either a part of the original data -// or a part of the temp buffer, should be copied if +// the result is a part of the temp buffer, should be copied if // the data needs to be saved func (it *Iterator) readStringAsSlice() (_ []byte, err error) { for i := it.head; i < it.tail; i++ { @@ -138,9 +137,9 @@ func (it *Iterator) readStringAsSlice() (_ []byte, err error) { return nil, InvalidStringCharError{c: c} } if c == '"' { - buf := it.buffer[it.head:i] + it.tmpBuffer = append(it.tmpBuffer[:0], it.buffer[it.head:i]...) it.head = i + 1 - return buf, nil + return it.tmpBuffer, nil } else if c == '\\' { buf := append(it.tmpBuffer[:0], it.buffer[it.head:i]...) it.head = i + 1 @@ -158,6 +157,7 @@ func (it *Iterator) readStringAsSlice() (_ []byte, err error) { buf := append(it.tmpBuffer[:0], it.buffer[it.head:it.tail]...) it.head = it.tail if err := it.readMore(); err != nil { + it.tmpBuffer = buf return nil, err } buf, err = it.readStringAsSliceSlow(buf) diff --git a/val_decoder_native_struct.go b/val_decoder_native_struct.go index 9b38c2c..dee1e61 100644 --- a/val_decoder_native_struct.go +++ b/val_decoder_native_struct.go @@ -64,6 +64,7 @@ func (df *decoderFields) add(f *field, dec ValDecoder) { df.list = append(df.list, dfi) } +// key and buf func (df *decoderFields) find(key, buf []byte, caseSensitive bool) (*decoderFieldInfo, []byte) { if i, ok := df.nameIndex[localByteToString(key)]; ok { return &df.list[i], buf @@ -126,7 +127,7 @@ func (dec *structDecoder) Decode(ptr unsafe.Pointer, it *Iterator, _ *DecOpts) ( if err != nil { return err } - stField, fieldOut := dec.fields.find(field, it.tmpBuffer, it.cfg.caseSensitive) + stField, fieldOut := dec.fields.find(field, field, it.cfg.caseSensitive) it.tmpBuffer = fieldOut if stField != nil { curPtr := add(ptr, stField.offsets[0].val, "struct field")