mirror of
https://github.com/zr-hebo/sniffer-agent.git
synced 2025-08-11 19:58:42 +08:00
change marshal strategy
This commit is contained in:
@@ -62,7 +62,7 @@ func (mqp *MysqlQueryPiece) Bytes() (content []byte) {
|
||||
return mqp.jsonContent
|
||||
}
|
||||
|
||||
mqp.jsonContent = marsharQueryPiece(mqp)
|
||||
mqp.jsonContent = marsharQueryPieceMonopolize(mqp)
|
||||
return mqp.jsonContent
|
||||
}
|
||||
|
||||
|
@@ -1,13 +1,15 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
// "github.com/json-iterator/go"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/pingcap/tidb/util/hack"
|
||||
"time"
|
||||
)
|
||||
|
||||
var jsonIterator = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
type QueryPiece interface {
|
||||
String() *string
|
||||
Bytes() []byte
|
||||
@@ -70,7 +72,7 @@ func (bqp *BaseQueryPiece) Bytes() (content []byte) {
|
||||
return bqp.jsonContent
|
||||
}
|
||||
|
||||
bqp.jsonContent = marsharQueryPiece(bqp)
|
||||
bqp.jsonContent = marsharQueryPieceMonopolize(bqp)
|
||||
return bqp.jsonContent
|
||||
}
|
||||
|
||||
@@ -81,7 +83,7 @@ func (bqp *BaseQueryPiece) GetSQL() (*string) {
|
||||
func (bqp *BaseQueryPiece) Recovery() {
|
||||
}
|
||||
|
||||
func marsharQueryPiece(qp interface{}) []byte {
|
||||
func marsharQueryPieceShareMemory(qp interface{}) []byte {
|
||||
var cacheBuffer = localSliceBufferPool.Dequeue()
|
||||
if len(cacheBuffer) > 0 {
|
||||
panic("there already have bytes in buffer")
|
||||
@@ -95,3 +97,12 @@ func marsharQueryPiece(qp interface{}) []byte {
|
||||
|
||||
return buffer.Bytes()
|
||||
}
|
||||
|
||||
func marsharQueryPieceMonopolize(qp interface{}) (content []byte) {
|
||||
content, err := jsonIterator.Marshal(qp)
|
||||
if err != nil {
|
||||
return []byte(err.Error())
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
Reference in New Issue
Block a user