protobuf python api
摘要:
python中一切都可以看作类。那么如何查看每个类的API。使用ipython
python protobuf 的函数在message中定义
编译
protoc -I=./ --python_out=./ people.proto
1 GidChannelInfo.proto
package bfd.gidchannelinfo;
//定义 gid的来源,是dsp还是电商或者媒体等
message Channel
{
required string name = 1; //来源,例如dsp_Cbehe
required int64 timestamp = 2; //时间戳
}
//key为 G:Channel:gid
message GidChannelInfo
{
required Channel init_channel = 1; //gid初次产生的channel来源
repeated Channel channel = 2; //包含的所有channel渠道
}
2 例子
gidchannelinfo_tmp = GidChannelInfo_pb2.GidChannelInfo()
channel_tmp = GidChannelInfo_pb2.Channel()
DB_SERVER = 'app-2'
db = "DMP_GDMP_Cbehe"
conn = mdb.Connect(DB_SERVER,'bfdroot','qianfendian',db)
cur = conn.cursor()
#cur.execute("select gid,update_time from Mapping_gid where id >0 and id<20000000")
cur.execute("select gid,update_time from Mapping_gid limit 1")
results = cur.fetchall()
for result in results:
print "result :",str(result)
gid = result[0]
date_tmp = result[1]
key = "G:GidChannelInfo:"+gid
#d = datetime.datetime.strptime(date_tmp,"%Y-%m-%d %H:%M:%S")
timestamp_tmp = int(time.mktime(date_tmp.timetuple()))
channel_tmp.name = "dsp_baifendian"
channel_tmp.timestamp = timestamp_tmp
print "timestamp_tmp :",timestamp_tmp
gidchannelinfo_tmp.init_channel.CopyFrom(channel_tmp)
channel_tmp = gidchannelinfo_tmp.channel.add()
channel_tmp.name = "dsp_baifendian"
channel_tmp.timestamp = timestamp_tmp
channel_tmp = gidchannelinfo_tmp.channel.add()
channel_tmp.name = "dsp_behe"
channel_tmp.timestamp = timestamp_tmp
print "gidchannelinfo_tmp: ",gidchannelinfo_tmp
mystr = gidchannelinfo_tmp.SerializeToString()
3 注意 :
对于 Singular fields 可以使用 gci.init_channel.MergeFrom赋值
或者对于每个属性赋值。gci.init_channel.name=name
对于repeated fileds可以使用
CopyFrom MergeFrom
4 api 说明
MergeFrom(self, other_msg) |
source code |
Merges the contents of the specified message into current message. This method merges the contents of the specified message into the current
message. Singular fields that are set in the specified message overwrite
the corresponding fields in the current message. Repeated fields are
appended. Singular sub-messages and groups are recursively merged. Args:
other_msg: Message to merge into the current message.
CopyFrom(self, other_msg) |
source code |
Copies the content of the specified message into the current message. The method clears the current message and then merges the specified
message using MergeFrom. Args:
other_msg: Message to copy into the current one.
protobuf python api的更多相关文章
- Appium python API 总结
Appium python api 根据testerhome的文章,再补充一些文章里面没有提及的API [TOC] [1]find element driver 的方法 注意:这几个方法只能通过sel ...
- The novaclient Python API
The novaclient Python API Usage First create a client instance with your credentials: >>> f ...
- Openstack python api 学习文档 api创建虚拟机
Openstack python api 学习文档 转载请注明http://www.cnblogs.com/juandx/p/4953191.html 因为需要学习使用api接口调用openstack ...
- BotVS开发基础—Python API
代码 import json def main(): # python API列表 https://www.botvs.com/bbs-topic/443 #状态信息 LogStatus(" ...
- 《Spark Python API 官方文档中文版》 之 pyspark.sql (一)
摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...
- 《Spark Python API 官方文档中文版》 之 pyspark.sql (二)
摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...
- HBase Python API
HBase Python API HBase通过thrift机制可以实现多语言编程,信息通过端口传递,因此Python是个不错的选择 吐槽 博主在Mac上配置HBase,奈何Zoomkeeper一直报 ...
- 二、Blender/Python API总览
原文:https://docs.blender.org/api/blender_python_api_current/info_overview.html Python in Blender Ble ...
- Appium+python自动化8-Appium Python API
Appium+python自动化8-AppiumPython API 前言: Appium Python API全集,不知道哪个大神整理的,这里贴出来分享给大家. 1.contexts conte ...
随机推荐
- JSP内置对象--response对象 (addCookie(),setHeader(),sendRedirect())
服务器接收客户端请求:request 服务器对客户端的回应:response javax.servlet.http的接口HttpServletResponse extends ServletRespo ...
- vs调试有时能进去后台,有时不能进去
前两天做项目时,遇到调试时有时候能进后台,有时候直接就弹出运行结果,反复查找原因,最后发现,原来是页面输出缓存的原因,我在web页面用到了< OutputCache Duration=" ...
- How To Add Swap on Ubuntu 14.04
https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04 How To Add Swap on ...
- 标签—box-shadow
box-shadow:2px 3px 4px #CCC; 一个带外阴影的元素,阴影位置x轴偏移2px,y轴偏移3px,模糊范围4px,阴影颜色#CCC box-shadow:inset 0 -4px ...
- 为ubuntu添加右键打开终端效果
安装工具:nautilus-open-terminal sudo apt-get install nautilus-open-terminal 注销或重启
- oracle 锁表的处理。
最近系统每天经常锁表,进程杀死后,很快再次锁住这个表. (一)先贴出现场处理死锁的步骤. 另外:有时候通过PL/SQL执行kill session可能仍然无法解锁,此时需要登陆到Oracle服务器将进 ...
- download下载excel模板的代码
<%-- 直接在JSP页面中进行文件下载的代码(改 Servlet 或者 JavaBean 的话自己改吧), 支持中文附件名(做了转内码处理). 事实上只要向 out 输出字节就被认为是附件内容 ...
- MVVM 入门介绍
转载自:http://www.objccn.io/issue-13-1/ 我于 2011 年在 500px 找到自己的第一份 iOS 开发工作.虽然我已经在大学里做了好几年 iOS 外包开发,但这才是 ...
- js对象大总结2016/4/19
本地对象(非静态对象) 常用的对象Object,Funcion,Array,Boolen,String,Boolen,Number,Date,RegEXP,Error;new一下就能用的 内置对象:( ...
- 交换数组中两个元素的位置,元素包括key和value 一维数组
/*author: yangyu@sina.cndescription: 交换数组中两个元素的位置,元素包括key和value,具体用法见下面的例子*/$arr = array(11=>'a', ...