mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Switch to faster json library go-json and sonic
Former-commit-id: ab9b4723f1dcf79fe5c073fff4d86f4f6969edfd
This commit is contained in:
@ -3,12 +3,13 @@ package obiutils
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
|
||||
"github.com/barkimedes/go-deepcopy"
|
||||
)
|
||||
|
||||
@ -363,9 +364,12 @@ func AtomicCounter(initial ...int) func() int {
|
||||
return nextCounter
|
||||
}
|
||||
|
||||
// JsonMarshalByteBuffer marshals an interface into JSON format.
|
||||
//
|
||||
// It takes a bytes.Buffer as a buffer and an interface{} as i.
|
||||
// Returns an error.
|
||||
func JsonMarshalByteBuffer(buffer *bytes.Buffer, i interface{}) error {
|
||||
encoder := json.NewEncoder(buffer)
|
||||
encoder.SetEscapeHTML(false)
|
||||
encoder := sonic.ConfigDefault.NewEncoder(buffer)
|
||||
err := encoder.Encode(i)
|
||||
b := buffer.Bytes()
|
||||
b = bytes.TrimRight(b, "\n")
|
||||
|
Reference in New Issue
Block a user