mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2025-12-06 11:22:50 +08:00
fix #23
This commit is contained in:
@@ -2,6 +2,7 @@ package packet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import (
|
|||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/andybalholm/brotli"
|
"github.com/andybalholm/brotli"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -53,11 +54,18 @@ func NewPlainPacket(operation int, body []byte) Packet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewPacketFromBytes(data []byte) Packet {
|
func NewPacketFromBytes(data []byte) Packet {
|
||||||
packLen := binary.BigEndian.Uint32(data[0:4])
|
if len(data) == 0 {
|
||||||
// 校验包长度
|
|
||||||
if int(packLen) != len(data) {
|
|
||||||
log.Error("error packet")
|
log.Error("error packet")
|
||||||
|
return Packet{ProtocolVersion: 1, Operation: uint32(3), Body: make([]byte, 0)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
packLen := binary.BigEndian.Uint32(data[0:4])
|
||||||
|
|
||||||
|
if int(packLen) == 0 || int(packLen) != len(data) {
|
||||||
|
log.Error("error packet")
|
||||||
|
return Packet{ProtocolVersion: 1, Operation: uint32(3), Body: make([]byte, 0)}
|
||||||
|
}
|
||||||
|
|
||||||
pv := binary.BigEndian.Uint16(data[6:8])
|
pv := binary.BigEndian.Uint16(data[6:8])
|
||||||
op := binary.BigEndian.Uint32(data[8:12])
|
op := binary.BigEndian.Uint32(data[8:12])
|
||||||
body := data[16:packLen]
|
body := data[16:packLen]
|
||||||
|
|||||||
Reference in New Issue
Block a user