You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nnet/packet/ws.go

38 lines
615 B
Go

package packet
import "fmt"
type WSPacket struct {
MessageType int
Len uint64
Raw []byte
}
func NewWSPacket(typ int, data []byte) IPacket {
l := len(data)
raw := make([]byte, l)
copy(raw, data)
return &WSPacket{
MessageType: typ,
Len: uint64(l),
Raw: raw,
}
}
func (p *WSPacket) GetHeader() any {
return p.MessageType
}
func (p *WSPacket) GetLen() uint64 {
return p.Len
}
func (p *WSPacket) GetBody() []byte {
return p.Raw
}
func (p *WSPacket) String() string {
return fmt.Sprintf("MessageType=%d, Len=%d, RawStr=%s", p.MessageType, p.Len, string(p.Raw))
}