Sabre forges 10-year partnership with Google to build the future of travel
sabre.com3 pointsby andrewg0 comments
message Config {
repeated Server server = 1;
}
message Server {
string address = 1;
int32 port = 2;
bool standby = 3;
}
And then you use the text representation in a config file: # main instance
server { address: "127.0.0.1" port: 4567 }
# backup instance
server { address: "127.0.0.1" port: 9876 standby: true }
And load it into a message instance: Config config;
google::protobuf::TextFormat::ParseFromString(input, &config); std::variant<int, bool, double> options;
options = true;
bool value = std::get<bool>(options);
bool has_bool = std::holds_alternative<bool>(options);
// or test which alternative is held
if (auto i = std::get_if<int>(&options)) {
// do something with int
} else if (auto b = std::get_if<bool>(&options)) {
// do something with bool
} else {
// do something with double
}
You tell it what’s being renamed with a special comment.