使用protobuf编写配置文件以及读写
2014-09-29 11:28
916 查看
.proto文件示例
写配置文件
读配置文件
message Configure { required string host = 1; required uint32 port = 2; }
写配置文件
Configure config; config.set_host("127.0.0.1"); config.set_port(8080); string contect; google::protobuf::TextFormat::PrintToString(config, & contect);
ofstream fout; fout.open("config.cfg", ios::out| ios_base::ate); if (!fout.is_open()) { fprintf(stderr, "open config.cfg fail\n"); return -1; } fout << contect <<endl; fout.flush(); fout.close();
读配置文件
int fd = open("config.cfg", O_RDONLY); if (fd < 0) { printf("open config.cfg failure:%s \n",strerror(errno)); return false; } google::protobuf::io::FileInputStream fileInput(fd); fileInput.SetCloseOnDelete(true); google::protobuf::TextFormat::Parse(&fileInput, &config);
相关文章推荐
- Protobuf :编写proto文件以及protobuf文件的使用
- Google protobuf使用之proto文件编写规则
- iOS 整理基于socket集成Protobuf相关环境,以及将Protobuf文件转成OC文件,以及使用Protobuf
- Google protobuf使用之proto文件编写规则(二)
- protobuf的配置原始文件.proto中,使用修饰符repeated、required、optional生成的java文件的区别
- QT读写ini配置文件以及绝对路径的使用
- protobuf使用之proto文件编写规则
- 一个用C#编写的自动读写配置文件的开源组件
- FCKeditor是使用非常广泛的HTML编辑器,本文从 ASP.NET 的使用场景对 FCKeditor 与 FCKeditor.NET 的配置、功能扩展(如自定义文件上传子目录、自定义文件名、上传图片的后期处理等)、以及安全性进行初步的阐述。
- 使用反射和范型来动态读写应用程序配置文件
- 一个用C#编写的自动读写配置文件的开源组件
- .Net2.0使用ConfigurationManager读写配置文件
- Control Study->AdRotator广告控件显示自定义配置文件中广告以及与DataGrid控件结合使用显示图片(示例代码下载)
- .net2.0 使用configurationmanager读写配置文件
- 使用WindowsAPI读写配置文件
- 代理自动配置文件-pac文件格式以及使用方式
- .Net2.0使用ConfigurationManager读写配置文件
- 一个用C#编写的自动读写配置文件的开源组件--V1.0.2版本
- 使用XML读写删除功能来实现资源文件配置
- 使用ConfigurationManager类 读写配置文件