function Message::mergeFromArrayJsonImpl
1 call to Message::mergeFromArrayJsonImpl()
- Message::mergeFromJsonArray in vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ Message.php
File
-
vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ Message.php, line 1222
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
private function mergeFromArrayJsonImpl($array, $ignore_unknown) {
foreach ($array as $key => $value) {
$field = $this->desc
->getFieldByJsonName($key);
if (is_null($field)) {
$field = $this->desc
->getFieldByName($key);
if (is_null($field)) {
if ($ignore_unknown) {
continue;
}
else {
throw new GPBDecodeException($key . ' is unknown.');
}
}
}
if ($field->isMap()) {
if (is_null($value)) {
continue;
}
$key_field = $field->getMessageType()
->getFieldByNumber(1);
$value_field = $field->getMessageType()
->getFieldByNumber(2);
foreach ($value as $tmp_key => $tmp_value) {
if (is_null($tmp_value)) {
throw new \Exception("Map value field element cannot be null.");
}
$proto_key = $this->convertJsonValueToProtoValue($tmp_key, $key_field, $ignore_unknown, true);
$proto_value = $this->convertJsonValueToProtoValue($tmp_value, $value_field, $ignore_unknown);
self::kvUpdateHelper($field, $proto_key, $proto_value);
}
}
else {
if ($field->isRepeated()) {
if (is_null($value)) {
continue;
}
foreach ($value as $tmp) {
if (is_null($tmp)) {
throw new \Exception("Repeated field elements cannot be null.");
}
$proto_value = $this->convertJsonValueToProtoValue($tmp, $field, $ignore_unknown);
self::appendHelper($field, $proto_value);
}
}
else {
$setter = $field->getSetter();
$proto_value = $this->convertJsonValueToProtoValue($value, $field, $ignore_unknown);
if ($field->getType() === GPBType::MESSAGE) {
if (is_null($proto_value)) {
continue;
}
$getter = $field->getGetter();
$submsg = $this->{$getter}();
if (!is_null($submsg)) {
$submsg->mergeFrom($proto_value);
continue;
}
}
$this->{$setter}($proto_value);
}
}
}
}