🎨 byte-string convert

This commit is contained in:
Akiba
2022-06-04 09:15:46 +08:00
parent b4bc1a280f
commit 95bc1bedaa

View File

@@ -1,8 +1,7 @@
package message package message
import ( import (
"bytes" "github.com/Akegarasu/blivedm-go/utils"
"encoding/json"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
@@ -60,15 +59,15 @@ type (
) )
func (d *Danmaku) Parse(data []byte) { func (d *Danmaku) Parse(data []byte) {
sb := bytes.NewBuffer(data).String() sb := utils.BytesToString(data)
info := gjson.Get(sb, "info") info := gjson.Parse(sb).Get("info")
ext := new(Extra) ext := new(Extra)
emo := new(Emoticon) emo := new(Emoticon)
err := json.Unmarshal([]byte(info.Get("0.15.extra").String()), ext) err := utils.UnmarshalString(info.Get("0.15.extra").String(), ext)
if err != nil { if err != nil {
log.Error("parse danmuku extra failed") log.Error("parse danmuku extra failed")
} }
err = json.Unmarshal([]byte(info.Get("0.13").String()), emo) err = utils.UnmarshalString(info.Get("0.13").String(), emo)
if err != nil { if err != nil {
log.Error("parse danmuku emoticon failed") log.Error("parse danmuku emoticon failed")
} }