当前位置: 首页>>代码示例>>C#>>正文


C# NetOutgoingMessage.EnsureBufferSize方法代码示例

本文整理汇总了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;
		}
开发者ID:xxy1991,项目名称:cozy,代码行数:21,代码来源:NetCryptoProviderEncryption.cs

示例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;
        }
开发者ID:fgeraci,项目名称:CS195-Core,代码行数:25,代码来源:NetBlockEncryptionBase.cs

示例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;
 }
开发者ID:cody82,项目名称:spacewar-arena,代码行数:13,代码来源:Net.cs


注:本文中的Lidgren.Network.NetOutgoingMessage.EnsureBufferSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。