summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/internal/encoder/stream.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-03-11 10:12:06 +0000
committerLibravatar GitHub <noreply@github.com>2024-03-11 10:12:06 +0000
commite24efcac8b67baa9454bf27631e5e49f898a88d4 (patch)
treed9adec2f05e1d8714edee66062a4b95a81ee2a61 /vendor/github.com/bytedance/sonic/internal/encoder/stream.go
parent[bugfix] Fix whitespace move_id issue (#2742) (diff)
downloadgotosocial-e24efcac8b67baa9454bf27631e5e49f898a88d4.tar.xz
[chore]: Bump github.com/gin-contrib/cors from 1.5.0 to 1.7.0 (#2745)
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
}