python读写protobuf
来源:互联网 发布:广电网络wifi上不了网 编辑:程序博客网 时间:2024/06/06 18:09
{
};
message
{
};
protoc --python_out=./ ./entity.proto
test_pb.py
01 # coding: gbk
02 import entity_pb2
03 entitydesc= entity_pb2.entity_desc()
04 entitydesc.entity_id=1
05 entitydesc.entity_name='haha'
06
07 #create proto
08 entityattr=entitydesc.attributes.add() #嵌套message
09 entityattr.attr_id = 11
10 entityattr.attribute = '标题'.decode('gbk').encode('utf-8')
11 entityattr.value.append("title adfadf")
12
13 entity_attr_str=entityattr.SerializeToString()
14 print entity_attr_str
15 entitydesc_str=entitydesc.SerializeToString()
16 print entitydesc_str
17 print '----'
18 #read
19 entityattr2 = entity_pb2.entity_attr()
20 entityattr2.ParseFromString(entity_attr_str)
21 print entityattr2.attr_id
22 print entityattr2.attribute.decode('utf-8').encode('gbk')
23 for i in entityattr2.value:
24 print i
25
26 print '----'
27 entitydesc2= entity_pb2.entity_desc()
28 entitydesc2.ParseFromString(entitydesc_str)
29 print entitydesc2.entity_id
30 #repeated entity_attr attributes,由于是repeated需要遍历
31 for oneatt in entitydesc2.attributes:
32 print oneatt.attr_id
33 for i in oneatt.value:
34 print i
- python读写protobuf
- python读写protobuf
- python读写protobuf
- 【Python】用 Protobuf 读写数据
- python操作protobuf
- python使用protobuf
- protobuf python api
- python版protobuf安装
- python下使用protobuf
- Python操作protobuf示例
- Python中protobuf
- 安装protobuf Python支持
- python使用protobuf
- python protobuf 实践
- python 如何使用 protobuf
- python中使用protobuf
- Protobuf在Python中的使用
- windows下python protobuf 安装
- R语言与Python
- 使scp不用输入密码(转)
- machinations游戏经济系统验证工具
- python添加模块路径的三种方法
- python 线性代数:解多元一次方程
- python读写protobuf
- Java的File类
- Mac下发布Qt应用程序(转)
- 基于Qt的跨平台应用开发(转)
- Python GUI编程各种实现的对比(转)
- 开源硬件仿真库spice 3f5在xcode上编译
- C++与C语言混合编程
- UE4框架(转)
- the following packages have unmet dependencies