function Message::discardUnknownFields
Clear all unknown fields previously parsed.
Return value
null
File
-
vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ Message.php, line 637
Class
- Message
- Parent class of all proto messages. Users should not instantiate this class or extend this class or its child classes by their own. See the comment of specific functions for more details.
Namespace
Google\Protobuf\InternalCode
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();
}
}
}
}
}
}