diff --git a/feature_adapter.go b/feature_adapter.go index c799127..673aa20 100644 --- a/feature_adapter.go +++ b/feature_adapter.go @@ -16,7 +16,7 @@ func Unmarshal(data []byte, v interface{}) error { return nil } if iter.Error == nil { - iter.reportError("UnmarshalAny", "there are bytes left after unmarshal") + iter.reportError("Unmarshal", "there are bytes left after unmarshal") } return iter.Error } diff --git a/feature_iter_int.go b/feature_iter_int.go index 5c14b41..20a41f0 100644 --- a/feature_iter_int.go +++ b/feature_iter_int.go @@ -1,6 +1,8 @@ package jsoniter -import "strconv" +import ( + "strconv" +) var intDigits []int8 @@ -124,6 +126,7 @@ func (iter *Iterator) readUint32(c byte) (ret uint32) { for i := iter.head; i < iter.tail; i++ { ind = intDigits[iter.buf[i]] if ind == invalidCharForNumber { + iter.head = i return value } if value > uint32SafeToMultiply10 { @@ -181,6 +184,7 @@ func (iter *Iterator) readUint64(c byte) (ret uint64) { for i := iter.head; i < iter.tail; i++ { ind = intDigits[iter.buf[i]] if ind == invalidCharForNumber { + iter.head = i return value } if value > uint64SafeToMultiple10 { diff --git a/feature_stream.go b/feature_stream.go index 25c7270..dae0835 100644 --- a/feature_stream.go +++ b/feature_stream.go @@ -17,6 +17,10 @@ func NewStream(out io.Writer, bufSize int) *Stream { return &Stream{out, make([]byte, bufSize), 0, nil, 0, 0} } +func (b *Stream) Reset(out io.Writer) { + b.out = out + b.n = 0 +} // Available returns how many bytes are unused in the buffer. func (b *Stream) Available() int { diff --git a/jsoniter_int_test.go b/jsoniter_int_test.go index 0a5dbbe..5bea263 100644 --- a/jsoniter_int_test.go +++ b/jsoniter_int_test.go @@ -64,6 +64,22 @@ func Test_read_int32(t *testing.T) { } } +func Test_read_int32_array(t *testing.T) { + should := require.New(t) + input := `[123,456,789]` + val := make([]int32, 0) + UnmarshalFromString(input, &val) + should.Equal(3, len(val)) +} + +func Test_read_int64_array(t *testing.T) { + should := require.New(t) + input := `[123,456,789]` + val := make([]int64, 0) + UnmarshalFromString(input, &val) + should.Equal(3, len(val)) +} + func Test_read_int32_overflow(t *testing.T) { should := require.New(t) input := "123456789123456789,"