diff --git a/csharp/src/Google.Protobuf/MessageExtensions.cs b/csharp/src/Google.Protobuf/MessageExtensions.cs
index 047156c3ee..9dbc49d6bf 100644
--- a/csharp/src/Google.Protobuf/MessageExtensions.cs
+++ b/csharp/src/Google.Protobuf/MessageExtensions.cs
@@ -53,6 +53,22 @@ namespace Google.Protobuf
input.CheckReadEndOfStreamTag();
}
+ ///
+ /// Merges data from the given byte array slice into an existing message.
+ ///
+ /// The message to merge the data into.
+ /// The data containing the slice to merge, which must be protobuf-encoded binary data.
+ /// The offset of the slice to merge.
+ /// The length of the slice to merge.
+ public static void MergeFrom(this IMessage message, byte[] data, int offset, int length)
+ {
+ ProtoPreconditions.CheckNotNull(message, "message");
+ ProtoPreconditions.CheckNotNull(data, "data");
+ CodedInputStream input = new CodedInputStream(data, offset, length);
+ message.MergeFrom(input);
+ input.CheckReadEndOfStreamTag();
+ }
+
///
/// Merges data from the given byte string into an existing message.
///
diff --git a/csharp/src/Google.Protobuf/MessageParser.cs b/csharp/src/Google.Protobuf/MessageParser.cs
index 8889638b20..569414b0c7 100644
--- a/csharp/src/Google.Protobuf/MessageParser.cs
+++ b/csharp/src/Google.Protobuf/MessageParser.cs
@@ -70,6 +70,21 @@ namespace Google.Protobuf
return message;
}
+ ///
+ /// Parses a message from a byte array slice.
+ ///
+ /// The byte array containing the message. Must not be null.
+ /// The offset of the slice to parse.
+ /// The length of the slice to parse.
+ /// The newly parsed message.
+ public IMessage ParseFrom(byte[] data, int offset, int length)
+ {
+ ProtoPreconditions.CheckNotNull(data, "data");
+ IMessage message = factory();
+ message.MergeFrom(data, offset, length);
+ return message;
+ }
+
///
/// Parses a message from the given byte string.
///