protobuffer
caffe 里面贯穿始终的文件格式就是protobuffer和glog了,不得不佩服,google确实很牛啊,恭维的话不说,熟悉一下protobuffer吧。其中官方文档什么的,网上搜吧,还有一系列别人在ubuntu和windows下的使用。把caffe中的代码粘贴下来如下:
//读取保存为text文档的proto文件,读进来,并通过Parse解析。
void ReadProtoFromTextFile(const char* filename,
::google::protobuf::Message* proto) {
int fd = open(filename, O_RDONLY);
CHECK_NE(fd, -1) << "File not found: " << filename;
FileInputStream* input = new FileInputStream(fd);
CHECK(google::protobuf::TextFormat::Parse(input, proto));
delete input;
close(fd);
}
//把proto写到文件,文件是text格式的。
void WriteProtoToTextFile(const Message& proto, const char* filename) {
int fd = open(filename, O_WRONLY);
FileOutputStream* output = new FileOutputStream(fd);
CHECK(google::protobuf::TextFormat::Print(proto, output));
delete output;
close(fd);
}
//读proto,其中proto的保存格式是binary格式文件。
void ReadProtoFromBinaryFile(const char* filename, Message* proto) {
int fd = open(filename, O_RDONLY);
CHECK_NE(fd, -1) << "File not found: " << filename;
ZeroCopyInputStream* raw_input = new FileInputStream(fd);
CodedInputStream* coded_input = new CodedInputStream(raw_input);
coded_input->SetTotalBytesLimit(536870912, 268435456);
CHECK(proto->ParseFromCodedStream(coded_input));
delete coded_input;
delete raw_input;
close(fd);
}
//将proto保存到文件,文件的序列化格式是binary的
void WriteProtoToBinaryFile(const Message& proto, const char* filename) {
fstream output(filename, ios::out | ios::trunc | ios::binary);
CHECK(proto.SerializeToOstream(&output));
}
从代码可以看到,提供了两种格式,一种是文档格式的,一种是二进制格式的。其中值得注意的是几个函数,
ZeroCopyInputStream ,相应的有ZeroCopyOutputStream //避免进行内存的拷贝 具体参考:http://name5566.com/2633.html,https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.io.zero_copy_stream
CodedInputStream 相应CodedOutputStream//,正如上面代码写的,用来定义不同长度的解析,理解的可能不太对,具体可参见:https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.io.coded_stream?hl=zh-CN
未完待续,儿子哭闹了,要哄我家小祖宗碎觉了。
protobuffer相关推荐
- vs2013编译 protoBuffer编译出现的问题
2019独角兽企业重金招聘Python工程师标准>>> 编译protobuffer ,出现了两个问题 1.vs加载项目后,会发现min函数 没有引入头文件 #include &l ...
- ProtoBuffer由.proto文件生成.cc/.h
ProtoBuffer由.proto文件生成.cc/.h 一:编译源码 下载地址:http://code.google.com/p/protobuf/downloads/list 下载后,根据编译说 ...
- AspnetCore 2.0 自动API文档生成组件,支持protobuffer
关于 API文档自动生成,用于对APP端的开发帮助文档生成,默认ProtoBuffer传输格式. 本项目并不是RESTful风格,是面向功能的API类型.ApiDoc的作用是根据定义好的API接口和注 ...
- Caffe 增加自定义 Layer 及其 ProtoBuffer 参数
转载自:http://blog.csdn.net/kkk584520/article/details/52721838 http://blog.csdn.net/kkk584520 博客内容基于新书& ...
- Protobuffer和json深度对比
Protobuffer和json深度对比 JSON相信大家都知道是什么东西,如果不知道,那可就真的OUT了,GOOGLE一下去.这里就不介绍啥的了. Protobuffer大家估计就很少听说了,但如果 ...
- Protobuffer教程
目录 什么是protobuffer? protobuffer是如何工作的? 为什么不用xml? 1.什么是protobuffer? protobuffer是一种灵活,高效,自动化的机制,用于序列化结构 ...
- PHP probuf详细步骤_【转】protobuffer php使用
收藏一篇文章 没有实际操作过 . 公司再用都是直接用现成的东西 这片文章收藏一下 protobuffer是google推出的一种数据传的方式,具体压缩,体积小的特点 protobuffer本身不支持p ...
- protobuffer简介
1.什么是protocol buffers 2.protocol buffers的工作流程 3.protobuffer和xml.json的区别 1.什么是protocol buffers protoc ...
- 抖音数据采集xgorgon算法、device_id算法、xlog算法、protobuffer解密...
某音里面用得比较多的算法是xgorgon算法,设备注册算法.xlog算法.protobuffer,有了这些算法才能玩转某音. xgorgon算法:生成xg签名算法,最常用的算法: 设备注册算法:生成设 ...
最新文章
- auto自动类型推断
- Deep Learning(深度学习)学习笔记整理系列三
- 带有示例的Python date strftime()方法
- 输入域html,我可以让HTML输入表单域成为可选的吗?
- 一代上网人的记忆!百度浏览器将不再更新
- java emmt插件_Emmet缩写语法
- 几种机器学习平台的对比和选择
- String、StringBuffer、StringBuilder有什么区别
- java 数组中数字和_java – 查找数组中的数字总和 – 不包括数字13和它后面的数字...
- SAP固定资产业务场景及方案
- Java:QQ登录页面的制作(实现成功登录的代码)——含源码
- 实验代做 行人识别_实验室代做实验项目
- 小胖儿 闲聊 百度有啊
- 大象跳转:解析微信内自动跳转浏览器打开URL网页的操作步骤
- [Unity3D]Unity3D游戏开发之从《魂斗罗》游戏说起(上)——目标追踪
- redis发布/订阅模式
- 正在更新office,请稍后 然后报错 解决办法
- 拼多多求变 200 天:撒钱百亿元,江湖人称拼爹爹?
- uni-app实现app内嵌微信文章
- [Unity]动态人物头像