aboutsummaryrefslogtreecommitdiff
path: root/php
diff options
context:
space:
mode:
authorAdam Cozzette <acozzette@google.com>2017-11-30 13:34:51 -0800
committerAdam Cozzette <acozzette@google.com>2017-11-30 13:34:51 -0800
commita27da093393d3dc7301d27fe328284335cb98528 (patch)
treef594ef198ba98a8860b26b3db6cfcc718222ca19 /php
parent6de51caed52d798815954646b230c5aef3e4d2fc (diff)
parent94bb1eed17209cacfdf2571be5a1ae91b3964cff (diff)
downloadprotobuf-a27da093393d3dc7301d27fe328284335cb98528.tar.gz
protobuf-a27da093393d3dc7301d27fe328284335cb98528.tar.bz2
protobuf-a27da093393d3dc7301d27fe328284335cb98528.zip
Merge branch '3.5.x' into 3.5.x-merge
Diffstat (limited to 'php')
-rw-r--r--php/ext/google/protobuf/encode_decode.c9
-rw-r--r--php/ext/google/protobuf/message.c1
-rw-r--r--php/ext/google/protobuf/package.xml22
-rw-r--r--php/ext/google/protobuf/protobuf.h29
-rw-r--r--php/src/Google/Protobuf/Any.php7
-rw-r--r--php/src/Google/Protobuf/Internal/Message.php20
-rw-r--r--php/tests/encode_decode_test.php7
7 files changed, 63 insertions, 32 deletions
diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c
index 7e2b3ae6..ae5a61f5 100644
--- a/php/ext/google/protobuf/encode_decode.c
+++ b/php/ext/google/protobuf/encode_decode.c
@@ -1614,3 +1614,12 @@ PHP_METHOD(Message, mergeFromJsonString) {
stackenv_uninit(&se);
}
}
+
+PHP_METHOD(Message, discardUnknownFields) {
+ MessageHeader* msg = UNBOX(MessageHeader, getThis());
+ stringsink* unknown = DEREF(message_data(msg), 0, stringsink*);
+ if (unknown != NULL) {
+ stringsink_uninit(unknown);
+ DEREF(message_data(msg), 0, stringsink*) = NULL;
+ }
+}
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c
index 3fce2c17..6db010c5 100644
--- a/php/ext/google/protobuf/message.c
+++ b/php/ext/google/protobuf/message.c
@@ -42,6 +42,7 @@ static void hex_to_binary(const char* hex, char** binary, int* binary_len);
static zend_function_entry message_methods[] = {
PHP_ME(Message, clear, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, discardUnknownFields, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, serializeToString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, mergeFromString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, serializeToJsonString, NULL, ZEND_ACC_PUBLIC)
diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml
index 4a473801..53aa4c7f 100644
--- a/php/ext/google/protobuf/package.xml
+++ b/php/ext/google/protobuf/package.xml
@@ -10,11 +10,11 @@
<email>protobuf-opensource@google.com</email>
<active>yes</active>
</lead>
- <date>2017-09-14</date>
+ <date>2017-11-15</date>
<time>11:02:07</time>
<version>
- <release>3.4.1</release>
- <api>3.4.1</api>
+ <release>3.5.0</release>
+ <api>3.5.0</api>
</version>
<stability>
<release>stable</release>
@@ -168,5 +168,21 @@ GA release.
GA release.
</notes>
</release>
+ <release>
+ <version>
+ <release>3.5.0</release>
+ <api>3.5.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2017-11-15</date>
+ <time>11:02:07</time>
+ <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
+ <notes>
+GA release.
+ </notes>
+ </release>
</changelog>
</package>
diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h
index 18343772..bd475144 100644
--- a/php/ext/google/protobuf/protobuf.h
+++ b/php/ext/google/protobuf/protobuf.h
@@ -37,7 +37,7 @@
#include "upb.h"
#define PHP_PROTOBUF_EXTNAME "protobuf"
-#define PHP_PROTOBUF_VERSION "3.4.1"
+#define PHP_PROTOBUF_VERSION "3.5.0"
#define MAX_LENGTH_OF_INT64 20
#define SIZEOF_INT64 8
@@ -608,48 +608,36 @@ typedef struct Api Api;
typedef struct BoolValue BoolValue;
typedef struct BytesValue BytesValue;
typedef struct Descriptor Descriptor;
-typedef struct Descriptor Descriptor;
typedef struct DescriptorPool DescriptorPool;
typedef struct DoubleValue DoubleValue;
typedef struct Duration Duration;
-typedef struct Enum Enum;
typedef struct EnumDescriptor EnumDescriptor;
-typedef struct EnumDescriptor EnumDescriptor;
-typedef struct EnumValue EnumValue;
-typedef struct EnumValueDescriptor EnumValueDescriptor;
+typedef struct Enum Enum;
typedef struct EnumValueDescriptor EnumValueDescriptor;
-typedef struct Field Field;
-typedef struct FieldDescriptor FieldDescriptor;
-typedef struct FieldDescriptor FieldDescriptor;
-typedef struct FieldMask FieldMask;
+typedef struct EnumValue EnumValue;
typedef struct Field_Cardinality Field_Cardinality;
+typedef struct FieldDescriptor FieldDescriptor;
+typedef struct Field Field;
typedef struct Field_Kind Field_Kind;
+typedef struct FieldMask FieldMask;
typedef struct FloatValue FloatValue;
typedef struct GPBEmpty GPBEmpty;
typedef struct Int32Value Int32Value;
typedef struct Int64Value Int64Value;
typedef struct InternalDescriptorPool InternalDescriptorPool;
typedef struct ListValue ListValue;
-typedef struct Map Map;
-typedef struct Map Map;
-typedef struct MapIter MapIter;
typedef struct MapIter MapIter;
+typedef struct Map Map;
typedef struct MessageField MessageField;
-typedef struct MessageField MessageField;
-typedef struct MessageHeader MessageHeader;
typedef struct MessageHeader MessageHeader;
typedef struct MessageLayout MessageLayout;
-typedef struct MessageLayout MessageLayout;
typedef struct Method Method;
typedef struct Mixin Mixin;
typedef struct NullValue NullValue;
typedef struct Oneof Oneof;
-typedef struct Oneof Oneof;
typedef struct Option Option;
-typedef struct RepeatedField RepeatedField;
-typedef struct RepeatedField RepeatedField;
-typedef struct RepeatedFieldIter RepeatedFieldIter;
typedef struct RepeatedFieldIter RepeatedFieldIter;
+typedef struct RepeatedField RepeatedField;
typedef struct SourceContext SourceContext;
typedef struct StringValue StringValue;
typedef struct Struct Struct;
@@ -969,6 +957,7 @@ PHP_METHOD(Message, serializeToString);
PHP_METHOD(Message, mergeFromString);
PHP_METHOD(Message, serializeToJsonString);
PHP_METHOD(Message, mergeFromJsonString);
+PHP_METHOD(Message, discardUnknownFields);
// -----------------------------------------------------------------------------
// Type check / conversion.
diff --git a/php/src/Google/Protobuf/Any.php b/php/src/Google/Protobuf/Any.php
index 91ba4bd5..f027b05d 100644
--- a/php/src/Google/Protobuf/Any.php
+++ b/php/src/Google/Protobuf/Any.php
@@ -4,7 +4,6 @@
namespace Google\Protobuf;
-use Google\Protobuf\Internal\DescriptorPool;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBUtil;
use Google\Protobuf\Internal\Message;
@@ -217,7 +216,7 @@ class Any extends \Google\Protobuf\Internal\Message
substr($this->type_url, $url_prifix_len);
// Create message according to fully qualified name.
- $pool = DescriptorPool::getGeneratedPool();
+ $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByProtoName( ".".$fully_qualifed_name);
if (is_null($desc)) {
throw new \Exception("Class ".$fully_qualifed_name
@@ -248,7 +247,7 @@ class Any extends \Google\Protobuf\Internal\Message
$this->value = $msg->serializeToString();
// Set type url.
- $pool = DescriptorPool::getGeneratedPool();
+ $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName(get_class($msg));
$fully_qualifed_name = $desc->getFullName();
$this->type_url = GPBUtil::TYPE_URL_PREFIX.substr(
@@ -262,7 +261,7 @@ class Any extends \Google\Protobuf\Internal\Message
*/
public function is($klass)
{
- $pool = DescriptorPool::getGeneratedPool();
+ $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName($klass);
$fully_qualifed_name = $desc->getFullName();
$type_url = GPBUtil::TYPE_URL_PREFIX.substr(
diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php
index 9785be30..26d20575 100644
--- a/php/src/Google/Protobuf/Internal/Message.php
+++ b/php/src/Google/Protobuf/Internal/Message.php
@@ -577,6 +577,15 @@ class Message
}
/**
+ * Clear all unknown fields previously parsed.
+ * @return null.
+ */
+ public function discardUnknownFields()
+ {
+ $this->unknown = "";
+ }
+
+ /**
* Merges the contents of the specified message into current message.
*
* This method merges the contents of the specified message into the
@@ -833,6 +842,8 @@ class Message
}
return $value;
case GPBType::INT32:
+ case GPBType::SINT32:
+ case GPBType::SFIXED32:
if (is_null($value)) {
return $this->defaultValue($field);
}
@@ -850,6 +861,7 @@ class Message
}
return $value;
case GPBType::UINT32:
+ case GPBType::FIXED32:
if (is_null($value)) {
return $this->defaultValue($field);
}
@@ -863,6 +875,8 @@ class Message
}
return $value;
case GPBType::INT64:
+ case GPBType::SINT64:
+ case GPBType::SFIXED64:
if (is_null($value)) {
return $this->defaultValue($field);
}
@@ -880,6 +894,7 @@ class Message
}
return $value;
case GPBType::UINT64:
+ case GPBType::FIXED64:
if (is_null($value)) {
return $this->defaultValue($field);
}
@@ -895,11 +910,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;
}
diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php
index 4dca922b..4512c871 100644
--- a/php/tests/encode_decode_test.php
+++ b/php/tests/encode_decode_test.php
@@ -466,6 +466,13 @@ class EncodeDecodeTest extends TestBase
$m->mergeFromString($from);
$to = $m->serializeToString();
$this->assertSame(bin2hex($from), bin2hex($to));
+
+ $m = new TestMessage();
+ $from = hex2bin('F80601');
+ $m->mergeFromString($from);
+ $m->discardUnknownFields();
+ $to = $m->serializeToString();
+ $this->assertSame("", bin2hex($to));
}
public function testJsonEncode()