protobuf/benchmarks/util/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 
4 #include "google/protobuf/message.h"
5 #include "google/protobuf/descriptor.h"
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 
45 class GogoDataStripper : public DataStripper {
46  private:
47  virtual bool ShouldBeClear(const FieldDescriptor *field) {
48  return field->type() == FieldDescriptor::TYPE_GROUP;
49  }
50 };
51 
52 class Proto3DataStripper : public DataStripper {
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::FieldDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:515
google::protobuf::util::GogoDataStripper::ShouldBeClear
virtual bool ShouldBeClear(const FieldDescriptor *field)
Definition: protobuf/benchmarks/util/data_proto2_to_proto3_util.h:47
grpc::protobuf::Message
GRPC_CUSTOM_MESSAGE Message
Definition: include/grpcpp/impl/codegen/config_protobuf.h:78
google::protobuf::util::DataStripper::StripMessage
void StripMessage(Message *message)
Definition: protobuf/benchmarks/util/data_proto2_to_proto3_util.h:17
grpc::protobuf::FieldDescriptor
GRPC_CUSTOM_FIELDDESCRIPTOR FieldDescriptor
Definition: include/grpcpp/impl/codegen/config_protobuf.h:84
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf::FieldDescriptor::TYPE_GROUP
@ TYPE_GROUP
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:535
google::protobuf::Reflection
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:397
google::protobuf::UnknownFieldSet::Clear
void Clear()
Definition: bloaty/third_party/protobuf/src/google/protobuf/unknown_field_set.h:296
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
google::protobuf::Reflection::MutableUnknownFields
UnknownFieldSet * MutableUnknownFields(Message *message) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:237
google::protobuf::Reflection::ClearField
void ClearField(Message *message, const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:789
google::protobuf::Reflection::FieldSize
int FieldSize(const Message &message, const FieldDescriptor *field) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:744
google::protobuf::Reflection::MutableMessage
Message * MutableMessage(Message *message, const FieldDescriptor *field, MessageFactory *factory=nullptr) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1461
google::protobuf::Message
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:205
field
const FieldDescriptor * field
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
google::protobuf::Reflection::MutableRepeatedMessage
Message * MutableRepeatedMessage(Message *message, const FieldDescriptor *field, int index) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1616
google::protobuf::FieldDescriptor::TYPE_MESSAGE
@ TYPE_MESSAGE
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:536
google::protobuf::util::Proto3DataStripper::ShouldBeClear
virtual bool ShouldBeClear(const FieldDescriptor *field)
Definition: protobuf/benchmarks/util/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: bloaty/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc:1029
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:08