data_proto2_to_proto3_util.h
Go to the documentation of this file.
1 #ifndef PROTOBUF_BENCHMARKS_UTIL_DATA_PROTO2_TO_PROTO3_UTIL_H_
2 #define PROTOBUF_BENCHMARKS_UTIL_DATA_PROTO2_TO_PROTO3_UTIL_H_
3 
6 
10 
11 namespace google {
12 namespace protobuf {
13 namespace util {
14 
15 class DataStripper {
16  public:
18  std::vector<const FieldDescriptor*> set_fields;
19  const Reflection* reflection = message->GetReflection();
20  reflection->ListFields(*message, &set_fields);
21 
22  for (size_t i = 0; i < set_fields.size(); i++) {
23  const FieldDescriptor* field = set_fields[i];
24  if (ShouldBeClear(field)) {
25  reflection->ClearField(message, field);
26  continue;
27  }
28  if (field->type() == FieldDescriptor::TYPE_MESSAGE) {
29  if (field->is_repeated()) {
30  for (int j = 0; j < reflection->FieldSize(*message, field); j++) {
32  }
33  } else {
35  }
36  }
37  }
38 
39  reflection->MutableUnknownFields(message)->Clear();
40  }
41  private:
42  virtual bool ShouldBeClear(const FieldDescriptor *field) = 0;
43 };
44 
46  private:
47  virtual bool ShouldBeClear(const FieldDescriptor *field) {
48  return field->type() == FieldDescriptor::TYPE_GROUP;
49  }
50 };
51 
53  private:
54  virtual bool ShouldBeClear(const FieldDescriptor *field) {
55  return field->type() == FieldDescriptor::TYPE_GROUP ||
56  field->is_extension();
57  }
58 };
59 
60 } // namespace util
61 } // namespace protobuf
62 } // namespace google
63 
64 #endif // PROTOBUF_BENCHMARKS_UTIL_DATA_PROTO2_TO_PROTO3_UTIL_H_
google::protobuf::util::DataStripper
Definition: data_proto2_to_proto3_util.h:15
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
google::protobuf::util::GogoDataStripper::ShouldBeClear
virtual bool ShouldBeClear(const FieldDescriptor *field)
Definition: data_proto2_to_proto3_util.h:47
google::protobuf::util::DataStripper::StripMessage
void StripMessage(Message *message)
Definition: data_proto2_to_proto3_util.h:17
google::protobuf::Reflection
Definition: src/google/protobuf/message.h:400
google::protobuf::UnknownFieldSet::Clear
void Clear()
Definition: unknown_field_set.h:299
google::protobuf::util::GogoDataStripper
Definition: data_proto2_to_proto3_util.h:45
google::protobuf::Reflection::MutableUnknownFields
UnknownFieldSet * MutableUnknownFields(Message *message) const
Definition: generated_message_reflection.cc:237
message.h
google::protobuf::Reflection::ClearField
void ClearField(Message *message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:789
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
google::protobuf::Reflection::FieldSize
int FieldSize(const Message &message, const FieldDescriptor *field) const
Definition: generated_message_reflection.cc:744
google::protobuf::Reflection::MutableMessage
Message * MutableMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: generated_message_reflection.cc:1462
i
int i
Definition: gmock-matchers_test.cc:764
google::protobuf::FieldDescriptor::TYPE_MESSAGE
@ TYPE_MESSAGE
Definition: src/google/protobuf/descriptor.h:536
google::protobuf::Message
Definition: src/google/protobuf/message.h:205
google::protobuf::util::Proto3DataStripper
Definition: data_proto2_to_proto3_util.h:52
google::protobuf::Reflection::MutableRepeatedMessage
Message * MutableRepeatedMessage(Message *message, const FieldDescriptor *field, int index) const
Definition: generated_message_reflection.cc:1617
descriptor.h
google::protobuf::FieldDescriptor::TYPE_GROUP
@ TYPE_GROUP
Definition: src/google/protobuf/descriptor.h:535
FieldDescriptor
struct FieldDescriptor FieldDescriptor
Definition: php/ext/google/protobuf/protobuf.h:637
google::protobuf::util::Proto3DataStripper::ShouldBeClear
virtual bool ShouldBeClear(const FieldDescriptor *field)
Definition: data_proto2_to_proto3_util.h:54
google::protobuf::util::DataStripper::ShouldBeClear
virtual bool ShouldBeClear(const FieldDescriptor *field)=0
google::protobuf::Reflection::ListFields
void ListFields(const Message &message, std::vector< const FieldDescriptor * > *output) const
Definition: generated_message_reflection.cc:1029
google
Definition: data_proto2_to_proto3_util.h:11
message
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glcorearb.h:2695


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:49