protobuf/benchmarks/util/gogo_data_scrubber.cc
Go to the documentation of this file.
1 #include "benchmarks.pb.h"
2 #include "datasets/google_message1/proto2/benchmark_message1_proto2.pb.h"
3 #include "datasets/google_message1/proto3/benchmark_message1_proto3.pb.h"
4 #include "datasets/google_message2/benchmark_message2.pb.h"
5 #include "datasets/google_message3/benchmark_message3.pb.h"
6 #include "datasets/google_message4/benchmark_message4.pb.h"
8 
9 #include <fstream>
10 
12 
14  std::ifstream file(name.c_str());
15  GOOGLE_CHECK(file.is_open()) << "Couldn't find file '"
16  << name
17  << "', please make sure you are running this command from the benchmarks"
18  << " directory.\n";
19  return std::string((std::istreambuf_iterator<char>(file)),
20  std::istreambuf_iterator<char>());
21 }
22 
23 int main(int argc, char *argv[]) {
24  if (argc % 2 == 0 || argc == 1) {
25  std::cerr << "Usage: [input_files] [output_file_names] where " <<
26  "input_files are one to one mapping to output_file_names." <<
27  std::endl;
28  return 1;
29  }
30 
31  for (int i = argc / 2; i > 0; i--) {
32  const std::string &input_file = argv[i];
33  const std::string &output_file = argv[i + argc / 2];
34 
35  std::cerr << "Generating " << input_file
36  << " to " << output_file << std::endl;
37  benchmarks::BenchmarkDataset dataset;
39  std::string dataset_payload = ReadFile(input_file);
40  GOOGLE_CHECK(dataset.ParseFromString(dataset_payload))
41  << "Can' t parse data file " << input_file;
42 
43  if (dataset.message_name() == "benchmarks.proto3.GoogleMessage1") {
44  message = new benchmarks::proto3::GoogleMessage1;
45  } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage1") {
46  message = new benchmarks::proto2::GoogleMessage1;
47  } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage2") {
48  message = new benchmarks::proto2::GoogleMessage2;
49  } else if (dataset.message_name() ==
50  "benchmarks.google_message3.GoogleMessage3") {
51  message = new benchmarks::google_message3::GoogleMessage3;
52  } else if (dataset.message_name() ==
53  "benchmarks.google_message4.GoogleMessage4") {
54  message = new benchmarks::google_message4::GoogleMessage4;
55  } else {
56  std::cerr << "Unknown message type: " << dataset.message_name();
57  exit(1);
58  }
59 
60  for (int i = 0; i < dataset.payload_size(); i++) {
61  message->ParseFromString(dataset.payload(i));
62  GogoDataStripper stripper;
63  stripper.StripMessage(message);
64  dataset.set_payload(i, message->SerializeAsString());
65  }
66 
67  std::ofstream ofs(output_file);
68  ofs << dataset.SerializeAsString();
69  ofs.close();
70  }
71 
72 
73  return 0;
74 }
file
const grpc_generator::File * file
Definition: python_private_generator.h:38
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf::util::DataStripper::StripMessage
void StripMessage(Message *message)
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:17
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
setup.name
name
Definition: setup.py:542
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
google::protobuf::util::GogoDataStripper
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:45
data_proto2_to_proto3_util.h
ReadFile
std::string ReadFile(const std::string &name)
Definition: protobuf/benchmarks/util/gogo_data_scrubber.cc:13
google::protobuf::Message
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:205
GOOGLE_CHECK
#define GOOGLE_CHECK(EXPRESSION)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:153
main
int main(int argc, char *argv[])
Definition: protobuf/benchmarks/util/gogo_data_scrubber.cc:23
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


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