🎨 byte-string convert

This commit is contained in:
Akiba
2022-06-04 09:21:59 +08:00
parent 7ed9b1f5b4
commit f69fa04863
3 changed files with 9 additions and 12 deletions

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"
) )
@@ -111,9 +110,9 @@ type ComboSend struct {
} }
func (g *Gift) Parse(data []byte) { func (g *Gift) Parse(data []byte) {
sb := bytes.NewBuffer(data).String() sb := utils.BytesToString(data)
sd := gjson.Get(sb, "data").String() sd := gjson.Get(sb, "data").String()
err := json.Unmarshal([]byte(sd), g) err := utils.UnmarshalString(sd, g)
if err != nil { if err != nil {
log.Error("parse Gift failed") log.Error("parse Gift failed")
} }

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"
) )
@@ -20,9 +19,9 @@ type GuardBuy struct {
} }
func (g *GuardBuy) Parse(data []byte) { func (g *GuardBuy) Parse(data []byte) {
sb := bytes.NewBuffer(data).String() sb := utils.BytesToString(data)
sd := gjson.Get(sb, "data").String() sd := gjson.Get(sb, "data").String()
err := json.Unmarshal([]byte(sd), g) err := utils.UnmarshalString(sd, g)
if err != nil { if err != nil {
log.Error("parse GuardBuy failed") log.Error("parse GuardBuy failed")
} }

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"
) )
@@ -72,9 +71,9 @@ type SuperChat struct {
} }
func (s *SuperChat) Parse(data []byte) { func (s *SuperChat) Parse(data []byte) {
sb := bytes.NewBuffer(data).String() sb := utils.BytesToString(data)
sd := gjson.Get(sb, "data").String() sd := gjson.Get(sb, "data").String()
err := json.Unmarshal([]byte(sd), s) err := utils.UnmarshalString(sd, s)
if err != nil { if err != nil {
log.Error("parse superchat failed") log.Error("parse superchat failed")
} }