This commit is contained in:
2025-11-02 01:25:30 +01:00
commit ed18be9fbd
17 changed files with 598 additions and 0 deletions

39
network/udp/enums.go Normal file
View File

@@ -0,0 +1,39 @@
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
}