diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2017-11-09 14:23:14 +0100 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2017-11-09 14:23:14 +0100 |
commit | 0c874a6a1901d5c4ebb9d09f218eb9e348b7279c (patch) | |
tree | 7c3983d6a13d9a7de6d209ce3a71edafeb120b31 /csharp/src/Google.Protobuf/MessageExtensions.cs | |
parent | c258fb303a804241cb2678dc732ed870a0ee97c8 (diff) | |
download | protobuf-0c874a6a1901d5c4ebb9d09f218eb9e348b7279c.tar.gz protobuf-0c874a6a1901d5c4ebb9d09f218eb9e348b7279c.tar.bz2 protobuf-0c874a6a1901d5c4ebb9d09f218eb9e348b7279c.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> |