HeaderSize Size of the packet header
const HeaderSize int = 10
StatusBad response status
const StatusBad uint8 = 0x01
StatusOk response status
const StatusOk uint8 = 0x00
StatusPush response status of push
const StatusPush uint8 = 0xff
UDPProtoHeaderSize Size of the UDP packet protocol header
const UDPProtoHeaderSize int = 4
RUDPProtoAck RUDP packet protocol header flag for RUDP ack this flag indicates that the packet is to be treated as the ack packet of dat packet reception
var RUDPProtoAck uint8 = 0x4
RUDPProtoDat RUDP packet protocol header flag for RUDP data this flag indicates that the packet is to be treated as the data packet carrying the actual data payload after syn packet
var RUDPProtoDat uint8 = 0x3
RUDPProtoEack RUDP packet protocol header flag for RUDP eack this flag indicates that the packet is to be trated as the eack of rst packet
var RUDPProtoEack uint8 = 0x6
RUDPProtoFin UDP packet protocol header flag for RUDP fin this flag indicates that the packet is to be treated as the fin packet of RUDP to end RUDP communication
var RUDPProtoFin uint8 = 0x7
RUDPProtoRst RUDP packet protocol header flag for RUDP rst this flag indicates that the packet is to be treated as the retry of dat packet
var RUDPProtoRst uint8 = 0x5
RUDPProtoSyn RUDP packet protocol header flag for RUDP initial syn this flag indicates that the packet is to be treated as the initial URUDP seq synchronization packet
var RUDPProtoSyn uint8 = 0x2
UDPProto UDP packet protocol header flag for UDP this flag indicates the packet is to be treated as a plain UDP packet
var UDPProto uint8 = 0x1
func BoolToBytes(val bool) []byte
BoolToBytes converts bool to bytes
func BytesListToBytes(list [][]byte) []byte
BytesListToBytes converts an array of byte array to byte array
func BytesToBool(bytes []byte) bool
BytesToBool converts bytes to bool
func BytesToBytesList(bytes []byte) [][]byte
BytesToBytesList converts a byte array to an array of byte array
func BytesToStringList(bytes []byte) []string
BytesToStringList Converts a byte array to an array of strings
func CreatePushPacket(version uint8, commandID uint16, payload []byte) []byte
CreatePushPacket Creates a push packet
func CreateReconnectPayload(addr string) []byte
CreateReconnectPayload Creates a payload to instruct the client to reconnect
func CreateRequestPacket(version uint8, commandID uint16, payload []byte) []byte
CreateRequestPacket Creates a request packet
func CreateResponsePacket(version uint8, commandID uint16, status uint8, payload []byte) []byte
CreateResponsePacket Creates a response packet - by giving StatusPush as status, it creates a push packet
func CreateSecureRequestPayload(sid []byte, key []byte, iv []byte, mackey []byte, payload []byte) ([]byte, error)
CreateSecureRequestPayload Creates an encrypted request packet payload
func CreateSecureResponsePayload(key []byte, iv []byte, mackey []byte, payload []byte) ([]byte, error)
CreateSecureResponsePayload Creates an encrypted response packet payload
func CreateSplitPacket(id uint16, bytes []byte, splitSize int) [][]byte
CreateSplitPacket creates an array of split packets
func CreateUDPPacket(flag uint8, seq uint32, packet []byte) ([]byte, error)
CreateUDPPacket Creates a UDP packet from the byte array created by CreateRequestPacket(), CreateResponsePacket(), and CreatePushPacket()
func GetSidFromPayload(payload []byte) ([]byte, []byte)
GetSidFromPayload Returns sid (session ID) and encrypted payload from the given payload
func GetSplitPacketID(bytes []byte) uint16
GetSplitPacketID returns the ID of split packet
func IsInvalidPacketErr(err error) bool
IsInvalidPacketErr Returns true if the given error is an invalid packet error
func IsPushPacket(status uint8) bool
IsPushPacket Returns true if the given packet status is a push packet
func IsSplitPacket(bytes []byte) bool
IsSplitPacket returns true if the evaluated bytes is a split packet chunk
func PackMMAdd(mmID, uniqueID string, maxMembers uint16, reserveOnly bool, props map[string]int, metadata []byte, ttl uint16) []byte
PackMMAdd packs command data into data byte array
func PackMMClaim(roomID string, message []byte) []byte
PackMMClaim packs the command data into data byte array
func PackMMRemove(mmID string, haltFlag bool, uniqueIDs []string, msg []byte) []byte
PackMMRemove packs the command data into data byte array
func PackMMSearch(howmany uint16, joinFlag bool, mmIDs []string, props map[string]int, msg []byte) []byte
PackMMSearch packs the command data into data byte array
func ParseReconnectPayload(payload []byte) string
ParseReconnectPayload converts the given payload to reconnect address
func ParseUDPPacket(packet []byte) (uint8, uint32, []byte, error)
ParseUDPPacket Parses a packet created by CreateUDPPacket()
func StringListToBytes(list []string) []byte
StringListToBytes Converts an array of strings to byte array
MMAdd data structure of MatchMaker's matchmaking add and wait command
BigEndian +-------------+--------------+--------+-------------+-----+-------------+-----+-----+ | Max Members | Reserve Flag | TTL | Size of (1) | (1) | Size of (2) | (2) | (3) | +-------------+--------------+--------+-------------+-----+-------------+-----+-----+ | 2 bytes | 1 byte | 2 byte | 2 byte | (1) | 2 byte | (2) | (3) | +-------------+--------------+--------+-------------+-----+-------------+-----+-----+ (1) - Matchmaking profile ID and UID +------------------------+------------------------+-------------+-------------+ | Size of matchmaking ID | Matchmaking ID | Size of UID | UID | +------------------------+------------------------+-------------+-------------+ | 4 byte | Size of matchmaking ID | 4 byte | Size of UID | +------------------------+------------------------+-------------+-------------+ (2) - Properties For multiple propery values, value, size of name, and name repeats as a data set +---------------+-----------------------+-----------------------+ | Propety Value | Size of property name | Propery name | ... +---------------+-----------------------+-----------------------+ | 4 byte | 2 byte | Size of property name | ... +---------------+-----------------------+-----------------------+ (3) - Metadata +--------------------------------------------------------------+ | Metadata | +--------------------------------------------------------------+ | From the end of properties to the end of the data byte array | +--------------------------------------------------------------+
type MMAdd struct { TTL int64 ID string UID string Props map[string]int Metadata []byte MaxMembers int ReserveOnly bool }
func UnpackMMAdd(bytes []byte) *MMAdd
UnpackMMAdd unpacks the data byte array to data structure
MMClaim MatchMaker's reservation claim command data structure
BigEndian +-----------------+---------+----------------------------------------------+ | Size of room ID | Room ID | Message | +-----------------+---------+----------------------------------------------+ | 2 byte | | end of room ID to the end of data byte array | +-----------------+---------+----------------------------------------------+
type MMClaim struct { RoomID string Message []byte }
func UnpackMMClaim(bytes []byte) *MMClaim
UnpackMMClaim unpacks command data byte array
MMRemove data structure of MatchMaker's remove and abort of matchmaking command
BigEndian +-----------+------------------------+----------------+-------------+-----+-----------------------------------------------+ | Halt Flag | Size of matchmaking ID | Matchmaking ID | Size of UID | UID | Message | +-----------+------------------------+----------------+-------------+-----+-----------------------------------------------+ | 1 byte | 4 byte | | 4 byte | | From end of UID to the end of data byte array | +-----------+------------------------+----------------+-------------+-----+-----------------------------------------------+
type MMRemove struct { HaltFlag bool ID string UIDs []string Message []byte }
func UnpackMMRemove(bytes []byte) *MMRemove
UnpackMMRemove unpacks the data byte array to data struct
MMSearch data structure of MatchMaker's search command
BigEndian +------------------+-----------+------------------------+----------------+--------------------+-----+-----+ | How many results | Join Flag | Size of matchmaking ID | Matchmaking ID | Size of properties | (1) | (2) | +------------------+-----------+------------------------+----------------+--------------------+-----+-----+ | 2 byte | 1 byte | 2 byte | | 2 byte | (1) | (2) | +------------------+-----------+------------------------+----------------+--------------------+-----+-----+ (1) - Properties For multiple propery values, value, size of name, and name repeats as a data set +---------------+-----------------------+-----------------------+ | Propety Value | Size of property name | Propery name | ... +---------------+-----------------------+-----------------------+ | 4 byte | 2 byte | Size of property name | ... +---------------+-----------------------+-----------------------+ (2) Message +------------------------------------------------------+ | Message | +------------------------------------------------------+ | From end of properties to the end of data byte array | +------------------------------------------------------+
type MMSearch struct { HowMany int Join bool IDs []string Props map[string]int Message []byte }
func UnpackMMSearch(bytes []byte) *MMSearch
UnpackMMSearch unpacks data byte array to data structure
RequestHeader Request header data structure
type RequestHeader struct { Version uint8 CommandID uint16 PayloadSize uint32 }
RequestPacket Request packet data structure
type RequestPacket struct { Header *RequestHeader Payload []byte }
func ParseRequestPacket(packet []byte) (*RequestPacket, int, error)
ParseRequestPacket Parses a request packet
ResponseHeader Response header data structure
type ResponseHeader struct { Version uint8 CommandID uint16 PayloadSize uint32 Status uint8 }
ResponsePacket Response packet data structure
type ResponsePacket struct { Header *ResponseHeader Payload []byte Push bool }
func ParseResponsePacket(packet []byte) (*ResponsePacket, int, error)
ParseResponsePacket Parses a response packet
SplitPacket a packet that are split into smaller chunks
type SplitPacket struct { ID uint16 sync.RWMutex // contains filtered or unexported fields }
func NewSplitPacket(bytes []byte) *SplitPacket
NewSplitPacket creates a split packet receiver
func (sp *SplitPacket) Add(bytes []byte) error
Add adds split packet chunk to split packet receiver
func (sp *SplitPacket) ConsumeBytes() ([]byte, bool)
ConsumeBytes returns the reconstructed split bytes