maxapi: use fastjson parser pool

This commit is contained in:
c9s 2021-06-26 21:03:03 +08:00 committed by c9s
parent 2bd93b4d25
commit 905148a34f
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -16,10 +16,13 @@ var ErrIncorrectBookEntryElementLength = errors.New("incorrect book entry elemen
const Buy = 1
const Sell = -1
var parserPool fastjson.ParserPool
// ParseMessage accepts the raw messages from max public websocket channels and parses them into market data
// Return types: *BookEvent, *PublicTradeEvent, *SubscriptionEvent, *ErrorEvent
func ParseMessage(payload []byte) (interface{}, error) {
parser := fastjson.Parser{}
parser := parserPool.Get()
val, err := parser.ParseBytes(payload)
if err != nil {
return nil, errors.Wrap(err, "failed to parse payload: "+string(payload))