mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2026-04-23 03:29:51 +08:00
🎨 parse 减少 gjson 使用 优化性能
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type Gift struct {
|
||||
@@ -111,9 +109,9 @@ type ComboSend struct {
|
||||
}
|
||||
|
||||
func (g *Gift) Parse(data []byte) {
|
||||
sb := bytes.NewBuffer(data).String()
|
||||
sd := gjson.Get(sb, "data").String()
|
||||
err := json.Unmarshal([]byte(sd), g)
|
||||
// len("{"cmd":"","data":") == 17 , len('SEND_GIFT') = 9
|
||||
d := data[17+9 : len(data)-1]
|
||||
err := json.Unmarshal(d, g)
|
||||
if err != nil {
|
||||
log.Error("parse Gift failed")
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type GuardBuy struct {
|
||||
@@ -20,9 +18,9 @@ type GuardBuy struct {
|
||||
}
|
||||
|
||||
func (g *GuardBuy) Parse(data []byte) {
|
||||
sb := bytes.NewBuffer(data).String()
|
||||
sd := gjson.Get(sb, "data").String()
|
||||
err := json.Unmarshal([]byte(sd), g)
|
||||
// len("{"cmd":"","data":") = 17 , len('GUARD_BUY') = 9
|
||||
d := data[17+9 : len(data)-1]
|
||||
err := json.Unmarshal(d, g)
|
||||
if err != nil {
|
||||
log.Error("parse GuardBuy failed")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user