Firefly Communication Protocol - 9miao/Firefly GitHub Wiki

Firefly Communication Protocol

One·Protocol Buffers Abstract

Firefly’s communication protocol adopts Google’s Protocol Buffers (hereafter referred to PB). PB is a mechanism for serializing and structuring data and can be used for data communication among distributed applications or data exchange in heterogeneous environment. It’s similar to XML with the flexible, efficient and automated features but has advantages on size, speed and complexity. PB is adopted by Google in almost all internal RPC protocol and file format.

PB Features:
1) Not limited to platform and language
2) High performance: 20-100 times as fast as XML
3) Smaller size: 3-10 times as small as XML
4) User-friendly
5) Great compatibility

PB also has its shortcomings: it’s hard to understand than XML. XML is a well-known self-describing language with a great legibility feature. However, it’s almost impossible to understand PB, a string of binary code after serializing, if you don’t have the corresponding protocol format (.proto file).

Two·Protocol Buffers Installation

1) download Google Protocol Buffer source package
Download address (protobuf official website): http://code.google.com/p/protobuf/downloads/list
My download file version is Protocol Buffers 2.5.0 compiler.
2) Unzip package
You will get file list after unzip.
3) Compiling VSprojects
Open vsprojects catalog in extracted folder, and run libprotobuf.vcproj (its vs project file, make sure your computer has been installed vs2005, 2008 or 2010). Just click “convert” when the possible “convert project” button pop-up appears.

Right click to generate project libprotobuf, libprotobuf-lite, libprotoc, protoc respectively. (Compile schema: release schema)
4) compiling finished
When compiling is finished, we can find three libs and one exe file in vsprojects\Release, they are libprotobuf.lib,libprotobuf-lite.lib,libprotoc.lib and protoc.exe respectively.
5) Copy files to Windows catalog
Copy libprotobuf.lib,libprotobuf-lite.lib,libprotoc.lib and protoc.exe to Windows catalog of system disk. If your computer’s system is installed in C, then copy these files to c:\windows.
6) compiling proto file and generating python file
Assuming there is a proto file naming test.proto in E:\test, open CMD and input “protoc.exe -I=e:\test --python_out=e:\test e:\test\test.proto” to generate python source code file test_pb2.py, it can be directly used by importing to your project.

Three·Protocol Buffers using example in Firefly

A communication example of a game player accepting assignment is shown below, run proto file first:
1) applyQuest.proto

Message applyQuestRequest: client request
Message applyQuestResponse: server response
Compile applyQuest.proto to python source code file applyQuest_pb2.py via the aforementioned compile method.

2) quest.py file, server handles with this request file.

3) The corresponding proto file in client parses out the data that server sent back, so as to get the interaction result.

⚠️ **GitHub.com Fallback** ⚠️