aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-06-08 18:00:43 -0500
committerrogerk <devnull@localhost>2011-06-08 18:00:43 -0500
commitaef072a46f7c902e6fa1adf18e34f8d4b1eba38a (patch)
tree0de385dfaf8e42a1084665267808344017783504 /src/ProtocolBuffers
parent4ba365d7932ca661640a402c93d2dfb2816ffd62 (diff)
downloadprotobuf-aef072a46f7c902e6fa1adf18e34f8d4b1eba38a.tar.gz
protobuf-aef072a46f7c902e6fa1adf18e34f8d4b1eba38a.tar.bz2
protobuf-aef072a46f7c902e6fa1adf18e34f8d4b1eba38a.zip
Renamed Bytes to ByteArray and added a Reverse method.
Diffstat (limited to 'src/ProtocolBuffers')
-rw-r--r--src/ProtocolBuffers/ByteArray.cs (renamed from src/ProtocolBuffers/Bytes.cs)19
-rw-r--r--src/ProtocolBuffers/ByteString.cs4
-rw-r--r--src/ProtocolBuffers/CodedInputStream.cs12
-rw-r--r--src/ProtocolBuffers/CodedOutputStream.cs12
-rw-r--r--src/ProtocolBuffers/ProtocolBuffers.csproj2
-rw-r--r--src/ProtocolBuffers/ProtocolBuffersLite.csproj2
6 files changed, 32 insertions, 19 deletions
diff --git a/src/ProtocolBuffers/Bytes.cs b/src/ProtocolBuffers/ByteArray.cs
index 88bc16f8..fd0b01e3 100644
--- a/src/ProtocolBuffers/Bytes.cs
+++ b/src/ProtocolBuffers/ByteArray.cs
@@ -3,10 +3,10 @@
/// <summary>
/// Provides a utility routine to copy small arrays much more quickly than Buffer.BlockCopy
/// </summary>
- static class Bytes
+ static class ByteArray
{
/// <summary>
- /// The threshold above which you should use Buffer.BlockCopy rather than Bytes.Copy
+ /// The threshold above which you should use Buffer.BlockCopy rather than ByteArray.Copy
/// </summary>
const int CopyThreshold = 12;
/// <summary>
@@ -20,7 +20,7 @@
ByteCopy(src, srcOffset, dst, dstOffset, count);
}
/// <summary>
- /// Copyies the bytes provided with a for loop, faster when there are only a few bytes to copy
+ /// Copy the bytes provided with a for loop, faster when there are only a few bytes to copy
/// </summary>
public static void ByteCopy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count)
{
@@ -28,5 +28,18 @@
for (int i = srcOffset; i < stop; i++)
dst[dstOffset++] = src[i];
}
+ /// <summary>
+ /// Reverses the order of bytes in the array
+ /// </summary>
+ public static void Reverse(byte[] bytes)
+ {
+ byte temp;
+ for (int first = 0, last = bytes.Length - 1; first < last; first++, last--)
+ {
+ temp = bytes[first];
+ bytes[first] = bytes[last];
+ bytes[last] = temp;
+ }
+ }
}
} \ No newline at end of file
diff --git a/src/ProtocolBuffers/ByteString.cs b/src/ProtocolBuffers/ByteString.cs
index 06708af7..e5f422d4 100644
--- a/src/ProtocolBuffers/ByteString.cs
+++ b/src/ProtocolBuffers/ByteString.cs
@@ -123,7 +123,7 @@ namespace Google.ProtocolBuffers
public static ByteString CopyFrom(byte[] bytes, int offset, int count)
{
byte[] portion = new byte[count];
- Bytes.Copy(bytes, offset, portion, 0, count);
+ ByteArray.Copy(bytes, offset, portion, 0, count);
return new ByteString(portion);
}
@@ -261,7 +261,7 @@ namespace Google.ProtocolBuffers
/// </summary>
public void CopyTo(byte[] array, int position)
{
- Bytes.Copy(bytes, 0, array, position, bytes.Length);
+ ByteArray.Copy(bytes, 0, array, position, bytes.Length);
}
/// <summary>
diff --git a/src/ProtocolBuffers/CodedInputStream.cs b/src/ProtocolBuffers/CodedInputStream.cs
index 105dc378..000065bd 100644
--- a/src/ProtocolBuffers/CodedInputStream.cs
+++ b/src/ProtocolBuffers/CodedInputStream.cs
@@ -213,7 +213,7 @@ namespace Google.ProtocolBuffers
{
byte[] rawBytes = ReadRawBytes(8);
if (!BitConverter.IsLittleEndian)
- Array.Reverse(rawBytes);
+ ByteArray.Reverse(rawBytes);
value = BitConverter.ToDouble(rawBytes, 0);
}
#else
@@ -236,7 +236,7 @@ namespace Google.ProtocolBuffers
{
byte[] rawBytes = ReadRawBytes(4);
if (!BitConverter.IsLittleEndian)
- Array.Reverse(rawBytes);
+ ByteArray.Reverse(rawBytes);
value = BitConverter.ToSingle(rawBytes, 0);
}
return true;
@@ -1240,7 +1240,7 @@ namespace Google.ProtocolBuffers
{
// We have all the bytes we need already.
byte[] bytes = new byte[size];
- Bytes.Copy(buffer, bufferPos, bytes, 0, size);
+ ByteArray.Copy(buffer, bufferPos, bytes, 0, size);
bufferPos += size;
return bytes;
}
@@ -1252,7 +1252,7 @@ namespace Google.ProtocolBuffers
// First copy what we have.
byte[] bytes = new byte[size];
int pos = bufferSize - bufferPos;
- Bytes.Copy(buffer, bufferPos, bytes, 0, pos);
+ ByteArray.Copy(buffer, bufferPos, bytes, 0, pos);
bufferPos = bufferSize;
// We want to use RefillBuffer() and then copy from the buffer into our
@@ -1268,7 +1268,7 @@ namespace Google.ProtocolBuffers
RefillBuffer(true);
}
- Bytes.Copy(buffer, 0, bytes, pos, size - pos);
+ ByteArray.Copy(buffer, 0, bytes, pos, size - pos);
bufferPos = size - pos;
return bytes;
@@ -1320,7 +1320,7 @@ namespace Google.ProtocolBuffers
// Start by copying the leftover bytes from this.buffer.
int newPos = originalBufferSize - originalBufferPos;
- Bytes.Copy(buffer, originalBufferPos, bytes, 0, newPos);
+ ByteArray.Copy(buffer, originalBufferPos, bytes, 0, newPos);
// And now all the chunks.
foreach (byte[] chunk in chunks)
diff --git a/src/ProtocolBuffers/CodedOutputStream.cs b/src/ProtocolBuffers/CodedOutputStream.cs
index bd508661..0bc4a462 100644
--- a/src/ProtocolBuffers/CodedOutputStream.cs
+++ b/src/ProtocolBuffers/CodedOutputStream.cs
@@ -648,7 +648,7 @@ namespace Google.ProtocolBuffers
#if SILVERLIGHT2 || COMPACT_FRAMEWORK_35
byte[] rawBytes = BitConverter.GetBytes(value);
if (!BitConverter.IsLittleEndian)
- Array.Reverse(rawBytes);
+ ByteArray.Reverse(rawBytes);
if (limit - position >= 8)
{
@@ -674,8 +674,8 @@ namespace Google.ProtocolBuffers
public void WriteFloatNoTag(float value)
{
byte[] rawBytes = BitConverter.GetBytes(value);
- if (!BitConverter.IsLittleEndian)
- Array.Reverse(rawBytes);
+ if (!BitConverter.IsLittleEndian)
+ ByteArray.Reverse(rawBytes);
if (limit - position >= 4)
{
@@ -1008,7 +1008,7 @@ namespace Google.ProtocolBuffers
{
if (limit - position >= length)
{
- Bytes.Copy(value, offset, buffer, position, length);
+ ByteArray.Copy(value, offset, buffer, position, length);
// We have room in the current buffer.
position += length;
}
@@ -1017,7 +1017,7 @@ namespace Google.ProtocolBuffers
// Write extends past current buffer. Fill the rest of this buffer and
// flush.
int bytesWritten = limit - position;
- Bytes.Copy(value, offset, buffer, position, bytesWritten);
+ ByteArray.Copy(value, offset, buffer, position, bytesWritten);
offset += bytesWritten;
length -= bytesWritten;
position = limit;
@@ -1029,7 +1029,7 @@ namespace Google.ProtocolBuffers
if (length <= limit)
{
// Fits in new buffer.
- Bytes.Copy(value, offset, buffer, 0, length);
+ ByteArray.Copy(value, offset, buffer, 0, length);
position = length;
}
else
diff --git a/src/ProtocolBuffers/ProtocolBuffers.csproj b/src/ProtocolBuffers/ProtocolBuffers.csproj
index cf212909..336b387f 100644
--- a/src/ProtocolBuffers/ProtocolBuffers.csproj
+++ b/src/ProtocolBuffers/ProtocolBuffers.csproj
@@ -99,7 +99,7 @@
<Compile Include="AbstractMessageLite.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Bytes.cs" />
+ <Compile Include="ByteArray.cs" />
<Compile Include="ByteString.cs" />
<Compile Include="Collections\Enumerables.cs" />
<Compile Include="Collections\IPopsicleList.cs" />
diff --git a/src/ProtocolBuffers/ProtocolBuffersLite.csproj b/src/ProtocolBuffers/ProtocolBuffersLite.csproj
index fc1c7f64..44c92550 100644
--- a/src/ProtocolBuffers/ProtocolBuffersLite.csproj
+++ b/src/ProtocolBuffers/ProtocolBuffersLite.csproj
@@ -78,7 +78,7 @@
<ItemGroup>
<Compile Include="AbstractBuilderLite.cs" />
<Compile Include="AbstractMessageLite.cs" />
- <Compile Include="Bytes.cs" />
+ <Compile Include="ByteArray.cs" />
<Compile Include="CodedOutputStream.ComputeSize.cs" />
<Compile Include="Collections\Dictionaries.cs" />
<Compile Include="Collections\Enumerables.cs" />