Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
1 year ago
|
#include <iostream>
|
||
|
#include <string>
|
||
|
|
||
|
#ifdef _WIN32
|
||
|
#include <fcntl.h>
|
||
|
#else
|
||
|
#include <unistd.h>
|
||
|
#endif
|
||
|
|
||
|
#include "google/protobuf/descriptor.pb.h"
|
||
10 months ago
|
#include "absl/flags/flag.h"
|
||
|
#include "absl/flags/parse.h"
|
||
|
#include "absl/log/absl_log.h"
|
||
1 year ago
|
#include "absl/strings/escaping.h"
|
||
|
|
||
|
#if defined(_WIN32)
|
||
|
#include "google/protobuf/io/io_win32.h"
|
||
|
|
||
|
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
|
||
|
// them like we do below.
|
||
|
using google::protobuf::io::win32::setmode;
|
||
|
#endif
|
||
|
|
||
10 months ago
|
ABSL_FLAG(std::string, encoding, "octal",
|
||
|
"The encoding to use for the output.");
|
||
|
|
||
1 year ago
|
int main(int argc, char *argv[]) {
|
||
10 months ago
|
absl::ParseCommandLine(argc, argv);
|
||
1 year ago
|
#ifdef _WIN32
|
||
|
setmode(STDIN_FILENO, _O_BINARY);
|
||
|
setmode(STDOUT_FILENO, _O_BINARY);
|
||
|
#endif
|
||
|
google::protobuf::FeatureSetDefaults defaults;
|
||
|
if (!defaults.ParseFromFileDescriptor(STDIN_FILENO)) {
|
||
|
std::cerr << argv[0] << ": unable to parse edition defaults." << std::endl;
|
||
|
return 1;
|
||
|
}
|
||
|
std::string output;
|
||
|
defaults.SerializeToString(&output);
|
||
10 months ago
|
std::string encoding = absl::GetFlag(FLAGS_encoding);
|
||
|
if (encoding == "base64") {
|
||
|
std::cout << absl::Base64Escape(output);
|
||
|
} else if (encoding == "octal") {
|
||
|
std::cout << absl::CEscape(output);
|
||
|
} else {
|
||
|
ABSL_LOG(FATAL) << "Unknown encoding: " << encoding;
|
||
|
}
|
||
1 year ago
|
return 0;
|
||
|
}
|