diff options
author | csharptest <roger@csharptest.net> | 2011-06-02 10:52:37 -0500 |
---|---|---|
committer | rogerk <devnull@localhost> | 2011-06-02 10:52:37 -0500 |
commit | 45a93fad4d7123887d14135ee15ee3e9b0d4ca58 (patch) | |
tree | c62c6a5b4159619de112d4d60bb876d834ca4e94 /src/ProtocolBuffers/ByteString.cs | |
parent | efed509b55a1ab6d18b8ef960d799973e7e74544 (diff) | |
download | protobuf-45a93fad4d7123887d14135ee15ee3e9b0d4ca58.tar.gz protobuf-45a93fad4d7123887d14135ee15ee3e9b0d4ca58.tar.bz2 protobuf-45a93fad4d7123887d14135ee15ee3e9b0d4ca58.zip |
Optimized access to ByteString from coded io.
Diffstat (limited to 'src/ProtocolBuffers/ByteString.cs')
-rw-r--r-- | src/ProtocolBuffers/ByteString.cs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ProtocolBuffers/ByteString.cs b/src/ProtocolBuffers/ByteString.cs index 2cce287a..83d4a2df 100644 --- a/src/ProtocolBuffers/ByteString.cs +++ b/src/ProtocolBuffers/ByteString.cs @@ -52,6 +52,14 @@ namespace Google.ProtocolBuffers private readonly byte[] bytes;
/// <summary>
+ /// Internal use only. Ensure that the provided array is not mutated and belongs to this instance.
+ /// </summary>
+ internal static ByteString AttachBytes(byte[] bytes)
+ {
+ return new ByteString(bytes);
+ }
+
+ /// <summary>
/// Constructs a new ByteString from the given byte array. The array is
/// *not* copied, and must not be modified after this constructor is called.
/// </summary>
@@ -237,5 +245,26 @@ namespace Google.ProtocolBuffers get { return output; }
}
}
+
+ internal void WriteTo(CodedOutputStream outputStream)
+ {
+ outputStream.WriteRawBytes(bytes, 0, bytes.Length);
+ }
+
+ /// <summary>
+ /// Copies the entire byte array to the destination array provided at the offset specified.
+ /// </summary>
+ public void CopyTo(Array array, int position)
+ {
+ Array.Copy(bytes, 0, array, position, bytes.Length);
+ }
+
+ /// <summary>
+ /// Writes the entire byte array to the provided stream
+ /// </summary>
+ public void WriteTo(System.IO.Stream outputStream)
+ {
+ outputStream.Write(bytes, 0, bytes.Length);
+ }
}
}
\ No newline at end of file |