Source: Internet
Author: User

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 Build

Python text

Python Install

This is where the Python protobuf library is installed.


Complete the test Test.proto

Message testmsg{    required int32 id=1;    Required Int32 time=2;    Optional string note=3;}


#-*-coding:utf-8-*-import google.protobufimport testmsg_pb2import time# Compression test = TESTMSG_PB2 () (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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.