🎨 parse 减少 gjson 使用 优化性能

This commit is contained in:
Akiba
2022-05-25 17:55:15 +08:00
parent 10d7821c2a
commit b4bc1a280f
3 changed files with 8 additions and 15 deletions

View File

@@ -1,10 +1,8 @@
package message
import (
"bytes"
"encoding/json"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
)
// SuperChat
@@ -72,9 +70,8 @@ type SuperChat struct {
}
func (s *SuperChat) Parse(data []byte) {
sb := bytes.NewBuffer(data).String()
sd := gjson.Get(sb, "data").String()
err := json.Unmarshal([]byte(sd), s)
// len('{"cmd":"","data":') = 17 , len('SUPER_CHAT_MESSAGE') = 18
err := json.Unmarshal(data[17+18:len(data)-1], s)
if err != nil {
log.Error("parse superchat failed")
}