1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-15 14:46:29 +09:00

NetIncomingMessage and NetOutgoingMessage now implements Stream as base class

This commit is contained in:
lidgren
2010-07-13 14:28:34 +00:00
parent 0a65259e86
commit 551dca6d0e
7 changed files with 35 additions and 8 deletions

View File

@@ -56,11 +56,13 @@
<Compile Include="NetIncomingMessage.Peek.cs" />
<Compile Include="NetIncomingMessage.Read.cs" />
<Compile Include="NetIncomingMessage.Read.Reflection.cs" />
<Compile Include="NetIncomingMessage.Stream.cs" />
<Compile Include="NetIncomingMessage.Write.cs" />
<Compile Include="NetIncomingMessageType.cs" />
<Compile Include="NetMessageType.cs" />
<Compile Include="NetNatIntroduction.cs" />
<Compile Include="NetOutgoingMessage.cs" />
<Compile Include="NetOutgoingMessage.Stream.cs" />
<Compile Include="NetOutgoingMessage.Write.cs" />
<Compile Include="NetOutgoingMessage.Write.Reflection.cs" />
<Compile Include="NetPeer.ConnectionApproval.cs" />

View File

@@ -537,7 +537,10 @@ namespace Lidgren.Network
int offset = nr * info.FragmentSize;
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);

View File

@@ -35,10 +35,10 @@ namespace Lidgren.Network
/// <summary>
/// Gets or sets the read position in the buffer, in bits (not bytes)
/// </summary>
public int Position
public override long Position // override of Stream property
{
get { return m_readPosition; }
set { m_readPosition = value; }
get { return (long)m_readPosition; }
set { m_readPosition = (int)value; }
}
static NetIncomingMessage()

View File

@@ -88,7 +88,12 @@ namespace Lidgren.Network
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)
throw new ArgumentNullException("source");

View File

@@ -160,7 +160,7 @@ namespace Lidgren.Network
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)
throw new ArgumentNullException("source");

View File

@@ -12,8 +12,6 @@ namespace ManyServer
public static Form1 MainForm;
public static NetServer Server;
private static double m_lastUpdatedTitle;
[STAThread]
static void Main()
{

View File

@@ -88,6 +88,25 @@ namespace UnitTests
NetException.Assert(readTest.Number == 42);
NetException.Assert(readTest.Name == "Hallon");
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();
}
}