本文整理汇总了C#中Lidgren.Network.NetOutgoingMessage.EnsureBufferSize方法的典型用法代码示例。如果您正苦于以下问题:C# NetOutgoingMessage.EnsureBufferSize方法的具体用法?C# NetOutgoingMessage.EnsureBufferSize怎么用?C# NetOutgoingMessage.EnsureBufferSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetOutgoingMessage
的用法示例。
在下文中一共展示了NetOutgoingMessage.EnsureBufferSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Encrypt
public override bool Encrypt(NetOutgoingMessage msg)
{
int unEncLenBits = msg.LengthBits;
var ms = new MemoryStream();
var cs = GetEncryptStream(ms);
cs.Write(msg.m_data, 0, msg.LengthBytes);
cs.Close();
// get results
var arr = ms.ToArray();
ms.Close();
msg.EnsureBufferSize((arr.Length + 4) * 8);
msg.LengthBits = 0; // reset write pointer
msg.Write((uint)unEncLenBits);
msg.Write(arr);
msg.LengthBits = (arr.Length + 4) * 8;
return true;
}
示例2: Encrypt
/// <summary>
/// Encrypt am outgoing message with this algorithm; no writing can be done to the message after encryption, or message will be corrupted
/// </summary>
public bool Encrypt(NetOutgoingMessage msg)
{
int payloadBitLength = msg.LengthBits;
int numBytes = msg.LengthBytes;
int blockSize = BlockSize;
int numBlocks = (int)Math.Ceiling((double)numBytes / (double)blockSize);
int dstSize = numBlocks * blockSize;
msg.EnsureBufferSize(dstSize * 8 + (4 * 8)); // add 4 bytes for payload length at end
msg.LengthBits = dstSize * 8; // length will automatically adjust +4 bytes when payload length is written
for (int i = 0; i < numBlocks; i++)
{
EncryptBlock(msg.m_data, (i * blockSize), m_tmp);
Buffer.BlockCopy(m_tmp, 0, msg.m_data, (i * blockSize), m_tmp.Length);
}
// add true payload length last
msg.Write((UInt32)payloadBitLength);
return true;
}
示例3: Compress
public static NetOutgoingMessage Compress(NetOutgoingMessage msg)
{
msg.WritePadBits();
byte[] input = msg.PeekDataBuffer();
byte[] output = new byte[input.Length*2];
int outlength = ZipCompressor.Instance.Compress(input, msg.LengthBytes, output);
msg.EnsureBufferSize(outlength*8);
input = msg.PeekDataBuffer();
Array.Copy(output, input, outlength);
msg.LengthBytes = outlength;
msg.LengthBits = outlength * 8;
return msg;
}