本文整理汇总了C#中RakNet.BitStream.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# BitStream.Serialize方法的具体用法?C# BitStream.Serialize怎么用?C# BitStream.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RakNet.BitStream
的用法示例。
在下文中一共展示了BitStream.Serialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessMessage
public void ProcessMessage()
{
while (!_bStop)
{
_packet = _peer.Receive();
while (_packet != null)
{
byte messageType = _packet.data[0];
if (messageType < (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
{
DefaultMessageIDTypes idType = (DefaultMessageIDTypes)messageType;
switch (idType)
{
case DefaultMessageIDTypes.ID_CONNECTION_REQUEST_ACCEPTED:
Log.Info("In a client/server environment, our connection request to the server has been accepted.\n");
break;
case DefaultMessageIDTypes.ID_CONNECTION_ATTEMPT_FAILED:
Log.Info("Sent to the player when a connection request cannot be completed due to inability to connect.\n ");
break;
case DefaultMessageIDTypes.ID_ALREADY_CONNECTED:
Log.Info("Sent a connect request to a system we are currently connected to.\n ");
break;
case DefaultMessageIDTypes.ID_NEW_INCOMING_CONNECTION:
Log.Info("A remote system has successfully connected.\n");
break;
case DefaultMessageIDTypes.ID_DISCONNECTION_NOTIFICATION:
Log.Info(" A remote system has disconnected. \n");
break;
case DefaultMessageIDTypes.ID_CONNECTION_LOST:
Log.Info(" The connection to that system has been closed. \n");
break;
}
}
else
{
if (messageType == (byte)FT_MessageTypes.ID_SERVER_LOGIN)
{
byte dataType = _packet.data[1];
RakNet.BitStream bsIn = new RakNet.BitStream(_packet.data, _packet.length, false);
bsIn.IgnoreBytes(2);
FT_UnitData unitData = new FT_UnitData();
unitData.session.Serialize(false, bsIn);
unitData.Serialize(false, bsIn);
Log.Info("" + unitData.sInfo.C_String());
byte serverLogin = (byte)RakNet.FT_MessageTypes.ID_SERVER_LOGIN;
RakNet.BitStream bsOut = new RakNet.BitStream();
bsOut.Serialize(true, ref serverLogin);
bsOut.Serialize(true, ref dataType);
unitData.session.Serialize(true, bsOut);
unitData.Serialize(true, bsOut);
uint sendLength = _peer.Send(bsOut,
RakNet.PacketPriority.IMMEDIATE_PRIORITY,
RakNet.PacketReliability.RELIABLE_ORDERED, (char)0,
_packet.systemAddress,
false);
Log.Info("SendLength:" + sendLength);
}
}
Log.Info(string.Format("Receive Data. [0] = {0}, Length = {1}", _packet.data[0], _packet.data.Length));
_peer.DeallocatePacket(_packet);
_packet = _peer.Receive();
}
System.Threading.Thread.Sleep(30);
}
}
示例2: Main
//.........这里部分代码省略.........
//AddressOrGUID
Console.WriteLine("AddressOrGUID");
AddressOrGUID testAddressOrGUIDAddress = new AddressOrGUID(testSystemAddress);
Console.WriteLine(testAddressOrGUIDAddress.systemAddress);
AddressOrGUID testAddressOrGUIDRakNetGUID = new AddressOrGUID(testRakNetGUID);
Console.WriteLine(testAddressOrGUIDRakNetGUID.rakNetGuid);
//BitStream
Console.WriteLine("BitStream");
BitStream testBitStream1 = new BitStream();
BitStream testBitStream2 = new BitStream();
byte[] testBuffer = new byte[999];
byte[] writeArray = new byte[99];
Packet bitStreamTestPacket = null;
testBitStream1.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
testBitStream1.ResetWritePointer();
testBitStream1.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
writeArray[0] = (byte)127;
testBitStream1.Write("xy");
testBitStream1.WriteCompressed("xy");
testBitStream1.WriteFloat16(23.5f, 0, 100);
testBitStream1.WriteBits(writeArray, 7);
testBitStream1.WriteAlignedBytesSafe(writeArray, 1, 1);
testBitStream1.WriteAlignedBytes(writeArray, 1);
testBitStream1.Write0();
testBitStream1.Write1();
int intForSerialization = 99;
testBitStream1.Serialize(true, ref intForSerialization);
testClient.Send(testBitStream1, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS), true);
while (bitStreamTestPacket == null || bitStreamTestPacket.data[0] != (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
{
if (bitStreamTestPacket != null)
{
testServer.DeallocatePacket(bitStreamTestPacket);
}
bitStreamTestPacket = testServer.Receive();
testClient.Send(testBitStream1, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS), true);
}
testBitStream2.Reset();
testBitStream2 = new BitStream(bitStreamTestPacket.data, bitStreamTestPacket.length, true);
testBitStream2.IgnoreBytes(1);
testBitStream2.ResetReadPointer();
testBitStream2.IgnoreBits(8);
testBitStream2.ResetReadPointer();
testBitStream2.ReadBits(testBuffer, 8);
Console.WriteLine(testBuffer[0]);
Console.WriteLine(DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
testBitStream2.ResetReadPointer();
testBitStream2.ReadAlignedVar8(testBuffer);
Console.WriteLine(testBuffer[0]);
testBitStream2.ResetReadPointer();
testBitStream2.ReadAlignedVar16(testBuffer);
Console.WriteLine(testBuffer[1]);
testBitStream2.ResetReadPointer();
testBitStream2.ReadAlignedVar32(testBuffer);
Console.WriteLine(testBuffer[1]);