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 ...
随机推荐
- Git如何删除版本库中的一个提交?
如果不小心增加了一个最新的提交,可以通过以下的操作删除,记住:是删除最新的提交,如果回滚到其他的提交上面,就会导致之后的全部消失. 1.git reset --hard HEAD~1 2.gi ...
- 在ASP.Net中"../" "./" "~/"表示的意思
"../" 相对当前(根据不同的语境,当前是不同的)的上一级目录"./" 就是当前目录 "~/" 当前项目的根路径,只在服务器端有效.
- cocos2d-lua SDK接入
1.lua 调用Java函数 1.1 在java中创建一个静态函数(比如在org.cocos2dx.lua.AppActivity.java中)名为Login public static void m ...
- C++11 左值与右值
概念 左值:表达式结束后依然存在的对象 右值:表达式结束后就不存在的临时对象 2.如何判断左值和右值 能不能对表达式取地址,如果能,就是左值,否则就是右值 3.对下面的语句进行区分 int a = 3 ...
- C#中partial关键字
1. 什么是局部类型? C# 2.0 引入了局部类型的概念.局部类型允许我们将一个类.结构或接口分成几个部分,分别实现在几个不同的.cs文件中. 局部类型适用于以下情况: (1) 类型特别大,不宜放在 ...
- linux跨主机复制文件或文件夹
复制文件基本格式:(本地到远程) scp 文件名 用户名@ip:文件全目录 如果是文件夹加上参数 -r scp -r 基础目录 用户名@ip:目录 栗子: scp local_file remote_ ...
- linux的学习系列 10---vi
Linux下的文本编辑器有很多种,vi 是最常用的,也是各版本Linux的标配.注意,vi 仅仅是一个文本编辑器,可以给字符着色,可以自动补全,但是不像 Windows 下的 word 有排版功能. ...
- ImageLoader的Jar包加载图片
注意:需要添加权限,若缓存图片第二个必须要加 <uses-permission android:name="android.permission.INTERNET" /> ...
- AI 人工智能 探索 (十)
呼叫事件图形结构如下 蓝色代表 警察局 红色代表警察 黄色代表 死亡人 蓝色球代表呼救人 黑色代表 敌人 警察目标是 攻击 黑色人,但 路中 会碰到 黄色人,如果警察有 救人功能 则会先救人去医院再看 ...
- JS-DOM操作应用高级(二)
搜索 字符串比较.忽略大小写----大小写转换.模糊搜索----search的使用.split.高亮显示及筛选 toLowerCase() 方法用于把字符串转换为小写 str.search('') ...