40 lines
778 B
Go
40 lines
778 B
Go
package udp
|
|
|
|
import (
|
|
//"encoding/binary"
|
|
//"errors"
|
|
//"fmt"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type PacketType uint8
|
|
|
|
const (
|
|
PacketTypePing PacketType = 0
|
|
PacketTypeConnect PacketType = 1
|
|
PacketTypeDisconnect PacketType = 2
|
|
PacketTypeVoiceData PacketType = 9
|
|
)
|
|
|
|
type Message interface {
|
|
Type() PacketType
|
|
MarshalBinary() ([]byte, error)
|
|
Size() int
|
|
}
|
|
|
|
// MessagePing ClientPing représente un message ping client
|
|
type MessagePing struct {
|
|
MessageID uuid.UUID
|
|
}
|
|
|
|
func (m *MessagePing) Type() PacketType { return PacketTypePing }
|
|
func (m *MessagePing) Size() int { return 17 } // 1 + 16
|
|
|
|
func (m *MessagePing) MarshalBinary() ([]byte, error) {
|
|
buf := make([]byte, m.Size())
|
|
buf[0] = byte(PacketTypePing)
|
|
copy(buf[1:], m.MessageID[:])
|
|
return buf, nil
|
|
}
|