aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/ByteString.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2013-05-07 16:12:45 -0500
committerrogerk <devnull@localhost>2013-05-07 16:12:45 -0500
commitfdb4cc7ea5f9ad4af9d9a24611b1ad08531f40f6 (patch)
treead6e31101902e59303e24c07f050f1d4f233b9c1 /src/ProtocolBuffers/ByteString.cs
parent92fcf3537f42475148feaf9a85f800603811ede2 (diff)
downloadprotobuf-fdb4cc7ea5f9ad4af9d9a24611b1ad08531f40f6.tar.gz
protobuf-fdb4cc7ea5f9ad4af9d9a24611b1ad08531f40f6.tar.bz2
protobuf-fdb4cc7ea5f9ad4af9d9a24611b1ad08531f40f6.zip
Adde 'Unsafe' static type in ByteString to allow direct buffer manipulation without
copying bytes. Should be used very cautiously as modifications to buffers may result in unexpected behavior.
Diffstat (limited to 'src/ProtocolBuffers/ByteString.cs')
-rw-r--r--src/ProtocolBuffers/ByteString.cs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ProtocolBuffers/ByteString.cs b/src/ProtocolBuffers/ByteString.cs
index ea17ca1e..8b7bd06c 100644
--- a/src/ProtocolBuffers/ByteString.cs
+++ b/src/ProtocolBuffers/ByteString.cs
@@ -53,6 +53,30 @@ namespace Google.ProtocolBuffers
private readonly byte[] bytes;
/// <summary>
+ /// Unsafe operations that can cause IO Failure and/or other catestrophic side-effects.
+ /// </summary>
+ public static class Unsafe
+ {
+ /// <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>
+ public static ByteString FromBytes(byte[] bytes)
+ {
+ return new ByteString(bytes);
+ }
+
+ /// <summary>
+ /// Provides direct, unrestricted access to the bytes contained in this instance.
+ /// You must not modify or resize the byte array returned by this method.
+ /// </summary>
+ public static byte[] GetBuffer(ByteString bytes)
+ {
+ return bytes.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)