1
0
mirror of https://github.com/json-iterator/go.git synced 2025-02-10 19:41:53 +02:00
This commit is contained in:
Tao Wen 2017-06-19 23:43:53 +08:00
parent c3f5a2c536
commit f5edf564c8
25 changed files with 44 additions and 48 deletions

View File

@ -94,4 +94,4 @@ func ExampleOneLine() {
fmt.Printf(jsoniter.Get(val, "Colors", 0).ToString()) fmt.Printf(jsoniter.Get(val, "Colors", 0).ToString())
// Output: // Output:
// Crimson // Crimson
} }

View File

@ -43,7 +43,6 @@ func Get(data []byte, path ...interface{}) Any {
return ConfigDefault.Get(data, path...) return ConfigDefault.Get(data, path...)
} }
// Marshal adapts to json/encoding Marshal API // Marshal adapts to json/encoding Marshal API
// //
// Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API // Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API

View File

@ -2,8 +2,8 @@ package jsoniter
import ( import (
"fmt" "fmt"
"reflect"
"io" "io"
"reflect"
) )
type Any interface { type Any interface {

View File

@ -7,9 +7,9 @@ import (
type arrayLazyAny struct { type arrayLazyAny struct {
baseAny baseAny
cfg *frozenConfig cfg *frozenConfig
buf []byte buf []byte
err error err error
} }
func (any *arrayLazyAny) ValueType() ValueType { func (any *arrayLazyAny) ValueType() ValueType {
@ -175,7 +175,7 @@ func (any *arrayLazyAny) GetInterface() interface{} {
type arrayAny struct { type arrayAny struct {
baseAny baseAny
val reflect.Value val reflect.Value
} }
func wrapArray(val interface{}) *arrayAny { func wrapArray(val interface{}) *arrayAny {

View File

@ -4,7 +4,6 @@ import (
"strconv" "strconv"
) )
type floatAny struct { type floatAny struct {
baseAny baseAny
val float64 val float64

View File

@ -6,9 +6,9 @@ import (
type numberLazyAny struct { type numberLazyAny struct {
baseAny baseAny
cfg *frozenConfig cfg *frozenConfig
buf []byte buf []byte
err error err error
} }
func (any *numberLazyAny) ValueType() ValueType { func (any *numberLazyAny) ValueType() ValueType {
@ -103,4 +103,4 @@ func (any *numberLazyAny) GetInterface() interface{} {
iter := any.cfg.BorrowIterator(any.buf) iter := any.cfg.BorrowIterator(any.buf)
defer any.cfg.ReturnIterator(iter) defer any.cfg.ReturnIterator(iter)
return iter.Read() return iter.Read()
} }

View File

@ -158,7 +158,7 @@ func (any *objectLazyAny) Size() int {
defer any.cfg.ReturnIterator(iter) defer any.cfg.ReturnIterator(iter)
iter.ReadObjectCB(func(iter *Iterator, field string) bool { iter.ReadObjectCB(func(iter *Iterator, field string) bool {
iter.Skip() iter.Skip()
size ++ size++
return true return true
}) })
return size return size
@ -187,8 +187,8 @@ func (any *objectLazyAny) GetInterface() interface{} {
type objectAny struct { type objectAny struct {
baseAny baseAny
err error err error
val reflect.Value val reflect.Value
} }
func wrapStruct(val interface{}) *objectAny { func wrapStruct(val interface{}) *objectAny {
@ -342,8 +342,8 @@ func (any *objectAny) GetInterface() interface{} {
type mapAny struct { type mapAny struct {
baseAny baseAny
err error err error
val reflect.Value val reflect.Value
} }
func wrapMap(val interface{}) *mapAny { func wrapMap(val interface{}) *mapAny {

View File

@ -1,8 +1,8 @@
package jsoniter package jsoniter
import ( import (
"strconv"
"fmt" "fmt"
"strconv"
) )
type stringAny struct { type stringAny struct {

View File

@ -1,12 +1,12 @@
package jsoniter package jsoniter
import ( import (
"encoding/json"
"errors" "errors"
"io" "io"
"reflect" "reflect"
"sync/atomic" "sync/atomic"
"unsafe" "unsafe"
"encoding/json"
) )
type Config struct { type Config struct {

View File

@ -65,14 +65,14 @@ func init() {
// Iterator is a fast and flexible JSON parser // Iterator is a fast and flexible JSON parser
type Iterator struct { type Iterator struct {
cfg *frozenConfig cfg *frozenConfig
reader io.Reader reader io.Reader
buf []byte buf []byte
head int head int
tail int tail int
captureStartedAt int captureStartedAt int
captured []byte captured []byte
Error error Error error
} }
// Create creates an empty Iterator instance // Create creates an empty Iterator instance

View File

@ -53,7 +53,7 @@ func (iter *Iterator) stopCapture() []byte {
panic("not in capture mode") panic("not in capture mode")
} }
captured := iter.captured captured := iter.captured
remaining := iter.buf[iter.captureStartedAt: iter.head] remaining := iter.buf[iter.captureStartedAt:iter.head]
iter.captureStartedAt = -1 iter.captureStartedAt = -1
iter.captured = nil iter.captured = nil
if len(captured) == 0 { if len(captured) == 0 {

View File

@ -1,10 +1,10 @@
package jsoniter package jsoniter
import ( import (
"fmt"
"io"
"reflect" "reflect"
"unsafe" "unsafe"
"io"
"fmt"
) )
func decoderOfArray(cfg *frozenConfig, typ reflect.Type) (Decoder, error) { func decoderOfArray(cfg *frozenConfig, typ reflect.Type) (Decoder, error) {

View File

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

View File

@ -1,8 +1,8 @@
package jsoniter package jsoniter
import ( import (
"testing"
"github.com/json-iterator/go/require" "github.com/json-iterator/go/require"
"testing"
) )
func Test_read_bool_as_any(t *testing.T) { func Test_read_bool_as_any(t *testing.T) {

View File

@ -1,8 +1,8 @@
package jsoniter package jsoniter
import ( import (
"testing"
"github.com/json-iterator/go/require" "github.com/json-iterator/go/require"
"testing"
) )
func Test_read_float_as_any(t *testing.T) { func Test_read_float_as_any(t *testing.T) {

View File

@ -1,9 +1,9 @@
package jsoniter package jsoniter
import ( import (
"testing"
"github.com/json-iterator/go/require" "github.com/json-iterator/go/require"
"io" "io"
"testing"
) )
func Test_read_int64_as_any(t *testing.T) { func Test_read_int64_as_any(t *testing.T) {

View File

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

View File

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

View File

@ -1,8 +1,8 @@
package jsoniter package jsoniter
import ( import (
"testing"
"github.com/json-iterator/go/require" "github.com/json-iterator/go/require"
"testing"
) )
func Test_read_object_as_any(t *testing.T) { func Test_read_object_as_any(t *testing.T) {

View File

@ -1,8 +1,8 @@
package jsoniter package jsoniter
import ( import (
"testing"
"github.com/json-iterator/go/require" "github.com/json-iterator/go/require"
"testing"
) )
func Test_read_string_as_any(t *testing.T) { func Test_read_string_as_any(t *testing.T) {
@ -22,4 +22,4 @@ func Test_wrap_string(t *testing.T) {
should := require.New(t) should := require.New(t)
any := WrapString("123") any := WrapString("123")
should.Equal(123, any.ToInt()) should.Equal(123, any.ToInt())
} }

View File

@ -1,9 +1,9 @@
package jsoniter package jsoniter
import ( import (
"testing"
"github.com/json-iterator/go/require"
"encoding/json" "encoding/json"
"github.com/json-iterator/go/require"
"testing"
) )
func Test_encode_fixed_array(t *testing.T) { func Test_encode_fixed_array(t *testing.T) {

View File

@ -120,4 +120,3 @@ func Test_encode_map_with_sorted_keys(t *testing.T) {
should.Nil(err) should.Nil(err)
should.Equal(string(bytes), output) should.Equal(string(bytes), output)
} }

View File

@ -2,9 +2,9 @@ package jsoniter
import ( import (
"bytes" "bytes"
"fmt"
"github.com/json-iterator/go/require" "github.com/json-iterator/go/require"
"testing" "testing"
"fmt"
) )
func Test_empty_object(t *testing.T) { func Test_empty_object(t *testing.T) {

View File

@ -1,9 +1,9 @@
package jsoniter package jsoniter
import ( import (
"testing"
"encoding/json" "encoding/json"
"github.com/json-iterator/go/require" "github.com/json-iterator/go/require"
"testing"
) )
func Test_json_RawMessage(t *testing.T) { func Test_json_RawMessage(t *testing.T) {
@ -38,7 +38,6 @@ func Test_json_RawMessage_in_struct(t *testing.T) {
should.Equal(`hello`, data.Field1) should.Equal(`hello`, data.Field1)
} }
func Test_decode_map_of_raw_message(t *testing.T) { func Test_decode_map_of_raw_message(t *testing.T) {
should := require.New(t) should := require.New(t)
type RawMap map[string]*json.RawMessage type RawMap map[string]*json.RawMessage
@ -72,4 +71,4 @@ func Test_encode_map_of_jsoniter_raw_message(t *testing.T) {
output, err := MarshalToString(rawMap) output, err := MarshalToString(rawMap)
should.Nil(err) should.Nil(err)
should.Equal(`{"hello":[]}`, output) should.Equal(`{"hello":[]}`, output)
} }

View File

@ -1,10 +1,10 @@
package jsoniter package jsoniter
import ( import (
"encoding/json"
"testing"
"github.com/json-iterator/go/require"
"bytes" "bytes"
"encoding/json"
"github.com/json-iterator/go/require"
"testing"
) )
func Test_skip_number(t *testing.T) { func Test_skip_number(t *testing.T) {