Author: alanmc
Date: 2008-02-02 11:24:21 -0500 (Sat, 02 Feb 2008)
New Revision: 94634
Modified:
trunk/bitsharp/src/MonoTorrent/MonoTorrent.Client/Messages/Message.cs
Log:
Tidied up the Write() overloads
Modified: trunk/bitsharp/src/MonoTorrent/MonoTorrent.Client/Messages/Message.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/MonoTorrent.Client/Messages/Message.cs
2008-02-02 16:23:42 UTC (rev 94633)
+++ trunk/bitsharp/src/MonoTorrent/MonoTorrent.Client/Messages/Message.cs
2008-02-02 16:24:21 UTC (rev 94634)
@@ -57,10 +57,10 @@
return 1;
}
- static protected int Write(byte[] buffer, int offset, byte[] value)
+ static protected int Write(byte[] buffer, int offset, byte[] value,
int valueOffset, int count)
{
- Buffer.BlockCopy(value, 0, buffer, offset, value.Length);
- return value.Length;
+ Buffer.BlockCopy(value, valueOffset, buffer, offset, count);
+ return count;
}
static protected int Write(byte[] buffer, int offset, ushort value)
@@ -68,18 +68,18 @@
return Write(buffer, offset, (short)value);
}
+ private static int Write(byte[] buffer, int offset, byte[] value)
+ {
+ return Write(buffer, offset, value, 0, value.Length);
+ }
static protected int Write(byte[] buffer, int offset, short value)
{
- byte[] temp =
BitConverter.GetBytes(IPAddress.HostToNetworkOrder(value));
- Buffer.BlockCopy(temp, 0, buffer, offset, temp.Length);
- return temp.Length;
+ return Write(buffer, offset,
BitConverter.GetBytes(IPAddress.HostToNetworkOrder(value)));
}
static protected int Write(byte[] buffer, int offset, int value)
{
- byte[] temp =
BitConverter.GetBytes(IPAddress.HostToNetworkOrder(value));
- Buffer.BlockCopy(temp, 0, buffer, offset, temp.Length);
- return temp.Length;
+ return Write(buffer, offset,
BitConverter.GetBytes(IPAddress.HostToNetworkOrder(value)));
}
static protected int Write(byte[] buffer, int offset, uint value)
@@ -89,9 +89,7 @@
static protected int Write(byte[] buffer, int offset, long value)
{
- byte[] temp =
BitConverter.GetBytes(IPAddress.HostToNetworkOrder(value));
- Buffer.BlockCopy(temp, 0, buffer, offset, temp.Length);
- return temp.Length;
+ return Write(buffer, offset,
BitConverter.GetBytes(IPAddress.HostToNetworkOrder(value)));
}
static protected int Write(byte[] buffer, int offset, ulong value)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches