aboutsummaryrefslogtreecommitdiff
path: root/csharp/ProtocolBuffers/ByteString.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2008-08-14 20:33:30 +0100
committerJon Skeet <skeet@pobox.com>2008-08-14 20:33:30 +0100
commitfe7bb26214916d0eec25e7690ff3580477ede510 (patch)
tree814fad30050df141a0a38df71adc5b3d8326ff14 /csharp/ProtocolBuffers/ByteString.cs
parentc26b43d8cd182cfb5e0317b79c90f1f3f89759ba (diff)
downloadprotobuf-fe7bb26214916d0eec25e7690ff3580477ede510.tar.gz
protobuf-fe7bb26214916d0eec25e7690ff3580477ede510.tar.bz2
protobuf-fe7bb26214916d0eec25e7690ff3580477ede510.zip
Implemented AbstractMethod and split the descriptors into a new package
Diffstat (limited to 'csharp/ProtocolBuffers/ByteString.cs')
-rw-r--r--csharp/ProtocolBuffers/ByteString.cs31
1 files changed, 30 insertions, 1 deletions
diff --git a/csharp/ProtocolBuffers/ByteString.cs b/csharp/ProtocolBuffers/ByteString.cs
index ba3e6512..34aea2df 100644
--- a/csharp/ProtocolBuffers/ByteString.cs
+++ b/csharp/ProtocolBuffers/ByteString.cs
@@ -106,6 +106,35 @@ namespace Google.ProtocolBuffers {
}
// TODO(jonskeet): CopyTo, Equals, GetHashCode if they turn out to be required
- // TODO(jonskeet): Input/Output stuff
+
+ /// <summary>
+ /// Builder for ByteStrings which allows them to be created without extra
+ /// copying being involved. This has to be a nested type in order to have access
+ /// to the private ByteString constructor.
+ /// </summary>
+ internal class CodedBuilder {
+ private readonly CodedOutputStream output;
+ private readonly byte[] buffer;
+
+ internal CodedBuilder(int size) {
+ buffer = new byte[size];
+ output = CodedOutputStream.CreateInstance(buffer);
+ }
+
+ public ByteString Build() {
+ output.CheckNoSpaceLeft();
+
+ // We can be confident that the CodedOutputStream will not modify the
+ // underlying bytes anymore because it already wrote all of them. So,
+ // no need to make a copy.
+ return new ByteString(buffer);
+ }
+
+ public CodedOutputStream CodedOutput {
+ get {
+ return output;
+ }
+ }
+ }
}
}