34 #include <google/protobuf/reflection_ops.h>
39 #include <google/protobuf/stubs/logging.h>
40 #include <google/protobuf/stubs/common.h>
41 #include <google/protobuf/descriptor.pb.h>
42 #include <google/protobuf/descriptor.h>
43 #include <google/protobuf/map_field.h>
44 #include <google/protobuf/map_field_inl.h>
45 #include <google/protobuf/unknown_field_set.h>
47 #include <google/protobuf/port_def.inc>
57 const std::string& mtype = d ? d->name() :
"unknown";
59 GOOGLE_LOG(
FATAL) <<
"Message does not support reflection (type " << mtype <<
").";
75 <<
"Tried to merge messages of different types "
76 <<
"(merge " <<
descriptor->full_name() <<
" to "
77 <<
to->GetDescriptor()->full_name() <<
")";
81 bool is_from_generated = (from_reflection->GetMessageFactory() ==
83 bool is_to_generated = (to_reflection->GetMessageFactory() ==
86 std::vector<const FieldDescriptor*>
fields;
87 from_reflection->ListFieldsOmitStripped(
from, &
fields);
89 if (
field->is_repeated()) {
95 if (is_from_generated == is_to_generated &&
field->is_map()) {
96 const MapFieldBase* from_field =
98 MapFieldBase* to_field = to_reflection->MutableMapData(
to,
field);
99 if (to_field->IsMapValid() && from_field->IsMapValid()) {
100 to_field->MergeFrom(*from_field);
105 for (
int j = 0;
j <
count;
j++) {
106 switch (
field->cpp_type()) {
107 #define HANDLE_TYPE(CPPTYPE, METHOD) \
108 case FieldDescriptor::CPPTYPE_##CPPTYPE: \
109 to_reflection->Add##METHOD( \
110 to, field, from_reflection->GetRepeated##METHOD(from, field, j)); \
126 from_reflection->GetRepeatedMessage(
from,
field, j);
127 if (from_reflection == to_reflection) {
130 from_child.GetReflection()->GetMessageFactory())
131 ->MergeFrom(from_child);
133 to_reflection->AddMessage(
to,
field)->MergeFrom(from_child);
139 switch (
field->cpp_type()) {
140 #define HANDLE_TYPE(CPPTYPE, METHOD) \
141 case FieldDescriptor::CPPTYPE_##CPPTYPE: \
142 to_reflection->Set##METHOD(to, field, \
143 from_reflection->Get##METHOD(from, field)); \
159 if (from_reflection == to_reflection) {
162 to,
field, from_child.GetReflection()->GetMessageFactory())
163 ->MergeFrom(from_child);
165 to_reflection->MutableMessage(
to,
field)->MergeFrom(from_child);
172 to_reflection->MutableUnknownFields(
to)->MergeFrom(
173 from_reflection->GetUnknownFields(
from));
179 std::vector<const FieldDescriptor*>
fields;
185 reflection->MutableUnknownFields(
message)->Clear();
189 bool check_descendants) {
192 if (
const int field_count =
descriptor->field_count()) {
206 if (check_descendants) {
210 if (PROTOBUF_PREDICT_FALSE(
message_type->options().map_entry())) {
219 it != end_map; ++
it) {
220 if (!
it.GetValueRef().GetMessageValue().IsInitialized()) {
226 }
else if (
field->is_repeated()) {
228 for (
int j = 0; j <
size; j++) {
256 const int field_count =
descriptor->field_count();
257 for (
int i = 0;
i < field_count;
i++) {
267 std::vector<const FieldDescriptor*>
fields;
274 if (
field->is_map()) {
277 const MapFieldBase* map_field =
279 if (map_field->IsMapValid()) {
282 for (map_field->MapBegin(&
iter), map_field->MapEnd(&
end);
284 if (!
iter.GetValueRef().GetMessageValue().IsInitialized()) {
295 if (
field->is_repeated()) {
298 for (
int j = 0;
j <
size;
j++) {
327 std::vector<const FieldDescriptor*>
fields;
336 const MapFieldBase* map_field =
338 if (map_field->IsMapValid()) {
341 for (map_field->MapBegin(&
iter), map_field->MapEnd(&
end);
iter !=
end;
343 iter.MutableValueRef()->MutableMessageValue()->DiscardUnknownFields();
347 }
else if (
field->is_repeated()) {
349 for (
int j = 0;
j <
size;
j++) {
363 if (
field->is_extension()) {
381 std::vector<std::string>*
errors) {
387 const int field_count =
descriptor->field_count();
388 for (
int i = 0;
i < field_count;
i++) {
398 std::vector<const FieldDescriptor*>
fields;
403 if (
field->is_repeated()) {
406 for (
int j = 0;
j <
size;
j++) {
422 #ifndef PROTOBUF_FORCE_COPY_IN_SWAP
423 GOOGLE_DCHECK(Arena::InternalHelper<Message>::GetOwningArena(lhs) !=
424 Arena::InternalHelper<Message>::GetOwningArena(rhs));
425 GOOGLE_DCHECK(Arena::InternalHelper<Message>::GetOwningArena(lhs) !=
nullptr ||
426 Arena::InternalHelper<Message>::GetOwningArena(rhs) !=
nullptr);
427 #endif // !PROTOBUF_FORCE_COPY_IN_SWAP
429 Arena*
arena = Arena::InternalHelper<Message>::GetOwningArena(rhs);
430 if (
arena ==
nullptr) {
432 arena = Arena::InternalHelper<Message>::GetOwningArena(rhs);
438 tmp->CheckTypeAndMergeFrom(*lhs);
441 #ifdef PROTOBUF_FORCE_COPY_IN_SWAP
445 #else // PROTOBUF_FORCE_COPY_IN_SWAP
447 #endif // !PROTOBUF_FORCE_COPY_IN_SWAP
454 #include <google/protobuf/port_undef.inc>