Tao Wen 8 rokov pred
rodič
commit
2922666717
4 zmenil súbory, kde vykonal 26 pridanie a 2 odobranie
  1. 1 1
      feature_adapter.go
  2. 5 1
      feature_iter_int.go
  3. 4 0
      feature_stream.go
  4. 16 0
      jsoniter_int_test.go

+ 1 - 1
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
 }

+ 5 - 1
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 {

+ 4 - 0
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 {

+ 16 - 0
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,"