private void HandlePrefix(DataToken dataToken, byte[] buffer, ref int offset, ref int count) { var differBytes = DataToken.PrefixLength - dataToken.PrefixBytesDone; var copyedBytes = count >= differBytes ? differBytes : count; Buffer.BlockCopy(buffer, offset, dataToken.ByteArrayForPrefix, dataToken.PrefixBytesDone, copyedBytes); offset += copyedBytes; count -= copyedBytes; dataToken.PrefixBytesDone += copyedBytes; if (dataToken.IsPrefixReady) { dataToken.MessageLength = BitConverter.ToInt32(dataToken.ByteArrayForPrefix, 0); } }
private void HandleBody(DataToken dataToken, byte[] buffer, ref int offset, ref int count) { if (dataToken.MessageBytesDone == 0) { dataToken.ByteArrayForMessage = new byte[dataToken.MessageLength]; } var differBytes = dataToken.MessageLength - dataToken.MessageBytesDone; var copyedBytes = count >= differBytes ? differBytes : count; Buffer.BlockCopy(buffer, offset, dataToken.ByteArrayForMessage, dataToken.MessageBytesDone, copyedBytes); offset += copyedBytes; count -= copyedBytes; dataToken.MessageBytesDone += copyedBytes; }