1
0
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:
Tao Wen
2017-06-02 15:38:20 +08:00
parent 5310d4aa9a
commit 4cc44e7380
2 changed files with 33 additions and 0 deletions

View File

@ -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
}