diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-12-07 11:16:47 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-07 11:16:47 -0800 |
commit | c370f88fb18eecc33650ec3ce06f7bdcc11d1596 (patch) | |
tree | 71c4e5dc726b10741304d25906d6de4686d1942a /php/src/Google | |
parent | 1b5b3b28395fd04773589417dd1992098c08c2bb (diff) | |
download | protobuf-c370f88fb18eecc33650ec3ce06f7bdcc11d1596.tar.gz protobuf-c370f88fb18eecc33650ec3ce06f7bdcc11d1596.tar.bz2 protobuf-c370f88fb18eecc33650ec3ce06f7bdcc11d1596.zip |
Recursively clear unknown fields in submessages. (#3982)
* Recursively clear unknown fields in submessages.
* Recursively discard unknown fields in submsg for c extension
* Fix zts build
* Add comment for tests
* Add a TODO to add a util for encoding varint for better readability.
* Add test for oneof message field.
Diffstat (limited to 'php/src/Google')
-rw-r--r-- | php/src/Google/Protobuf/Internal/Message.php | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 26d20575..93e81c01 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -583,6 +583,34 @@ class Message public function discardUnknownFields() { $this->unknown = ""; + foreach ($this->desc->getField() as $field) { + if ($field->getType() != GPBType::MESSAGE) { + continue; + } + if ($field->isMap()) { + $value_field = $field->getMessageType()->getFieldByNumber(2); + if ($value_field->getType() != GPBType::MESSAGE) { + continue; + } + $getter = $field->getGetter(); + $map = $this->$getter(); + foreach ($map as $key => $value) { + $value->discardUnknownFields(); + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + $getter = $field->getGetter(); + $arr = $this->$getter(); + foreach ($arr as $sub) { + $sub->discardUnknownFields(); + } + } else if ($field->getLabel() === GPBLabel::OPTIONAL) { + $getter = $field->getGetter(); + $sub = $this->$getter(); + if (!is_null($sub)) { + $sub->discardUnknownFields(); + } + } + } } /** |