#include "proto_tool.h" #include #include #include #include using google::protobuf::io::FileInputStream; using google::protobuf::io::FileOutputStream; using google::protobuf::io::ZeroCopyInputStream; using google::protobuf::io::CodedInputStream; using google::protobuf::io::ZeroCopyOutputStream; using google::protobuf::io::CodedOutputStream; using google::protobuf::Message; //读取protobuf 配置文件,转化为protobuf参数形式 //input: prototxt_path :prototxt文件路径 //ouput: parameter: protobuf参数,这里是消息基类,实际调用时传入对应的子类即可。 bool proto_tool::read_proto_param(std::string prototxt_path, ::google::protobuf::Message& protobuf_parameter) { int fd = open(prototxt_path.c_str(), O_RDONLY); if (fd == -1) return false; FileInputStream* input = new FileInputStream(fd); bool success = google::protobuf::TextFormat::Parse(input, &protobuf_parameter); delete input; close(fd); return success; }