1
0
mirror of https://github.com/json-iterator/go.git synced 2025-11-26 22:40:13 +02:00

#164 support interface{} with ptr

This commit is contained in:
Tao Wen
2017-09-09 08:45:57 +08:00
parent 8c7fc7584a
commit 0828e559d0
2 changed files with 23 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"unsafe"
"reflect"
)
type stringCodec struct {
@@ -349,7 +350,12 @@ type emptyInterfaceCodec struct {
}
func (codec *emptyInterfaceCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
*((*interface{})(ptr)) = iter.Read()
existing := *((*interface{})(ptr))
if existing != nil && reflect.TypeOf(existing).Kind() == reflect.Ptr {
iter.ReadVal(existing)
} else {
*((*interface{})(ptr)) = iter.Read()
}
}
func (codec *emptyInterfaceCodec) Encode(ptr unsafe.Pointer, stream *Stream) {