/** * @ignore */ private function fieldByteSize($field) { $size = 0; if ($field->isMap()) { $getter = $field->getGetter(); $values = $this->{$getter}(); $count = count($values); if ($count !== 0) { $size += $count * GPBWire::tagSize($field); $message_type = $field->getMessageType(); $key_field = $message_type->getFieldByNumber(1); $value_field = $message_type->getFieldByNumber(2); foreach ($values as $key => $value) { $data_size = 0; $data_size += $this->fieldDataOnlyByteSize($key_field, $key); $data_size += $this->fieldDataOnlyByteSize($value_field, $value); $data_size += GPBWire::tagSize($key_field); $data_size += GPBWire::tagSize($value_field); $size += GPBWire::varint32Size($data_size) + $data_size; } } } elseif ($field->isRepeated()) { $getter = $field->getGetter(); $values = $this->{$getter}(); $count = count($values); if ($count !== 0) { if ($field->getPacked()) { $data_size = 0; foreach ($values as $value) { $data_size += $this->fieldDataOnlyByteSize($field, $value); } $size += GPBWire::tagSize($field); $size += GPBWire::varint32Size($data_size); $size += $data_size; } else { $size += $count * GPBWire::tagSize($field); foreach ($values as $value) { $size += $this->fieldDataOnlyByteSize($field, $value); } } } } elseif ($this->existField($field)) { $size += GPBWire::tagSize($field); $getter = $field->getGetter(); $value = $this->{$getter}(); $size += $this->fieldDataOnlyByteSize($field, $value); } return $size; }