aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2017-11-13 10:48:40 -0800
committerGravatar Jisi Liu <jisi.liu@gmail.com>2017-11-13 10:48:40 -0800
commit4041600aa17563aead04ad2abf479b5a6834b4c7 (patch)
tree6dba45903071946a759d66b960ac71e5dd61ae2a
parent4493595f8c77e9d094351987111cbf4aa2246f37 (diff)
parent2761122b810fe8861004ae785cc3ab39f384d342 (diff)
Merge branch '3.5.x' of github.com:google/protobuf into 3.5.x
-rw-r--r--CHANGES.txt1
-rw-r--r--conformance/conformance_test.cc16
-rw-r--r--csharp/src/Google.Protobuf/MessageExtensions.cs16
-rw-r--r--csharp/src/Google.Protobuf/MessageParser.cs32
-rw-r--r--php/src/Google/Protobuf/Internal/Message.php11
5 files changed, 67 insertions, 9 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index fe2de89d..ea3252bb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -62,6 +62,7 @@
C#
* Added unknown field support in JsonParser.
* Fixed oneof message field merge.
+ * Simplify parsing messages from array slices.
Ruby
* Unknown fields are now preserved by default.
diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc
index c54d4ccd..98c2eae4 100644
--- a/conformance/conformance_test.cc
+++ b/conformance/conformance_test.cc
@@ -1842,6 +1842,14 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
"optionalInt64": null,
"optionalUint32": null,
"optionalUint64": null,
+ "optionalSint32": null,
+ "optionalSint64": null,
+ "optionalFixed32": null,
+ "optionalFixed64": null,
+ "optionalSfixed32": null,
+ "optionalSfixed64": null,
+ "optionalFloat": null,
+ "optionalDouble": null,
"optionalBool": null,
"optionalString": null,
"optionalBytes": null,
@@ -1851,6 +1859,14 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
"repeatedInt64": null,
"repeatedUint32": null,
"repeatedUint64": null,
+ "repeatedSint32": null,
+ "repeatedSint64": null,
+ "repeatedFixed32": null,
+ "repeatedFixed64": null,
+ "repeatedSfixed32": null,
+ "repeatedSfixed64": null,
+ "repeatedFloat": null,
+ "repeatedDouble": null,
"repeatedBool": null,
"repeatedString": null,
"repeatedBytes": null,
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>
diff --git a/csharp/src/Google.Protobuf/MessageParser.cs b/csharp/src/Google.Protobuf/MessageParser.cs
index 8889638b..66d44135 100644
--- a/csharp/src/Google.Protobuf/MessageParser.cs
+++ b/csharp/src/Google.Protobuf/MessageParser.cs
@@ -64,20 +64,32 @@ namespace Google.Protobuf
/// <returns>The newly parsed message.</returns>
public IMessage ParseFrom(byte[] data)
{
- ProtoPreconditions.CheckNotNull(data, "data");
IMessage message = factory();
message.MergeFrom(data);
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)
+ {
+ IMessage message = factory();
+ message.MergeFrom(data, offset, length);
+ return message;
+ }
+
+ /// <summary>
/// Parses a message from the given byte string.
/// </summary>
/// <param name="data">The data to parse.</param>
/// <returns>The parsed message.</returns>
public IMessage ParseFrom(ByteString data)
{
- ProtoPreconditions.CheckNotNull(data, "data");
IMessage message = factory();
message.MergeFrom(data);
return message;
@@ -191,20 +203,32 @@ namespace Google.Protobuf
/// <returns>The newly parsed message.</returns>
public new T ParseFrom(byte[] data)
{
- ProtoPreconditions.CheckNotNull(data, "data");
T message = factory();
message.MergeFrom(data);
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 new T ParseFrom(byte[] data, int offset, int length)
+ {
+ T message = factory();
+ message.MergeFrom(data, offset, length);
+ return message;
+ }
+
+ /// <summary>
/// Parses a message from the given byte string.
/// </summary>
/// <param name="data">The data to parse.</param>
/// <returns>The parsed message.</returns>
public new T ParseFrom(ByteString data)
{
- ProtoPreconditions.CheckNotNull(data, "data");
T message = factory();
message.MergeFrom(data);
return message;
diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php
index 9785be30..a7a4f272 100644
--- a/php/src/Google/Protobuf/Internal/Message.php
+++ b/php/src/Google/Protobuf/Internal/Message.php
@@ -833,6 +833,8 @@ class Message
}
return $value;
case GPBType::INT32:
+ case GPBType::SINT32:
+ case GPBType::SFIXED32:
if (is_null($value)) {
return $this->defaultValue($field);
}
@@ -850,6 +852,7 @@ class Message
}
return $value;
case GPBType::UINT32:
+ case GPBType::FIXED32:
if (is_null($value)) {
return $this->defaultValue($field);
}
@@ -863,6 +866,8 @@ class Message
}
return $value;
case GPBType::INT64:
+ case GPBType::SINT64:
+ case GPBType::SFIXED64:
if (is_null($value)) {
return $this->defaultValue($field);
}
@@ -880,6 +885,7 @@ class Message
}
return $value;
case GPBType::UINT64:
+ case GPBType::FIXED64:
if (is_null($value)) {
return $this->defaultValue($field);
}
@@ -895,11 +901,6 @@ class Message
$value = bcsub($value, "18446744073709551616");
}
return $value;
- case GPBType::FIXED64:
- if (is_null($value)) {
- return $this->defaultValue($field);
- }
- return $value;
default:
return $value;
}