type Packet
A Plain JS object that holds all the info that will be encoded or was decoded from a Buffer.
It's structure is described as a Flow annotation in the example underneath.
sequence
A Number. Keeps track of request/response pair.isFromServer
A Boolean. Indicating that this packet originated on the server.isResponse
A Boolean. Indicating that this is a response to another packet.size
A Number. Indicating the size of the packet.totalWords
A Number. Indicating how many words it is in the data
key.words
An Array. That have the command + arguments.Flow annotation example
type Packet = {
sequence: number;
isFromServer: boolean;
isResponse: boolean;
size: number;
totalWords: number;
words: Array<any>;
}
Request to a server.
let packet = {
sequence: 0,
isFromServer: false,
isResponse: false,
totalWords: 1,
words: ['serverInfo']
};
packet.size = calculatePacketSize(packet.words);
Response from a server.
let packet = {
sequence: 0,
isFromServer: false, // NOTE: isFromServer is still false due to this packet originated on the client.
isResponse: true,
totalWords: 2,
words: ['OK', 'Some server info']
};
packet.size = calculatePacketSize(packet.words);
Request from a server.
let packet = {
sequence: 1,
isFromServer: true,
isResponse: false,
totalWords: 2,
words: ['player.onKill', 'Edvin_1337']
};
packet.size = calculatePacketSize(packet.words);