|
@@ -1,8 +1,10 @@
|
|
|
package jsoniter
|
|
package jsoniter
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
- "io"
|
|
|
|
|
"bytes"
|
|
"bytes"
|
|
|
|
|
+ "errors"
|
|
|
|
|
+ "io"
|
|
|
|
|
+ "reflect"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// Unmarshal adapts to json/encoding Unmarshal API
|
|
// Unmarshal adapts to json/encoding Unmarshal API
|
|
@@ -12,6 +14,12 @@ import (
|
|
|
func Unmarshal(data []byte, v interface{}) error {
|
|
func Unmarshal(data []byte, v interface{}) error {
|
|
|
data = data[:lastNotSpacePos(data)]
|
|
data = data[:lastNotSpacePos(data)]
|
|
|
iter := ParseBytes(data)
|
|
iter := ParseBytes(data)
|
|
|
|
|
+ typ := reflect.TypeOf(v)
|
|
|
|
|
+ if typ.Kind() != reflect.Ptr {
|
|
|
|
|
+ // return non-pointer error
|
|
|
|
|
+ err = errors.New("the second param must be ptr type")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
iter.ReadVal(v)
|
|
iter.ReadVal(v)
|
|
|
if iter.head == iter.tail {
|
|
if iter.head == iter.tail {
|
|
|
iter.loadMore()
|
|
iter.loadMore()
|
|
@@ -157,4 +165,4 @@ func (adapter *AdaptedEncoder) Encode(val interface{}) error {
|
|
|
|
|
|
|
|
func (adapter *AdaptedEncoder) SetIndent(prefix, indent string) {
|
|
func (adapter *AdaptedEncoder) SetIndent(prefix, indent string) {
|
|
|
// not implemented yet
|
|
// not implemented yet
|
|
|
-}
|
|
|
|
|
|
|
+}
|