Tidying up and extra tests.

This is mostly just making things internal instead of public, removing and reordering a bunch of code in CodedInputStream/CodedOutputStream, and generally tidying up.
diff --git a/csharp/src/ProtocolBuffers/CodedOutputStream.cs b/csharp/src/ProtocolBuffers/CodedOutputStream.cs
index 99a99ae..161f48f 100644
--- a/csharp/src/ProtocolBuffers/CodedOutputStream.cs
+++ b/csharp/src/ProtocolBuffers/CodedOutputStream.cs
@@ -37,7 +37,6 @@
 using System;

 using System.IO;

 using System.Text;

-using Google.Protobuf.Collections;

 

 namespace Google.Protobuf

 {

@@ -141,11 +140,12 @@
             }

         }

 

-        #region Writing of values without tags

+        #region Writing of values (not including tags)

 

         /// <summary>

-        /// Writes a double field value, including tag, to the stream.

+        /// Writes a double field value, without a tag, to the stream.

         /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteDouble(double value)

         {

             WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));

@@ -154,6 +154,7 @@
         /// <summary>

         /// Writes a float field value, without a tag, to the stream.

         /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteFloat(float value)

         {

             byte[] rawBytes = BitConverter.GetBytes(value);

@@ -178,6 +179,7 @@
         /// <summary>

         /// Writes a uint64 field value, without a tag, to the stream.

         /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteUInt64(ulong value)

         {

             WriteRawVarint64(value);

@@ -186,6 +188,7 @@
         /// <summary>

         /// Writes an int64 field value, without a tag, to the stream.

         /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteInt64(long value)

         {

             WriteRawVarint64((ulong) value);

@@ -194,6 +197,7 @@
         /// <summary>

         /// Writes an int32 field value, without a tag, to the stream.

         /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteInt32(int value)

         {

             if (value >= 0)

@@ -210,6 +214,7 @@
         /// <summary>

         /// Writes a fixed64 field value, without a tag, to the stream.

         /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteFixed64(ulong value)

         {

             WriteRawLittleEndian64(value);

@@ -218,6 +223,7 @@
         /// <summary>

         /// Writes a fixed32 field value, without a tag, to the stream.

         /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteFixed32(uint value)

         {

             WriteRawLittleEndian32(value);

@@ -226,6 +232,7 @@
         /// <summary>

         /// Writes a bool field value, without a tag, to the stream.

         /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteBool(bool value)

         {

             WriteRawByte(value ? (byte) 1 : (byte) 0);

@@ -233,13 +240,15 @@
 

         /// <summary>

         /// Writes a string field value, without a tag, to the stream.

+        /// The data is length-prefixed.

         /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteString(string value)

         {

             // Optimise the case where we have enough space to write

             // the string directly to the buffer, which should be common.

             int length = Utf8Encoding.GetByteCount(value);

-            WriteRawVarint32((uint)length);

+            WriteLength(length);

             if (limit - position >= length)

             {

                 if (length == value.Length) // Must be all ASCII...

@@ -262,23 +271,41 @@
             }

         }

 

+        /// <summary>

+        /// Writes a message, without a tag, to the stream.

+        /// The data is length-prefixed.

+        /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteMessage(IMessage value)

         {

             WriteRawVarint32((uint) value.CalculateSize());

             value.WriteTo(this);

         }

 

+        /// <summary>

+        /// Write a byte string, without a tag, to the stream.

+        /// The data is length-prefixed.

+        /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteBytes(ByteString value)

         {

             WriteRawVarint32((uint) value.Length);

             value.WriteRawBytesTo(this);

         }

 

+        /// <summary>

+        /// Writes a uint32 value, without a tag, to the stream.

+        /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteUInt32(uint value)

         {

             WriteRawVarint32(value);

         }

 

+        /// <summary>

+        /// Writes an enum value, without a tag, to the stream.

+        /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteEnum(int value)

         {

             WriteInt32(value);

@@ -289,27 +316,53 @@
             WriteRawLittleEndian32((uint) value);

         }

 

+        /// <summary>

+        /// Writes an sfixed64 value, without a tag, to the stream.

+        /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteSFixed64(long value)

         {

             WriteRawLittleEndian64((ulong) value);

         }

 

+        /// <summary>

+        /// Writes an sint32 value, without a tag, to the stream.

+        /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteSInt32(int value)

         {

             WriteRawVarint32(EncodeZigZag32(value));

         }

 

+        /// <summary>

+        /// Writes an sint64 value, without a tag, to the stream.

+        /// </summary>

+        /// <param name="value">The value to write</param>

         public void WriteSInt64(long value)

         {

             WriteRawVarint64(EncodeZigZag64(value));

         }

 

+        /// <summary>

+        /// Writes a length (in bytes) for length-delimited data.

+        /// </summary>

+        /// <remarks>

+        /// This method simply writes a rawint, but exists for clarity in calling code.

+        /// </remarks>

+        /// <param name="length">Length value, in bytes.</param>

+        public void WriteLength(int length)

+        {

+            WriteRawVarint32((uint) length);

+        }

+

         #endregion

 

         #region Raw tag writing

         /// <summary>

         /// Encodes and writes a tag.

         /// </summary>

+        /// <param name="fieldNumber">The number of the field to write the tag for</param>

+        /// <param name="type">The wire format type of the tag to write</param>

         public void WriteTag(int fieldNumber, WireFormat.WireType type)

         {

             WriteRawVarint32(WireFormat.MakeTag(fieldNumber, type));

@@ -318,6 +371,7 @@
         /// <summary>

         /// Writes an already-encoded tag.

         /// </summary>

+        /// <param name="tag">The encoded tag</param>

         public void WriteTag(uint tag)

         {

             WriteRawVarint32(tag);

@@ -326,6 +380,7 @@
         /// <summary>

         /// Writes the given single-byte tag directly to the stream.

         /// </summary>

+        /// <param name="b1">The encoded tag</param>

         public void WriteRawTag(byte b1)

         {

             WriteRawByte(b1);

@@ -334,6 +389,8 @@
         /// <summary>

         /// Writes the given two-byte tag directly to the stream.

         /// </summary>

+        /// <param name="b1">The first byte of the encoded tag</param>

+        /// <param name="b2">The second byte of the encoded tag</param>

         public void WriteRawTag(byte b1, byte b2)

         {

             WriteRawByte(b1);

@@ -343,6 +400,9 @@
         /// <summary>

         /// Writes the given three-byte tag directly to the stream.

         /// </summary>

+        /// <param name="b1">The first byte of the encoded tag</param>

+        /// <param name="b2">The second byte of the encoded tag</param>

+        /// <param name="b3">The third byte of the encoded tag</param>

         public void WriteRawTag(byte b1, byte b2, byte b3)

         {

             WriteRawByte(b1);

@@ -353,6 +413,10 @@
         /// <summary>

         /// Writes the given four-byte tag directly to the stream.

         /// </summary>

+        /// <param name="b1">The first byte of the encoded tag</param>

+        /// <param name="b2">The second byte of the encoded tag</param>

+        /// <param name="b3">The third byte of the encoded tag</param>

+        /// <param name="b4">The fourth byte of the encoded tag</param>

         public void WriteRawTag(byte b1, byte b2, byte b3, byte b4)

         {

             WriteRawByte(b1);

@@ -364,6 +428,11 @@
         /// <summary>

         /// Writes the given five-byte tag directly to the stream.

         /// </summary>

+        /// <param name="b1">The first byte of the encoded tag</param>

+        /// <param name="b2">The second byte of the encoded tag</param>

+        /// <param name="b3">The third byte of the encoded tag</param>

+        /// <param name="b4">The fourth byte of the encoded tag</param>

+        /// <param name="b5">The fifth byte of the encoded tag</param>

         public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5)

         {

             WriteRawByte(b1);

@@ -380,7 +449,7 @@
         /// there's enough buffer space left to whizz through without checking

         /// for each byte; otherwise, we resort to calling WriteRawByte each time.

         /// </summary>

-        public void WriteRawVarint32(uint value)

+        internal void WriteRawVarint32(uint value)

         {

             // Optimize for the common case of a single byte value

             if (value < 128 && position < limit)

@@ -409,7 +478,7 @@
             }

         }

 

-        public void WriteRawVarint64(ulong value)

+        internal void WriteRawVarint64(ulong value)

         {

             while (value > 127 && position < limit)

             {

@@ -431,7 +500,7 @@
             }

         }

 

-        public void WriteRawLittleEndian32(uint value)

+        internal void WriteRawLittleEndian32(uint value)

         {

             if (position + 4 > limit)

             {

@@ -449,7 +518,7 @@
             }

         }

 

-        public void WriteRawLittleEndian64(ulong value)

+        internal void WriteRawLittleEndian64(ulong value)

         {

             if (position + 8 > limit)

             {

@@ -475,7 +544,7 @@
             }

         }

 

-        public void WriteRawByte(byte value)

+        internal void WriteRawByte(byte value)

         {

             if (position == limit)

             {

@@ -485,7 +554,7 @@
             buffer[position++] = value;

         }

 

-        public void WriteRawByte(uint value)

+        internal void WriteRawByte(uint value)

         {

             WriteRawByte((byte) value);

         }

@@ -493,7 +562,7 @@
         /// <summary>

         /// Writes out an array of bytes.

         /// </summary>

-        public void WriteRawBytes(byte[] value)

+        internal void WriteRawBytes(byte[] value)

         {

             WriteRawBytes(value, 0, value.Length);

         }

@@ -501,7 +570,7 @@
         /// <summary>

         /// Writes out part of an array of bytes.

         /// </summary>

-        public void WriteRawBytes(byte[] value, int offset, int length)

+        internal void WriteRawBytes(byte[] value, int offset, int length)

         {

             if (limit - position >= length)

             {

@@ -548,7 +617,7 @@
         /// sign-extended to 64 bits to be varint encoded, thus always taking

         /// 10 bytes on the wire.)

         /// </remarks>

-        public static uint EncodeZigZag32(int n)

+        internal static uint EncodeZigZag32(int n)

         {

             // Note:  the right-shift must be arithmetic

             return (uint) ((n << 1) ^ (n >> 31));

@@ -563,7 +632,7 @@
         /// sign-extended to 64 bits to be varint encoded, thus always taking

         /// 10 bytes on the wire.)

         /// </remarks>

-        public static ulong EncodeZigZag64(long n)

+        internal static ulong EncodeZigZag64(long n)

         {

             return (ulong) ((n << 1) ^ (n >> 63));

         }