function Message::mergeFromJsonArray
1 call to Message::mergeFromJsonArray()
- Message::parseFromJsonStream in vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ Message.php - @ignore
File
-
vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ Message.php, line 1126
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
protected function mergeFromJsonArray($array, $ignore_unknown) {
if (is_a($this, "Google\\Protobuf\\Any")) {
$this->clear();
$this->setTypeUrl($array["@type"]);
$msg = $this->unpack();
if (GPBUtil::hasSpecialJsonMapping($msg)) {
$msg->mergeFromJsonArray($array["value"], $ignore_unknown);
}
else {
unset($array["@type"]);
$msg->mergeFromJsonArray($array, $ignore_unknown);
}
$this->setValue($msg->serializeToString());
return;
}
if (is_a($this, "Google\\Protobuf\\DoubleValue") || is_a($this, "Google\\Protobuf\\FloatValue") || is_a($this, "Google\\Protobuf\\Int64Value") || is_a($this, "Google\\Protobuf\\UInt64Value") || is_a($this, "Google\\Protobuf\\Int32Value") || is_a($this, "Google\\Protobuf\\UInt32Value") || is_a($this, "Google\\Protobuf\\BoolValue") || is_a($this, "Google\\Protobuf\\StringValue")) {
$this->setValue($array);
return;
}
if (is_a($this, "Google\\Protobuf\\BytesValue")) {
$this->setValue(base64_decode($array));
return;
}
if (is_a($this, "Google\\Protobuf\\Duration")) {
$this->mergeFrom(GPBUtil::parseDuration($array));
return;
}
if (is_a($this, "Google\\Protobuf\\FieldMask")) {
$this->mergeFrom(GPBUtil::parseFieldMask($array));
return;
}
if (is_a($this, "Google\\Protobuf\\Timestamp")) {
$this->mergeFrom(GPBUtil::parseTimestamp($array));
return;
}
if (is_a($this, "Google\\Protobuf\\Struct")) {
$fields = $this->getFields();
foreach ($array as $key => $value) {
$v = new Value();
$v->mergeFromJsonArray($value, $ignore_unknown);
$fields[$key] = $v;
}
return;
}
if (is_a($this, "Google\\Protobuf\\Value")) {
if (is_bool($array)) {
$this->setBoolValue($array);
}
elseif (is_string($array)) {
$this->setStringValue($array);
}
elseif (is_null($array)) {
$this->setNullValue(0);
}
elseif (is_double($array) || is_integer($array)) {
$this->setNumberValue($array);
}
elseif (is_array($array)) {
if (array_values($array) !== $array) {
// Associative array
$struct_value = $this->getStructValue();
if (is_null($struct_value)) {
$struct_value = new Struct();
$this->setStructValue($struct_value);
}
foreach ($array as $key => $v) {
$value = new Value();
$value->mergeFromJsonArray($v, $ignore_unknown);
$values = $struct_value->getFields();
$values[$key] = $value;
}
}
else {
// Array
$list_value = $this->getListValue();
if (is_null($list_value)) {
$list_value = new ListValue();
$this->setListValue($list_value);
}
foreach ($array as $v) {
$value = new Value();
$value->mergeFromJsonArray($v, $ignore_unknown);
$values = $list_value->getValues();
$values[] = $value;
}
}
}
else {
throw new GPBDecodeException("Invalid type for Value.");
}
return;
}
$this->mergeFromArrayJsonImpl($array, $ignore_unknown);
}