diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2017-11-09 14:23:14 +0100 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2017-11-10 09:00:52 +0100 |
commit | 435f61102bf23b9c9be2592d27b8935a8717e610 (patch) | |
tree | abef16d8e433a61b525dde7f5693afff312adcbc /csharp/src/Google.Protobuf/MessageExtensions.cs | |
parent | 5eb717c3006ad7da9aa6e49d40328a3963ad22a3 (diff) | |
download | protobuf-435f61102bf23b9c9be2592d27b8935a8717e610.tar.gz protobuf-435f61102bf23b9c9be2592d27b8935a8717e610.tar.bz2 protobuf-435f61102bf23b9c9be2592d27b8935a8717e610.zip |
allow message parsing from an array slice
Diffstat (limited to 'csharp/src/Google.Protobuf/MessageExtensions.cs')
-rw-r--r-- | csharp/src/Google.Protobuf/MessageExtensions.cs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf/MessageExtensions.cs b/csharp/src/Google.Protobuf/MessageExtensions.cs index 047156c3..9dbc49d6 100644 --- a/csharp/src/Google.Protobuf/MessageExtensions.cs +++ b/csharp/src/Google.Protobuf/MessageExtensions.cs @@ -54,6 +54,22 @@ namespace Google.Protobuf } /// <summary> + /// Merges data from the given byte array slice into an existing message. + /// </summary> + /// <param name="message">The message to merge the data into.</param> + /// <param name="data">The data containing the slice to merge, which must be protobuf-encoded binary data.</param> + /// <param name="offset">The offset of the slice to merge.</param> + /// <param name="length">The length of the slice to merge.</param> + 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(); + } + + /// <summary> /// Merges data from the given byte string into an existing message. /// </summary> /// <param name="message">The message to merge the data into.</param> |