Optimized access to ByteString from coded io.
diff --git a/src/ProtocolBuffers/CodedOutputStream.cs b/src/ProtocolBuffers/CodedOutputStream.cs
index f905b35..f30c806 100644
--- a/src/ProtocolBuffers/CodedOutputStream.cs
+++ b/src/ProtocolBuffers/CodedOutputStream.cs
@@ -54,7 +54,7 @@
/// methods are taken from the protocol buffer type names, not .NET types.
/// (Hence WriteFloat instead of WriteSingle, and WriteBool instead of WriteBoolean.)
/// </remarks>
- public sealed class CodedOutputStream
+ public sealed partial class CodedOutputStream
{
/// <summary>
/// The buffer size used by CreateInstance(Stream).
@@ -257,11 +257,9 @@
public void WriteBytes(int fieldNumber, ByteString value)
{
- // TODO(jonskeet): Optimise this! (No need to copy the bytes twice.)
WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited);
- byte[] bytes = value.ToByteArray();
- WriteRawVarint32((uint) bytes.Length);
- WriteRawBytes(bytes);
+ WriteRawVarint32((uint)value.Length);
+ value.WriteTo(this);
}
[CLSCompliant(false)]
@@ -564,10 +562,8 @@
public void WriteBytesNoTag(ByteString value)
{
- // TODO(jonskeet): Optimise this! (No need to copy the bytes twice.)
- byte[] bytes = value.ToByteArray();
- WriteRawVarint32((uint) bytes.Length);
- WriteRawBytes(bytes);
+ WriteRawVarint32((uint)value.Length);
+ value.WriteTo(this);
}
[CLSCompliant(false)]