function GPBJsonWire::serializeFieldValueToStream
1 call to GPBJsonWire::serializeFieldValueToStream()
- GPBJsonWire::serializeFieldToStream in vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ GPBJsonWire.php
File
-
vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ GPBJsonWire.php, line 33
Class
Namespace
Google\Protobuf\InternalCode
public static function serializeFieldValueToStream($values, $field, &$output, $is_well_known = false) {
if ($field->isMap()) {
$output->writeRaw("{", 1);
$first = true;
$map_entry = $field->getMessageType();
$key_field = $map_entry->getFieldByNumber(1);
$value_field = $map_entry->getFieldByNumber(2);
switch ($key_field->getType()) {
case GPBType::STRING:
case GPBType::SFIXED64:
case GPBType::INT64:
case GPBType::SINT64:
case GPBType::FIXED64:
case GPBType::UINT64:
$additional_quote = false;
break;
default:
$additional_quote = true;
}
foreach ($values as $key => $value) {
if ($first) {
$first = false;
}
else {
$output->writeRaw(",", 1);
}
if ($additional_quote) {
$output->writeRaw("\"", 1);
}
if (!static::serializeSingularFieldValueToStream($key, $key_field, $output, $is_well_known)) {
return false;
}
if ($additional_quote) {
$output->writeRaw("\"", 1);
}
$output->writeRaw(":", 1);
if (!static::serializeSingularFieldValueToStream($value, $value_field, $output, $is_well_known)) {
return false;
}
}
$output->writeRaw("}", 1);
return true;
}
elseif ($field->isRepeated()) {
$output->writeRaw("[", 1);
$first = true;
foreach ($values as $value) {
if ($first) {
$first = false;
}
else {
$output->writeRaw(",", 1);
}
if (!static::serializeSingularFieldValueToStream($value, $field, $output, $is_well_known)) {
return false;
}
}
$output->writeRaw("]", 1);
return true;
}
else {
return static::serializeSingularFieldValueToStream($values, $field, $output, $is_well_known);
}
}