Python Google protobuf use
Google Protobuf because of the use of binary packaging, data volume is small, and support the mainstream Java,c,python language,
Therefore, it is especially suitable for mobile clients to communicate with the server. It has unique advantages over Xml,html,json and other formats.
Unzip the protobuf-2.5.0.tar.gz with a Python directory.
First configure the Protoc.exe to the environment variable,
Then, under CMD, switch to the directory and execute
Python setup.py Build
Python setup.py text
Python setup.py Install
This is where the Python protobuf library is installed.
Example:
Complete the test Test.proto
Message testmsg{ required int32 id=1; Required Int32 time=2; Optional string note=3;}
Protoc.exe–python_out=d:/test/test.proto
#-*-coding:utf-8-*-import google.protobufimport testmsg_pb2import time# Compression test = TESTMSG_PB2 () test.id=1test.time=int (Time.time ()) test.string= "Asdftest" Print testtest_str = Test. Serializetostring () print test_str# unzip test1 = TESTMSG_PB2 () test1. Parsefromstring (test_str) Print test1
From for notes (Wiz)
List of attachments
Protobuf--python