Renamed Bytes to ByteArray and added a Reverse method.

pull/288/head
csharptest 14 years ago committed by rogerk
parent 4ba365d793
commit aef072a46f
  1. 19
      src/ProtocolBuffers/ByteArray.cs
  2. 4
      src/ProtocolBuffers/ByteString.cs
  3. 12
      src/ProtocolBuffers/CodedInputStream.cs
  4. 10
      src/ProtocolBuffers/CodedOutputStream.cs
  5. 2
      src/ProtocolBuffers/ProtocolBuffers.csproj
  6. 2
      src/ProtocolBuffers/ProtocolBuffersLite.csproj

@ -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;
}
}
}
}

@ -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>

@ -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)

@ -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)
{
@ -675,7 +675,7 @@ namespace Google.ProtocolBuffers
{
byte[] rawBytes = BitConverter.GetBytes(value);
if (!BitConverter.IsLittleEndian)
Array.Reverse(rawBytes);
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

@ -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" />

@ -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" />

Loading…
Cancel
Save