• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <iostream>
2 #include <string>
3 
4 #ifdef _WIN32
5 #include <fcntl.h>
6 #else
7 #include <unistd.h>
8 #endif
9 
10 #include "google/protobuf/descriptor.pb.h"
11 #include "absl/flags/flag.h"
12 #include "absl/flags/parse.h"
13 #include "absl/log/absl_log.h"
14 #include "absl/strings/escaping.h"
15 
16 #if defined(_WIN32)
17 #include "google/protobuf/io/io_win32.h"
18 
19 // DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
20 // them like we do below.
21 using google::protobuf::io::win32::setmode;
22 #endif
23 
24 ABSL_FLAG(std::string, encoding, "octal",
25           "The encoding to use for the output.");
26 
main(int argc,char * argv[])27 int main(int argc, char *argv[]) {
28   absl::ParseCommandLine(argc, argv);
29 #ifdef _WIN32
30   setmode(STDIN_FILENO, _O_BINARY);
31   setmode(STDOUT_FILENO, _O_BINARY);
32 #endif
33   google::protobuf::FeatureSetDefaults defaults;
34   if (!defaults.ParseFromFileDescriptor(STDIN_FILENO)) {
35     std::cerr << argv[0] << ": unable to parse edition defaults." << std::endl;
36     return 1;
37   }
38   std::string output;
39   defaults.SerializeToString(&output);
40   std::string encoding = absl::GetFlag(FLAGS_encoding);
41   if (encoding == "base64") {
42     std::cout << absl::Base64Escape(output);
43   } else if (encoding == "octal") {
44     std::cout << absl::CEscape(output);
45   } else {
46     ABSL_LOG(FATAL) << "Unknown encoding: " << encoding;
47   }
48   return 0;
49 }
50