本文整理汇总了C#中Lidgren.Network.NetBuffer.ReadVariableInt32方法的典型用法代码示例。如果您正苦于以下问题:C# NetBuffer.ReadVariableInt32方法的具体用法?C# NetBuffer.ReadVariableInt32怎么用?C# NetBuffer.ReadVariableInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBuffer
的用法示例。
在下文中一共展示了NetBuffer.ReadVariableInt32方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static unsafe void Main(string[] args)
{
// JIT stuff
NetBuffer msg = new NetBuffer(20);
msg.Write((short)short.MaxValue);
// Go
double timeStart = NetTime.Now;
msg = new NetBuffer(20);
for (int n = 0; n < 10000; n++)
{
msg.Reset();
msg.Write((short)short.MaxValue);
msg.Write((short)short.MinValue);
msg.Write((short)-42);
msg.Write(421);
msg.Write((byte)7);
msg.Write(-42.8f);
if (msg.LengthBytes != 15)
throw new Exception("Bad message length");
msg.Write("duke of earl");
int bytesWritten;
bytesWritten = msg.WriteVariableInt32(-1);
bytesWritten = msg.WriteVariableInt32(5);
bytesWritten = msg.WriteVariableInt32(-18);
bytesWritten = msg.WriteVariableInt32(42);
bytesWritten = msg.WriteVariableInt32(-420);
msg.Write((uint)9991);
// byte boundary kept until here
msg.Write(true);
msg.Write((uint)3, 5);
msg.Write(8.111f);
msg.Write("again");
byte[] arr = new byte[] { 1, 6, 12, 24 };
msg.Write(arr);
msg.Write((byte)7, 7);
msg.Write(Int32.MinValue);
msg.Write(UInt32.MaxValue);
msg.WriteRangedSingle(21.0f, -10, 50, 12);
// test reduced bit signed writing
msg.Write(15, 5);
msg.Write(2, 5);
msg.Write(0, 5);
msg.Write(-1, 5);
msg.Write(-2, 5);
msg.Write(-15, 5);
msg.Write(UInt64.MaxValue);
msg.Write(Int64.MaxValue);
msg.Write(Int64.MinValue);
msg.Write(42);
msg.WritePadBits();
int numBits = msg.WriteRangedInteger(0, 10, 5);
if (numBits != 4)
throw new Exception("Ack WriteRangedInteger failed");
// verify
msg.Position = 0;
short a = msg.ReadInt16();
short b = msg.ReadInt16();
short c = msg.ReadInt16();
if (a != short.MaxValue || b != short.MinValue || c != -42)
throw new Exception("Ack thpth short failed");
if (msg.ReadInt32() != 421)
throw new Exception("Ack thphth 1");
if (msg.ReadByte() != (byte)7)
throw new Exception("Ack thphth 2");
if (msg.ReadSingle() != -42.8f)
throw new Exception("Ack thphth 3");
if (msg.ReadString() != "duke of earl")
throw new Exception("Ack thphth 4");
if (msg.ReadVariableInt32() != -1) throw new Exception("ReadVariableInt32 failed 1");
if (msg.ReadVariableInt32() != 5) throw new Exception("ReadVariableInt32 failed 2");
if (msg.ReadVariableInt32() != -18) throw new Exception("ReadVariableInt32 failed 3");
if (msg.ReadVariableInt32() != 42) throw new Exception("ReadVariableInt32 failed 4");
if (msg.ReadVariableInt32() != -420) throw new Exception("ReadVariableInt32 failed 5");
if (msg.ReadUInt32() != 9991)
throw new Exception("Ack thphth 4.5");
if (msg.ReadBoolean() != true)
throw new Exception("Ack thphth 5");
if (msg.ReadUInt32(5) != (uint)3)
throw new Exception("Ack thphth 6");
//.........这里部分代码省略.........