Skip to content

Instantly share code, notes, and snippets.

@Matthewacon
Created July 18, 2016 14:09
Show Gist options
  • Save Matthewacon/d89471691ff35210788ed9e348693bbe to your computer and use it in GitHub Desktop.
Save Matthewacon/d89471691ff35210788ed9e348693bbe to your computer and use it in GitHub Desktop.
Rip iteration
Byte* getRelevantData(RakBitStream& stream) {
unsigned long protocolLength = sizeOfArray(protocolInfo);
unsigned long relevantDataLength = sizeOfArray(relevantData);
//Determining the final total length of the byte array to be returned.
unsigned long finalRelevantLength;
for (unsigned long l = 0l; l < relevantDataLength; l++) {
finalRelevantLength += protocolInfo[relevantData[l]];
}
//Allocate the array to store relevant data in
Byte* outArray[finalRelevantLength];
//Read in all stream data
char* streamData = new char[stream.GetNumberOfBytesUsed()];
stream.Read(streamData);
//Populate the outArray
for (unsigned long l = 0l; l < relevantDataLength; l++) {
//Calculate the offset for the current position in the protocolInfo[relevantData['m']]
unsigned long protocolDifference = 0;
for (unsigned long m = l-1; m > -1; m--) {
protocolDifference += protocolInfo[relevantData[m]];
}
//Calculate the offset for the current position in the outArray['n']
unsigned long streamDifference = 0;
for (unsigned long n = l; n > -1; n--) {
streamDifference += protocolInfo[n];
}
//Get the length in bytes of the current position in the protocolInfo[relevantData['l']]
unsigned long protocolLenAtl = protocolInfo[relevantData[l]];
//Populate the current position in outArray['outpos'] with streamData['streampos']
for (unsigned long outpos = protocolDifference, streampos = streamDifference; outpos < (protocolDifference + protocolLenAtl); outpos++, streampos++) {
outArray[outpos] = new Byte(streamData[streampos]);
}
}
return *outArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment