summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/internal/encoder/stream.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/bytedance/sonic/internal/encoder/stream.go')
-rw-r--r--vendor/github.com/bytedance/sonic/internal/encoder/stream.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/vendor/github.com/bytedance/sonic/internal/encoder/stream.go b/vendor/github.com/bytedance/sonic/internal/encoder/stream.go
index b6f3ce5fb..d498f68fc 100644
--- a/vendor/github.com/bytedance/sonic/internal/encoder/stream.go
+++ b/vendor/github.com/bytedance/sonic/internal/encoder/stream.go
@@ -36,7 +36,8 @@ func NewStreamEncoder(w io.Writer) *StreamEncoder {
// Encode encodes interface{} as JSON to io.Writer
func (enc *StreamEncoder) Encode(val interface{}) (err error) {
- out := newBytes()
+ buf := newBytes()
+ out := buf
/* encode into the buffer */
err = EncodeInto(&out, val, enc.Opts)
@@ -54,7 +55,9 @@ func (enc *StreamEncoder) Encode(val interface{}) (err error) {
}
// according to standard library, terminate each value with a newline...
- buf.WriteByte('\n')
+ if enc.Opts & NoEncoderNewline == 0 {
+ buf.WriteByte('\n')
+ }
/* copy into io.Writer */
_, err = io.Copy(enc.w, buf)
@@ -75,10 +78,12 @@ func (enc *StreamEncoder) Encode(val interface{}) (err error) {
}
// according to standard library, terminate each value with a newline...
- enc.w.Write([]byte{'\n'})
+ if enc.Opts & NoEncoderNewline == 0 {
+ enc.w.Write([]byte{'\n'})
+ }
}
free_bytes:
- freeBytes(out)
+ freeBytes(buf)
return err
}