Commit 0c874a6a authored by Jan Tattermusch's avatar Jan Tattermusch

allow message parsing from an array slice

parent c258fb30
......@@ -53,6 +53,22 @@ namespace Google.Protobuf
input.CheckReadEndOfStreamTag();
}
/// <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>
......
......@@ -70,6 +70,21 @@ namespace Google.Protobuf
return message;
}
/// <summary>
/// Parses a message from a byte array slice.
/// </summary>
/// <param name="data">The byte array containing the message. Must not be null.</param>
/// <param name="offset">The offset of the slice to parse.</param>
/// <param name="length">The length of the slice to parse.</param>
/// <returns>The newly parsed message.</returns>
public IMessage ParseFrom(byte[] data, int offset, int length)
{
ProtoPreconditions.CheckNotNull(data, "data");
IMessage message = factory();
message.MergeFrom(data, offset, length);
return message;
}
/// <summary>
/// Parses a message from the given byte string.
/// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment