HTML and CSS Reference
In-Depth Information
int dataLength=_inputBuffer[1] & 0x7F;
int actualLength;
int dataIndex=0;
byte[] length=new byte[8];
byte[] masks=new byte[4];
// Depending on the initial data length, get the actual length
// and the maskingkey from the appropriate bytes.
if (dataLength == 126)
{
dataIndex=4;
Array.Copy(_inputBuffer, 2, length, 0, 2);
actualLength=BitConverter.ToInt16(length, 0);
if (masked)
Array.Copy(_inputBuffer, 4, masks, 0, 4);
}
else if (dataLength == 127)
{
dataIndex=10;
Array.Copy(_inputBuffer, 2, length, 0, 8);
actualLength=(int)BitConverter.ToInt64(length, 0);
if (masked)
Array.Copy(_inputBuffer, 10, masks, 0, 4);
}
else
{
dataIndex=2;
actualLength=dataLength;
if (masked)
Array.Copy(_inputBuffer, 2, masks, 0, 4);
}
// If a mask is supplied, skip another 4 bytes
if (masked)
dataIndex += 4;
// Get the actual data in the payload array
byte[] payload=new byte[actualLength];
Array.Copy(_inputBuffer, dataIndex, payload, 0, dataLength);
// Unmask the data, if necessary
if (masked)
{
for (int i=0; i<actualLength; i++)
{
payload[i]=(byte)(payload[i] ^ masks[i % 4]);
}
}
Search WWH ::




Custom Search