1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

string any

This commit is contained in:
Tao Wen
2017-01-23 08:33:43 +08:00
parent d49ea1bc49
commit b9fe012eea
7 changed files with 206 additions and 18 deletions

View File

@ -2,7 +2,6 @@ package jsoniter
import (
"io"
"unsafe"
"bytes"
)
@ -10,6 +9,9 @@ import (
func Unmarshal(data []byte, v interface{}) error {
iter := ParseBytes(data)
iter.ReadVal(v)
if iter.head == iter.tail {
iter.loadMore()
}
if iter.Error == io.EOF {
return nil
}
@ -22,6 +24,9 @@ func Unmarshal(data []byte, v interface{}) error {
func UnmarshalAny(data []byte) (Any, error) {
iter := ParseBytes(data)
any := iter.ReadAny()
if iter.head == iter.tail {
iter.loadMore()
}
if iter.Error == io.EOF {
return any, nil
}
@ -32,10 +37,12 @@ func UnmarshalAny(data []byte) (Any, error) {
}
func UnmarshalFromString(str string, v interface{}) error {
// safe to do the unsafe cast here, as str is always referenced in this scope
data := *(*[]byte)(unsafe.Pointer(&str))
data := []byte(str)
iter := ParseBytes(data)
iter.ReadVal(v)
if iter.head == iter.tail {
iter.loadMore()
}
if iter.Error == io.EOF {
return nil
}
@ -46,10 +53,12 @@ func UnmarshalFromString(str string, v interface{}) error {
}
func UnmarshalAnyFromString(str string) (Any, error) {
// safe to do the unsafe cast here, as str is always referenced in this scope
data := *(*[]byte)(unsafe.Pointer(&str))
data := []byte(str)
iter := ParseBytes(data)
any := iter.ReadAny()
if iter.head == iter.tail {
iter.loadMore()
}
if iter.Error == io.EOF {
return any, nil
}