change marshal strategy

This commit is contained in:
hebo
2019-10-08 15:16:42 +08:00
parent 2c54f18374
commit c3531819bd
5 changed files with 20 additions and 7 deletions

View File

@@ -62,7 +62,7 @@ func (mqp *MysqlQueryPiece) Bytes() (content []byte) {
return mqp.jsonContent
}
mqp.jsonContent = marsharQueryPiece(mqp)
mqp.jsonContent = marsharQueryPieceMonopolize(mqp)
return mqp.jsonContent
}

View File

@@ -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
}