You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-18 22:57:33 +02:00
#34 add decoder adapter
This commit is contained in:
@ -99,3 +99,17 @@ func MarshalToString(v interface{}) (string, error) {
|
||||
}
|
||||
return string(buf), nil
|
||||
}
|
||||
|
||||
func NewDecoder(reader io.Reader) *AdaptedDecoder {
|
||||
iter := Parse(reader, 512)
|
||||
return &AdaptedDecoder{iter}
|
||||
}
|
||||
|
||||
type AdaptedDecoder struct {
|
||||
iter *Iterator
|
||||
}
|
||||
|
||||
func (adapter *AdaptedDecoder) Decode(obj interface{}) error {
|
||||
adapter.iter.ReadVal(obj)
|
||||
return adapter.iter.Error
|
||||
}
|
Reference in New Issue
Block a user