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

#34 implement NewEncoder

This commit is contained in:
Tao Wen
2017-06-02 18:46:44 +08:00
parent e36f926072
commit 45bbb40a9f
2 changed files with 31 additions and 0 deletions

View File

@ -125,4 +125,23 @@ func (adapter *AdaptedDecoder) More() bool {
func (adapter *AdaptedDecoder) Buffered() io.Reader {
remaining := adapter.iter.buf[adapter.iter.head:adapter.iter.tail]
return bytes.NewReader(remaining)
}
func NewEncoder(writer io.Writer) *AdaptedEncoder {
stream := NewStream(writer, 512)
return &AdaptedEncoder{stream}
}
type AdaptedEncoder struct {
stream *Stream
}
func (adapter *AdaptedEncoder) Encode(val interface{}) error {
adapter.stream.WriteVal(val)
adapter.stream.Flush()
return adapter.stream.Error
}
func (adapter *AdaptedEncoder) SetIndent(prefix, indent string) {
// not implemented yet
}