You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 23:56:30 +09:00
NetIncomingMessage and NetOutgoingMessage now implements Stream as base class
This commit is contained in:
@@ -56,11 +56,13 @@
|
|||||||
<Compile Include="NetIncomingMessage.Peek.cs" />
|
<Compile Include="NetIncomingMessage.Peek.cs" />
|
||||||
<Compile Include="NetIncomingMessage.Read.cs" />
|
<Compile Include="NetIncomingMessage.Read.cs" />
|
||||||
<Compile Include="NetIncomingMessage.Read.Reflection.cs" />
|
<Compile Include="NetIncomingMessage.Read.Reflection.cs" />
|
||||||
|
<Compile Include="NetIncomingMessage.Stream.cs" />
|
||||||
<Compile Include="NetIncomingMessage.Write.cs" />
|
<Compile Include="NetIncomingMessage.Write.cs" />
|
||||||
<Compile Include="NetIncomingMessageType.cs" />
|
<Compile Include="NetIncomingMessageType.cs" />
|
||||||
<Compile Include="NetMessageType.cs" />
|
<Compile Include="NetMessageType.cs" />
|
||||||
<Compile Include="NetNatIntroduction.cs" />
|
<Compile Include="NetNatIntroduction.cs" />
|
||||||
<Compile Include="NetOutgoingMessage.cs" />
|
<Compile Include="NetOutgoingMessage.cs" />
|
||||||
|
<Compile Include="NetOutgoingMessage.Stream.cs" />
|
||||||
<Compile Include="NetOutgoingMessage.Write.cs" />
|
<Compile Include="NetOutgoingMessage.Write.cs" />
|
||||||
<Compile Include="NetOutgoingMessage.Write.Reflection.cs" />
|
<Compile Include="NetOutgoingMessage.Write.Reflection.cs" />
|
||||||
<Compile Include="NetPeer.ConnectionApproval.cs" />
|
<Compile Include="NetPeer.ConnectionApproval.cs" />
|
||||||
|
|||||||
@@ -537,7 +537,10 @@ namespace Lidgren.Network
|
|||||||
int offset = nr * info.FragmentSize;
|
int offset = nr * info.FragmentSize;
|
||||||
|
|
||||||
if (im.m_data.Length < offset + payloadLength)
|
if (im.m_data.Length < offset + payloadLength)
|
||||||
Array.Resize<byte>(ref im.m_data, offset + payloadLength);
|
{
|
||||||
|
byte[] arr = im.m_data;
|
||||||
|
Array.Resize<byte>(ref arr, offset + payloadLength);
|
||||||
|
}
|
||||||
|
|
||||||
Buffer.BlockCopy(m_owner.m_receiveBuffer, ptr, im.m_data, offset, payloadLength);
|
Buffer.BlockCopy(m_owner.m_receiveBuffer, ptr, im.m_data, offset, payloadLength);
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,10 @@ namespace Lidgren.Network
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the read position in the buffer, in bits (not bytes)
|
/// Gets or sets the read position in the buffer, in bits (not bytes)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Position
|
public override long Position // override of Stream property
|
||||||
{
|
{
|
||||||
get { return m_readPosition; }
|
get { return (long)m_readPosition; }
|
||||||
set { m_readPosition = value; }
|
set { m_readPosition = (int)value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static NetIncomingMessage()
|
static NetIncomingMessage()
|
||||||
|
|||||||
@@ -88,7 +88,12 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += bits;
|
m_bitLength += bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Write(byte[] source, int offsetInBytes, int numberOfBytes)
|
public override void Write(byte[] source, int offsetInBytes, int numberOfBytes)
|
||||||
|
{
|
||||||
|
throw new NetException("NetIncomingMessage does not support writing!");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void WriteBytes(byte[] source, int offsetInBytes, int numberOfBytes)
|
||||||
{
|
{
|
||||||
if (source == null)
|
if (source == null)
|
||||||
throw new ArgumentNullException("source");
|
throw new ArgumentNullException("source");
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += bits;
|
m_bitLength += bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(byte[] source, int offsetInBytes, int numberOfBytes)
|
public override void Write(byte[] source, int offsetInBytes, int numberOfBytes)
|
||||||
{
|
{
|
||||||
if (source == null)
|
if (source == null)
|
||||||
throw new ArgumentNullException("source");
|
throw new ArgumentNullException("source");
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ namespace ManyServer
|
|||||||
public static Form1 MainForm;
|
public static Form1 MainForm;
|
||||||
public static NetServer Server;
|
public static NetServer Server;
|
||||||
|
|
||||||
private static double m_lastUpdatedTitle;
|
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,6 +88,25 @@ namespace UnitTests
|
|||||||
NetException.Assert(readTest.Number == 42);
|
NetException.Assert(readTest.Number == 42);
|
||||||
NetException.Assert(readTest.Name == "Hallon");
|
NetException.Assert(readTest.Name == "Hallon");
|
||||||
NetException.Assert(readTest.Age == 8.2f);
|
NetException.Assert(readTest.Age == 8.2f);
|
||||||
|
|
||||||
|
msg = peer.CreateMessage();
|
||||||
|
|
||||||
|
System.IO.BinaryWriter br = new System.IO.BinaryWriter(msg);
|
||||||
|
|
||||||
|
br.Write(true);
|
||||||
|
br.Write("hallon");
|
||||||
|
br.Write((byte)42);
|
||||||
|
|
||||||
|
int byteLen = msg.LengthBytes;
|
||||||
|
byte[] rbts = msg.PeekDataBuffer();
|
||||||
|
|
||||||
|
inc = Program.CreateIncomingMessage(rbts, msg.LengthBits);
|
||||||
|
|
||||||
|
System.IO.BinaryReader rdr = new System.IO.BinaryReader(inc);
|
||||||
|
|
||||||
|
bool one = rdr.ReadBoolean();
|
||||||
|
string hallon = rdr.ReadString();
|
||||||
|
byte fourtyTwo = rdr.ReadByte();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user