1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-20 11:28:49 +02:00
This commit is contained in:
Tao Wen 2018-02-24 22:04:41 +08:00
parent 8d6662b81b
commit fff342fd04
72 changed files with 165 additions and 176 deletions

4
any.go
View File

@ -3,11 +3,11 @@ package jsoniter
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/v2pro/plz/reflect2"
"io" "io"
"reflect" "reflect"
"unsafe"
"github.com/v2pro/plz/reflect2"
"strconv" "strconv"
"unsafe"
) )
// Any generic object representation. // Any generic object representation.

View File

@ -3,8 +3,8 @@ package any_tests
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_read_empty_array_as_any(t *testing.T) { func Test_read_empty_array_as_any(t *testing.T) {

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
var boolConvertMap = map[string]bool{ var boolConvertMap = map[string]bool{

View File

@ -3,8 +3,8 @@ package any_tests
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
var floatConvertMap = map[string]float64{ var floatConvertMap = map[string]float64{

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
var intConvertMap = map[string]int{ var intConvertMap = map[string]int{

View File

@ -1,9 +1,9 @@
package any_tests package any_tests
import ( import (
"github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"
"github.com/json-iterator/go"
) )
func Test_wrap_map(t *testing.T) { func Test_wrap_map(t *testing.T) {

View File

@ -1,9 +1,9 @@
package any_tests package any_tests
import ( import (
"github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"
"github.com/json-iterator/go"
) )
func Test_read_null_as_any(t *testing.T) { func Test_read_null_as_any(t *testing.T) {

View File

@ -3,8 +3,8 @@ package any_tests
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_read_object_as_any(t *testing.T) { func Test_read_object_as_any(t *testing.T) {
@ -120,4 +120,4 @@ func Test_object_wrapper_any_get_all(t *testing.T) {
should.NotContains(any.Keys(), "Field3") should.NotContains(any.Keys(), "Field3")
//should.Contains(any.GetObject()["Field1"].GetArray()[0], 1) //should.Contains(any.GetObject()["Field1"].GetArray()[0], 1)
} }

View File

@ -3,8 +3,8 @@ package any_tests
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
var stringConvertMap = map[string]string{ var stringConvertMap = map[string]string{

View File

@ -3,8 +3,8 @@ package any_tests
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
// if must be valid is useless, just drop this test // if must be valid is useless, just drop this test

View File

@ -3,8 +3,8 @@ package any_tests
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_wrap_and_valuetype_everything(t *testing.T) { func Test_wrap_and_valuetype_everything(t *testing.T) {

View File

@ -1,10 +1,10 @@
package test package test
import ( import (
"testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go"
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
"testing"
) )
func Test_use_number_for_unmarshal(t *testing.T) { func Test_use_number_for_unmarshal(t *testing.T) {
@ -23,7 +23,6 @@ func Test_customize_float_marshal(t *testing.T) {
should.Equal("1.234568", str) should.Equal("1.234568", str)
} }
func Test_customize_tag_key(t *testing.T) { func Test_customize_tag_key(t *testing.T) {
type TestObject struct { type TestObject struct {
@ -45,4 +44,4 @@ func Test_read_large_number_as_interface(t *testing.T) {
output, err := jsoniter.MarshalToString(val) output, err := jsoniter.MarshalToString(val)
should.Nil(err) should.Nil(err)
should.Equal(`123456789123456789123456789`, output) should.Equal(`123456789123456789123456789`, output)
} }

View File

@ -2,11 +2,11 @@ package test
import ( import (
"bytes" "bytes"
"github.com/stretchr/testify/require"
"testing"
"github.com/json-iterator/go"
"io/ioutil"
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
"io/ioutil"
"testing"
) )
func Test_disallowUnknownFields(t *testing.T) { func Test_disallowUnknownFields(t *testing.T) {
@ -18,7 +18,6 @@ func Test_disallowUnknownFields(t *testing.T) {
should.Error(decoder.Decode(&obj)) should.Error(decoder.Decode(&obj))
} }
func Test_new_decoder(t *testing.T) { func Test_new_decoder(t *testing.T) {
should := require.New(t) should := require.New(t)
decoder1 := json.NewDecoder(bytes.NewBufferString(`[1][2]`)) decoder1 := json.NewDecoder(bytes.NewBufferString(`[1][2]`))

View File

@ -8,8 +8,8 @@ import (
"testing" "testing"
"unicode/utf8" "unicode/utf8"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_new_encoder(t *testing.T) { func Test_new_encoder(t *testing.T) {

View File

@ -1,11 +1,11 @@
package test package test
import ( import (
"testing"
"github.com/stretchr/testify/require"
"bytes" "bytes"
"github.com/json-iterator/go"
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
"testing"
) )
// Standard Encoder has trailing newline. // Standard Encoder has trailing newline.
@ -17,4 +17,4 @@ func TestEncoderHasTrailingNewline(t *testing.T) {
stdenc := json.NewEncoder(&stdbuf) stdenc := json.NewEncoder(&stdbuf)
stdenc.Encode(1) stdenc.Encode(1)
should.Equal(stdbuf.Bytes(), buf.Bytes()) should.Equal(stdbuf.Bytes(), buf.Bytes())
} }

View File

@ -2,9 +2,9 @@ package test
import ( import (
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"
"github.com/json-iterator/go"
) )
func Test_marshal_indent(t *testing.T) { func Test_marshal_indent(t *testing.T) {

View File

@ -2,10 +2,10 @@ package test
import ( import (
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
"github.com/json-iterator/go"
) )
//func Test_large_file(t *testing.T) { //func Test_large_file(t *testing.T) {

View File

@ -2,10 +2,10 @@ package jsoniter
import ( import (
"encoding/json" "encoding/json"
"io"
"unsafe"
"github.com/v2pro/plz/reflect2" "github.com/v2pro/plz/reflect2"
"io"
"sync" "sync"
"unsafe"
) )
// Config customize how the API should behave. // Config customize how the API should behave.

View File

@ -111,7 +111,6 @@ func ExampleMapKey() {
type MyKey string type MyKey string
func (m *MyKey) MarshalText() ([]byte, error) { func (m *MyKey) MarshalText() ([]byte, error) {
return []byte(strings.Replace(string(*m), "h", "H", -1)), nil return []byte(strings.Replace(string(*m), "h", "H", -1)), nil
} }
@ -120,4 +119,3 @@ func (m *MyKey) UnmarshalText(text []byte) error {
*m = MyKey(text[:3]) *m = MyKey(text[:3])
return nil return nil
} }

View File

@ -1,12 +1,12 @@
package test package test
import ( import (
"testing"
"unsafe"
"time"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"strconv" "strconv"
"testing"
"time"
"unsafe"
) )
func Test_customize_type_decoder(t *testing.T) { func Test_customize_type_decoder(t *testing.T) {
@ -61,7 +61,6 @@ func Test_customize_field_decoder(t *testing.T) {
} }
} }
func Test_recursive_empty_interface_customization(t *testing.T) { func Test_recursive_empty_interface_customization(t *testing.T) {
t.Skip() t.Skip()
var obj interface{} var obj interface{}
@ -98,4 +97,4 @@ func Test_read_custom_interface(t *testing.T) {
err := jsoniter.UnmarshalFromString(`"hello"`, &val) err := jsoniter.UnmarshalFromString(`"hello"`, &val)
should.Nil(err) should.Nil(err)
should.Equal("hello", val.Hello()) should.Equal("hello", val.Hello())
} }

View File

@ -1,13 +1,13 @@
package test package test
import ( import (
"unsafe"
"strconv"
"testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
"github.com/v2pro/plz/reflect2" "github.com/v2pro/plz/reflect2"
"reflect" "reflect"
"strconv"
"testing"
"unsafe"
) )
type TestObject1 struct { type TestObject1 struct {

View File

@ -3,9 +3,9 @@ package misc_tests
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"
"github.com/json-iterator/go"
) )
func Test_empty_array(t *testing.T) { func Test_empty_array(t *testing.T) {

View File

@ -4,8 +4,8 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_true(t *testing.T) { func Test_true(t *testing.T) {
@ -44,4 +44,4 @@ func Test_write_val_bool(t *testing.T) {
should.Equal(stream.Buffered(), 0) should.Equal(stream.Buffered(), 0)
should.Nil(stream.Error) should.Nil(stream.Error)
should.Equal("true", buf.String()) should.Equal("true", buf.String())
} }

View File

@ -4,8 +4,8 @@ import (
"encoding/json" "encoding/json"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_read_big_float(t *testing.T) { func Test_read_big_float(t *testing.T) {

View File

@ -9,8 +9,8 @@ import (
"strconv" "strconv"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_read_uint64_invalid(t *testing.T) { func Test_read_uint64_invalid(t *testing.T) {

View File

@ -2,10 +2,10 @@ package misc_tests
import ( import (
"encoding/json" "encoding/json"
"testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
"io" "io"
"testing"
) )
func Test_nil_non_empty_interface(t *testing.T) { func Test_nil_non_empty_interface(t *testing.T) {

View File

@ -7,8 +7,8 @@ import (
"strconv" "strconv"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_bad_case(t *testing.T) { func Test_bad_case(t *testing.T) {

View File

@ -5,9 +5,9 @@ import (
"math/big" "math/big"
"testing" "testing"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"strings" "strings"
"github.com/json-iterator/go"
) )
func Test_decode_TextMarshaler_key_map(t *testing.T) { func Test_decode_TextMarshaler_key_map(t *testing.T) {

View File

@ -2,9 +2,9 @@ package misc_tests
import ( import (
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"reflect" "reflect"
"testing" "testing"
"github.com/json-iterator/go"
) )
type Level1 struct { type Level1 struct {

View File

@ -5,8 +5,8 @@ import (
"io" "io"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_read_null(t *testing.T) { func Test_read_null(t *testing.T) {

View File

@ -4,10 +4,10 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"time" "github.com/stretchr/testify/require"
"strings" "strings"
"time"
) )
func Test_empty_object(t *testing.T) { func Test_empty_object(t *testing.T) {
@ -129,4 +129,4 @@ func Test_reader_and_load_more(t *testing.T) {
decoder := jsoniter.ConfigCompatibleWithStandardLibrary.NewDecoder(reader) decoder := jsoniter.ConfigCompatibleWithStandardLibrary.NewDecoder(reader)
obj := TestObject{} obj := TestObject{}
should.Nil(decoder.Decode(&obj)) should.Nil(decoder.Decode(&obj))
} }

View File

@ -2,10 +2,10 @@ package misc_tests
import ( import (
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"strings" "strings"
"testing" "testing"
"github.com/json-iterator/go"
) )
func Test_jsoniter_RawMessage(t *testing.T) { func Test_jsoniter_RawMessage(t *testing.T) {
@ -45,18 +45,18 @@ func Test_marshal_invalid_json_raw_message(t *testing.T) {
func Test_raw_message_memory_not_copied_issue(t *testing.T) { func Test_raw_message_memory_not_copied_issue(t *testing.T) {
jsonStream := `{"name":"xxxxx","bundle_id":"com.zonst.majiang","app_platform":"ios","app_category":"100103", "budget_day":1000,"bidding_min":1,"bidding_max":2,"bidding_type":"CPM", "freq":{"open":true,"type":"day","num":100},"speed":1, "targeting":{"vendor":{"open":true,"list":["zonst"]}, "geo_code":{"open":true,"list":["156110100"]},"app_category":{"open":true,"list":["100101"]}, "day_parting":{"open":true,"list":["100409","100410"]},"device_type":{"open":true,"list":["ipad"]}, "os_version":{"open":true,"list":[10]},"carrier":{"open":true,"list":["mobile"]}, "network":{"open":true,"list":["4G"]}},"url":{"tracking_imp_url":"http://www.baidu.com", "tracking_clk_url":"http://www.baidu.com","jump_url":"http://www.baidu.com","deep_link_url":"http://www.baidu.com"}}` jsonStream := `{"name":"xxxxx","bundle_id":"com.zonst.majiang","app_platform":"ios","app_category":"100103", "budget_day":1000,"bidding_min":1,"bidding_max":2,"bidding_type":"CPM", "freq":{"open":true,"type":"day","num":100},"speed":1, "targeting":{"vendor":{"open":true,"list":["zonst"]}, "geo_code":{"open":true,"list":["156110100"]},"app_category":{"open":true,"list":["100101"]}, "day_parting":{"open":true,"list":["100409","100410"]},"device_type":{"open":true,"list":["ipad"]}, "os_version":{"open":true,"list":[10]},"carrier":{"open":true,"list":["mobile"]}, "network":{"open":true,"list":["4G"]}},"url":{"tracking_imp_url":"http://www.baidu.com", "tracking_clk_url":"http://www.baidu.com","jump_url":"http://www.baidu.com","deep_link_url":"http://www.baidu.com"}}`
type IteratorObject struct { type IteratorObject struct {
Name *string `json:"name"` Name *string `json:"name"`
BundleId *string `json:"bundle_id"` BundleId *string `json:"bundle_id"`
AppCategory *string `json:"app_category"` AppCategory *string `json:"app_category"`
AppPlatform *string `json:"app_platform"` AppPlatform *string `json:"app_platform"`
BudgetDay *float32 `json:"budget_day"` BudgetDay *float32 `json:"budget_day"`
BiddingMax *float32 `json:"bidding_max"` BiddingMax *float32 `json:"bidding_max"`
BiddingMin *float32 `json:"bidding_min"` BiddingMin *float32 `json:"bidding_min"`
BiddingType *string `json:"bidding_type"` BiddingType *string `json:"bidding_type"`
Freq *jsoniter.RawMessage `json:"freq"` Freq *jsoniter.RawMessage `json:"freq"`
Targeting *jsoniter.RawMessage `json:"targeting"` Targeting *jsoniter.RawMessage `json:"targeting"`
Url *jsoniter.RawMessage `json:"url"` Url *jsoniter.RawMessage `json:"url"`
Speed *int `json:"speed" db:"speed"` Speed *int `json:"speed" db:"speed"`
} }
obj := &IteratorObject{} obj := &IteratorObject{}

View File

@ -2,9 +2,9 @@ package jsoniter
import ( import (
"fmt" "fmt"
"github.com/v2pro/plz/reflect2"
"reflect" "reflect"
"unsafe" "unsafe"
"github.com/v2pro/plz/reflect2"
) )
// ValDecoder is an internal type registered to cache as needed. // ValDecoder is an internal type registered to cache as needed.

View File

@ -2,9 +2,9 @@ package jsoniter
import ( import (
"fmt" "fmt"
"github.com/v2pro/plz/reflect2"
"io" "io"
"unsafe" "unsafe"
"github.com/v2pro/plz/reflect2"
) )
func decoderOfArray(ctx *ctx, typ reflect2.Type) ValDecoder { func decoderOfArray(ctx *ctx, typ reflect2.Type) ValDecoder {

View File

@ -2,8 +2,8 @@ package jsoniter
import ( import (
"github.com/v2pro/plz/reflect2" "github.com/v2pro/plz/reflect2"
"unsafe"
"reflect" "reflect"
"unsafe"
) )
type dynamicEncoder struct { type dynamicEncoder struct {

View File

@ -2,12 +2,12 @@ package jsoniter
import ( import (
"fmt" "fmt"
"github.com/v2pro/plz/reflect2"
"reflect" "reflect"
"sort" "sort"
"strings" "strings"
"unicode" "unicode"
"unsafe" "unsafe"
"github.com/v2pro/plz/reflect2"
) )
var typeDecoders = map[string]ValDecoder{} var typeDecoders = map[string]ValDecoder{}
@ -18,8 +18,8 @@ var extensions = []Extension{}
// StructDescriptor describe how should we encode/decode the struct // StructDescriptor describe how should we encode/decode the struct
type StructDescriptor struct { type StructDescriptor struct {
Type reflect2.Type Type reflect2.Type
Fields []*Binding Fields []*Binding
} }
// GetField get one field from the descriptor by its name. // GetField get one field from the descriptor by its name.
@ -387,8 +387,8 @@ func describeStruct(ctx *ctx, typ reflect2.Type) *StructDescriptor {
} }
func createStructDescriptor(ctx *ctx, typ reflect2.Type, bindings []*Binding, embeddedBindings []*Binding) *StructDescriptor { func createStructDescriptor(ctx *ctx, typ reflect2.Type, bindings []*Binding, embeddedBindings []*Binding) *StructDescriptor {
structDescriptor := &StructDescriptor{ structDescriptor := &StructDescriptor{
Type: typ, Type: typ,
Fields: bindings, Fields: bindings,
} }
for _, extension := range extensions { for _, extension := range extensions {
extension.UpdateStructDescriptor(structDescriptor) extension.UpdateStructDescriptor(structDescriptor)

View File

@ -2,9 +2,9 @@ package jsoniter
import ( import (
"encoding/json" "encoding/json"
"github.com/v2pro/plz/reflect2"
"strconv" "strconv"
"unsafe" "unsafe"
"github.com/v2pro/plz/reflect2"
) )
type Number string type Number string
@ -109,4 +109,4 @@ func (codec *jsoniterNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
func (codec *jsoniterNumberCodec) IsEmpty(ptr unsafe.Pointer) bool { func (codec *jsoniterNumberCodec) IsEmpty(ptr unsafe.Pointer) bool {
return len(*((*Number)(ptr))) == 0 return len(*((*Number)(ptr))) == 0
} }

View File

@ -1,9 +1,9 @@
package jsoniter package jsoniter
import ( import (
"unsafe"
"encoding/json" "encoding/json"
"github.com/v2pro/plz/reflect2" "github.com/v2pro/plz/reflect2"
"unsafe"
) )
var jsonRawMessageType = reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem() var jsonRawMessageType = reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem()
@ -57,4 +57,4 @@ func (codec *jsoniterRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream)
func (codec *jsoniterRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool { func (codec *jsoniterRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool {
return len(*((*RawMessage)(ptr))) == 0 return len(*((*RawMessage)(ptr))) == 0
} }

View File

@ -1,11 +1,11 @@
package jsoniter package jsoniter
import ( import (
"fmt"
"github.com/v2pro/plz/reflect2"
"reflect" "reflect"
"sort" "sort"
"unsafe" "unsafe"
"github.com/v2pro/plz/reflect2"
"fmt"
) )
func decoderOfMap(ctx *ctx, typ reflect2.Type) ValDecoder { func decoderOfMap(ctx *ctx, typ reflect2.Type) ValDecoder {

View File

@ -1,10 +1,10 @@
package jsoniter package jsoniter
import ( import (
"github.com/v2pro/plz/reflect2"
"unsafe"
"encoding" "encoding"
"encoding/json" "encoding/json"
"github.com/v2pro/plz/reflect2"
"unsafe"
) )
var marshalerType = reflect2.TypeOfPtr((*json.Marshaler)(nil)).Elem() var marshalerType = reflect2.TypeOfPtr((*json.Marshaler)(nil)).Elem()

View File

@ -2,10 +2,10 @@ package jsoniter
import ( import (
"encoding/base64" "encoding/base64"
"reflect"
"unsafe"
"github.com/v2pro/plz/reflect2" "github.com/v2pro/plz/reflect2"
"reflect"
"strconv" "strconv"
"unsafe"
) )
const ptrSize = 32 << uintptr(^uintptr(0)>>63) const ptrSize = 32 << uintptr(^uintptr(0)>>63)
@ -405,7 +405,7 @@ func (codec *boolCodec) IsEmpty(ptr unsafe.Pointer) bool {
} }
type base64Codec struct { type base64Codec struct {
sliceType *reflect2.UnsafeSliceType sliceType *reflect2.UnsafeSliceType
sliceDecoder ValDecoder sliceDecoder ValDecoder
} }
@ -418,7 +418,7 @@ func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
case StringValue: case StringValue:
encoding := base64.StdEncoding encoding := base64.StdEncoding
src := iter.SkipAndReturnBytes() src := iter.SkipAndReturnBytes()
src = src[1: len(src)-1] src = src[1 : len(src)-1]
decodedLen := encoding.DecodedLen(len(src)) decodedLen := encoding.DecodedLen(len(src))
dst := make([]byte, decodedLen) dst := make([]byte, decodedLen)
len, err := encoding.Decode(dst, src) len, err := encoding.Decode(dst, src)

View File

@ -1,9 +1,9 @@
package jsoniter package jsoniter
import ( import (
"github.com/v2pro/plz/reflect2"
"reflect" "reflect"
"unsafe" "unsafe"
"github.com/v2pro/plz/reflect2"
) )
func decoderOfOptional(ctx *ctx, typ reflect2.Type) ValDecoder { func decoderOfOptional(ctx *ctx, typ reflect2.Type) ValDecoder {

View File

@ -2,9 +2,9 @@ package jsoniter
import ( import (
"fmt" "fmt"
"github.com/v2pro/plz/reflect2"
"io" "io"
"unsafe" "unsafe"
"github.com/v2pro/plz/reflect2"
) )
func decoderOfSlice(ctx *ctx, typ reflect2.Type) ValDecoder { func decoderOfSlice(ctx *ctx, typ reflect2.Type) ValDecoder {

View File

@ -2,10 +2,10 @@ package jsoniter
import ( import (
"fmt" "fmt"
"github.com/v2pro/plz/reflect2"
"io" "io"
"strings" "strings"
"unsafe" "unsafe"
"github.com/v2pro/plz/reflect2"
) )
func decoderOfStruct(ctx *ctx, typ reflect2.Type) ValDecoder { func decoderOfStruct(ctx *ctx, typ reflect2.Type) ValDecoder {
@ -1031,4 +1031,4 @@ func (decoder *stringModeNumberDecoder) Decode(ptr unsafe.Pointer, iter *Iterato
iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c})) iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c}))
return return
} }
} }

View File

@ -2,10 +2,10 @@ package jsoniter
import ( import (
"fmt" "fmt"
"github.com/v2pro/plz/reflect2"
"io" "io"
"reflect" "reflect"
"unsafe" "unsafe"
"github.com/v2pro/plz/reflect2"
) )
func encoderOfStruct(ctx *ctx, typ reflect2.Type) ValEncoder { func encoderOfStruct(ctx *ctx, typ reflect2.Type) ValEncoder {

View File

@ -5,8 +5,8 @@ import (
"encoding/json" "encoding/json"
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require"
) )
func Test_skip_number_in_array(t *testing.T) { func Test_skip_number_in_array(t *testing.T) {

View File

@ -6,8 +6,8 @@ import (
"github.com/json-iterator/go" "github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"io" "io"
"testing"
"reflect" "reflect"
"testing"
) )
type testCase struct { type testCase struct {

View File

@ -14,4 +14,4 @@ func init() {
`"\t"`, // valid `"\t"`, // valid
}, },
}) })
} }

View File

@ -16,4 +16,4 @@ func init() {
`{abc}`, // invalid `{abc}`, // invalid
}, },
}) })
} }

View File

@ -17,16 +17,16 @@ func init() {
func writeFirstBuf(space []byte, v uint32) []byte { func writeFirstBuf(space []byte, v uint32) []byte {
start := v >> 24 start := v >> 24
if start == 0 { if start == 0 {
space = append(space, byte(v >> 16), byte(v >> 8)) space = append(space, byte(v>>16), byte(v>>8))
} else if start == 1 { } else if start == 1 {
space = append(space, byte(v >> 8)) space = append(space, byte(v>>8))
} }
space = append(space, byte(v)) space = append(space, byte(v))
return space return space
} }
func writeBuf(buf []byte, v uint32) []byte { func writeBuf(buf []byte, v uint32) []byte {
return append(buf, byte(v >> 16), byte(v >> 8), byte(v)) return append(buf, byte(v>>16), byte(v>>8), byte(v))
} }
// WriteUint8 write uint8 to stream // WriteUint8 write uint8 to stream
@ -91,7 +91,7 @@ func (stream *Stream) WriteUint32(val uint32) {
stream.buf = writeFirstBuf(stream.buf, digits[q2]) stream.buf = writeFirstBuf(stream.buf, digits[q2])
} else { } else {
r3 := q2 - q3*1000 r3 := q2 - q3*1000
stream.buf = append(stream.buf, byte(q3 + '0')) stream.buf = append(stream.buf, byte(q3+'0'))
stream.buf = writeBuf(stream.buf, digits[r3]) stream.buf = writeBuf(stream.buf, digits[r3])
} }
stream.buf = writeBuf(stream.buf, digits[r2]) stream.buf = writeBuf(stream.buf, digits[r2])

View File

@ -60,4 +60,4 @@ func init() {
} }
type structEmpty struct{} type structEmpty struct{}
type arrayAlis [4]stringAlias type arrayAlis [4]stringAlias

View File

@ -1,8 +1,8 @@
package test package test
import ( import (
"strings"
"encoding" "encoding"
"strings"
) )
func init() { func init() {
@ -26,7 +26,6 @@ func (k *stringKeyType) UnmarshalText(text []byte) error {
var _ encoding.TextMarshaler = stringKeyType("") var _ encoding.TextMarshaler = stringKeyType("")
var _ encoding.TextUnmarshaler = new(stringKeyType) var _ encoding.TextUnmarshaler = new(stringKeyType)
type structKeyType struct { type structKeyType struct {
X string X string
} }
@ -41,4 +40,4 @@ func (k *structKeyType) UnmarshalText(text []byte) error {
} }
var _ encoding.TextMarshaler = structKeyType{} var _ encoding.TextMarshaler = structKeyType{}
var _ encoding.TextUnmarshaler = &structKeyType{} var _ encoding.TextUnmarshaler = &structKeyType{}

View File

@ -3,8 +3,8 @@ package test
import ( import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"strings"
"encoding/json" "encoding/json"
"strings"
) )
type StringMarshaler string type StringMarshaler string
@ -49,4 +49,4 @@ var _ json.Unmarshaler = new(StringMarshaler)
func init() { func init() {
testCases = append(testCases, (*StringMarshaler)(nil)) testCases = append(testCases, (*StringMarshaler)(nil))
} }

View File

@ -1,10 +1,10 @@
package test package test
import ( import (
"strings"
"encoding/base64"
"bytes" "bytes"
"encoding/base64"
"encoding/json" "encoding/json"
"strings"
) )
type structMarshaler struct { type structMarshaler struct {

View File

@ -91,7 +91,6 @@ func (p *jsonMarshaler) UnmarshalJSON(input []byte) error {
return nil return nil
} }
type jsonMarshalerMap map[int]int type jsonMarshalerMap map[int]int
func (p *jsonMarshalerMap) MarshalJSON() ([]byte, error) { func (p *jsonMarshalerMap) MarshalJSON() ([]byte, error) {
@ -117,11 +116,10 @@ func (p *textMarshaler) UnmarshalText(input []byte) error {
type textMarshalerMap map[int]int type textMarshalerMap map[int]int
func (p *textMarshalerMap) MarshalText() ([]byte, error) { func (p *textMarshalerMap) MarshalText() ([]byte, error) {
return []byte(`{}`), nil return []byte(`{}`), nil
} }
func (p *textMarshalerMap) UnmarshalText(input []byte) error { func (p *textMarshalerMap) UnmarshalText(input []byte) error {
return nil return nil
} }

View File

@ -230,4 +230,4 @@ type EmbeddedPtrOption struct {
type EmbeddedPtr struct { type EmbeddedPtr struct {
EmbeddedPtrOption `json:","` EmbeddedPtrOption `json:","`
} }

View File

@ -192,12 +192,12 @@ type StringFieldNameE struct {
} }
type StringFieldName struct { type StringFieldName struct {
F1 string `json:"F1"` F1 string `json:"F1"`
F2 string `json:"f2"` F2 string `json:"f2"`
F3 string `json:"-"` F3 string `json:"-"`
F4 string `json:"-,"` F4 string `json:"-,"`
F5 string `json:","` F5 string `json:","`
F6 string `json:""` F6 string `json:""`
StringFieldNameE `json:"e"` StringFieldNameE `json:"e"`
} }

View File

@ -1,10 +1,10 @@
package test package test
import ( import (
"strings"
"encoding"
"bytes" "bytes"
"encoding"
"encoding/base64" "encoding/base64"
"strings"
) )
func init() { func init() {

View File

@ -2,9 +2,9 @@ package test
import ( import (
"bytes" "bytes"
"encoding"
"encoding/base64" "encoding/base64"
"strings" "strings"
"encoding"
) )
func init() { func init() {
@ -66,4 +66,4 @@ func (m *structTextMarshaler) UnmarshalText(text []byte) error {
var _ encoding.TextMarshaler = structTextMarshaler{} var _ encoding.TextMarshaler = structTextMarshaler{}
var _ encoding.TextUnmarshaler = &structTextMarshaler{} var _ encoding.TextUnmarshaler = &structTextMarshaler{}
type structTextMarshalerAlias structTextMarshaler type structTextMarshalerAlias structTextMarshaler

View File

@ -1,15 +1,15 @@
package test package test
import ( import (
"testing"
"reflect"
"fmt"
"github.com/google/gofuzz"
"strings"
"github.com/json-iterator/go"
"encoding/json"
"bytes" "bytes"
"encoding/json"
"fmt"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/google/gofuzz"
"github.com/json-iterator/go"
"reflect"
"strings"
"testing"
) )
var testCases []interface{} var testCases []interface{}

View File

@ -8,13 +8,13 @@ func init() {
[2]*float64{}, [2]*float64{},
) )
unmarshalCases = append(unmarshalCases, unmarshalCase{ unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*[0]int)(nil), ptr: (*[0]int)(nil),
input: `[1]`, input: `[1]`,
}, unmarshalCase{ }, unmarshalCase{
ptr: (*[1]int)(nil), ptr: (*[1]int)(nil),
input: `[2]`, input: `[2]`,
}, unmarshalCase{ }, unmarshalCase{
ptr: (*[1]int)(nil), ptr: (*[1]int)(nil),
input: `[]`, input: `[]`,
}) })
} }

View File

@ -8,16 +8,16 @@ func init() {
return &val return &val
} }
unmarshalCases = append(unmarshalCases, unmarshalCase{ unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (**interface{})(nil), ptr: (**interface{})(nil),
input: `"hello"`, input: `"hello"`,
}, unmarshalCase{ }, unmarshalCase{
ptr: (**interface{})(nil), ptr: (**interface{})(nil),
input: `1e1`, input: `1e1`,
}, unmarshalCase{ }, unmarshalCase{
ptr: (**interface{})(nil), ptr: (**interface{})(nil),
input: `1.0e1`, input: `1.0e1`,
}, unmarshalCase{ }, unmarshalCase{
ptr: (*[]interface{})(nil), ptr: (*[]interface{})(nil),
input: `[1.0e1]`, input: `[1.0e1]`,
}, unmarshalCase{ }, unmarshalCase{
ptr: (*struct { ptr: (*struct {
@ -66,12 +66,12 @@ func init() {
}{"hello"}, }{"hello"},
struct { struct {
Field interface{} Field interface{}
}{struct{ }{struct {
field chan int field chan int
}{}}, }{}},
struct { struct {
Field interface{} Field interface{}
}{struct{ }{struct {
Field *int Field *int
}{pInt(100)}}, }{pInt(100)}},
) )

View File

@ -1,13 +1,13 @@
package test package test
import ( import (
"bytes"
"encoding/json"
"fmt" "fmt"
"testing" "github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"strconv" "strconv"
"bytes" "testing"
"github.com/json-iterator/go"
"encoding/json"
) )
func Test_read_float(t *testing.T) { func Test_read_float(t *testing.T) {
@ -50,7 +50,6 @@ func Test_read_float(t *testing.T) {
} }
} }
func Test_write_float32(t *testing.T) { func Test_write_float32(t *testing.T) {
vals := []float32{0, 1, -1, 99, 0xff, 0xfff, 0xffff, 0xfffff, 0xffffff, 0x4ffffff, 0xfffffff, vals := []float32{0, 1, -1, 99, 0xff, 0xfff, 0xffff, 0xfffff, 0xffffff, 0x4ffffff, 0xfffffff,
-0x4ffffff, -0xfffffff, 1.2345, 1.23456, 1.234567, 1.001} -0x4ffffff, -0xfffffff, 1.2345, 1.23456, 1.234567, 1.001}
@ -127,4 +126,4 @@ func Test_write_float64(t *testing.T) {
stream = jsoniter.NewStream(jsoniter.ConfigDefault, nil, 0) stream = jsoniter.NewStream(jsoniter.ConfigDefault, nil, 0)
stream.WriteFloat64(float64(0.0000001)) stream.WriteFloat64(float64(0.0000001))
should.Equal("1e-07", string(stream.Buffer())) should.Equal("1e-07", string(stream.Buffer()))
} }

View File

@ -17,7 +17,7 @@ func init() {
pCloser2("hello"), pCloser2("hello"),
) )
unmarshalCases = append(unmarshalCases, unmarshalCase{ unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*[]io.Closer)(nil), ptr: (*[]io.Closer)(nil),
input: "[null]", input: "[null]",
}, unmarshalCase{ }, unmarshalCase{
obj: func() interface{} { obj: func() interface{} {

View File

@ -1,12 +1,12 @@
package test package test
import ( import (
"bytes"
"fmt"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"strconv" "strconv"
"fmt"
"testing" "testing"
"bytes"
"github.com/json-iterator/go"
) )
func init() { func init() {
@ -158,7 +158,6 @@ func Test_read_int64(t *testing.T) {
} }
} }
func Test_write_uint8(t *testing.T) { func Test_write_uint8(t *testing.T) {
vals := []uint8{0, 1, 11, 111, 255} vals := []uint8{0, 1, 11, 111, 255}
for _, val := range vals { for _, val := range vals {
@ -417,4 +416,4 @@ func Test_write_int64(t *testing.T) {
stream.Flush() stream.Flush()
should.Nil(stream.Error) should.Nil(stream.Error)
should.Equal("a4294967295", buf.String()) should.Equal("a4294967295", buf.String())
} }

View File

@ -3,11 +3,11 @@ package test
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"io" "io"
"testing" "testing"
"github.com/json-iterator/go"
) )
func Test_missing_object_end(t *testing.T) { func Test_missing_object_end(t *testing.T) {
@ -223,4 +223,4 @@ func Test_EmptyInput(t *testing.T) {
if err == nil { if err == nil {
t.Errorf("Expected error") t.Errorf("Expected error")
} }
} }

View File

@ -1,8 +1,8 @@
package test package test
import ( import (
"math/big"
"encoding/json" "encoding/json"
"math/big"
) )
func init() { func init() {
@ -26,16 +26,16 @@ func init() {
}, },
nilMap, nilMap,
&nilMap, &nilMap,
map[string]*json.RawMessage{"hello":pRawMessage(json.RawMessage("[]"))}, map[string]*json.RawMessage{"hello": pRawMessage(json.RawMessage("[]"))},
) )
unmarshalCases = append(unmarshalCases, unmarshalCase{ unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*map[string]string)(nil), ptr: (*map[string]string)(nil),
input: `{"k\"ey": "val"}`, input: `{"k\"ey": "val"}`,
}, unmarshalCase{ }, unmarshalCase{
ptr: (*map[string]string)(nil), ptr: (*map[string]string)(nil),
input: `null`, input: `null`,
}, unmarshalCase{ }, unmarshalCase{
ptr: (*map[string]*json.RawMessage)(nil), ptr: (*map[string]*json.RawMessage)(nil),
input: "{\"test\":[{\"key\":\"value\"}]}", input: "{\"test\":[{\"key\":\"value\"}]}",
}) })
} }

View File

@ -1,8 +1,8 @@
package test package test
import ( import (
"encoding/json"
"encoding" "encoding"
"encoding/json"
) )
func init() { func init() {
@ -17,20 +17,20 @@ func init() {
tmOfStructInt{}, tmOfStructInt{},
&tm2, &tm2,
map[tmOfStruct]int{ map[tmOfStruct]int{
tmOfStruct{}: 100, {}: 100,
}, },
map[*tmOfStruct]int{ map[*tmOfStruct]int{
&tmOfStruct{}: 100, {}: 100,
}, },
map[encoding.TextMarshaler]int{ map[encoding.TextMarshaler]int{
tm1: 100, tm1: 100,
}, },
) )
unmarshalCases = append(unmarshalCases, unmarshalCase{ unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*tmOfMap)(nil), ptr: (*tmOfMap)(nil),
input: `"{1:2}"`, input: `"{1:2}"`,
}, unmarshalCase{ }, unmarshalCase{
ptr: (*tmOfMapPtr)(nil), ptr: (*tmOfMapPtr)(nil),
input: `"{1:2}"`, input: `"{1:2}"`,
}) })
} }
@ -47,7 +47,6 @@ func (q *jmOfStruct) UnmarshalJSON(value []byte) error {
return nil return nil
} }
type tmOfStruct struct { type tmOfStruct struct {
F2 chan []byte F2 chan []byte
} }

View File

@ -7,7 +7,7 @@ func init() {
json.RawMessage("{}"), json.RawMessage("{}"),
) )
unmarshalCases = append(unmarshalCases, unmarshalCase{ unmarshalCases = append(unmarshalCases, unmarshalCase{
ptr: (*json.RawMessage)(nil), ptr: (*json.RawMessage)(nil),
input: `[1,2,3]`, input: `[1,2,3]`,
}) })
} }

View File

@ -1,9 +1,9 @@
package test package test
import ( import (
"testing"
"github.com/json-iterator/go"
"encoding/json" "encoding/json"
"github.com/json-iterator/go"
"testing"
"unicode/utf8" "unicode/utf8"
) )

View File

@ -1,9 +1,9 @@
package test package test
import ( import (
"time"
"encoding/json"
"bytes" "bytes"
"encoding/json"
"time"
) )
func init() { func init() {

View File

@ -1,18 +1,18 @@
package test package test
import ( import (
"testing"
"encoding/json" "encoding/json"
"github.com/stretchr/testify/require"
"github.com/json-iterator/go"
"fmt" "fmt"
"github.com/json-iterator/go"
"github.com/stretchr/testify/require"
"github.com/v2pro/plz/reflect2" "github.com/v2pro/plz/reflect2"
"testing"
) )
type unmarshalCase struct { type unmarshalCase struct {
obj func() interface{} obj func() interface{}
ptr interface{} ptr interface{}
input string input string
selected bool selected bool
} }
@ -22,7 +22,7 @@ var marshalCases = []interface{}{
nil, nil,
} }
type selectedMarshalCase struct { type selectedMarshalCase struct {
marshalCase interface{} marshalCase interface{}
} }
@ -77,4 +77,4 @@ func Test_marshal(t *testing.T) {
should.Equal(string(output1), string(output2)) should.Equal(string(output1), string(output2))
}) })
} }
} }