The communication protocol between Google Protobuf and AS3

Source: Internet
Author: User

Protobuf is a set of tools developed by Google for serialization of structural data, communication protocols, data storage, etc., with the advantages of language independence, platform independence and scalability.

When used for communication, as long as both sides of the communication use the Protocol code generated by PROTOBUF, they can be used to serialize data into binary data or parse it. It supports C + +, JAVA, and Python itself. After installing the AS3 version of the plug-in, can also be used for the Flash platform and other platform data communication.

how to write. proto files, define AS3 and backend protocol content (this part is translated from Google's help document)

PROTOBUF to handle data communication can eliminate the communication between the two sides of the problem of language, where we want to communicate on the one side is flash, its language is actionscript3.0. The other end can be any protobuf supported language, C + +, Java, and so on.

First of all, the Protocol of communication, that is, the two sides to transmit what kind of information, what kinds of information, each of the information contains what data. These rules will be written in a file with a. proto suffix (of course you want to end with a different suffix or do not use the suffix is not a problem, as long as the following use of this. proto file in the batch file modified to the corresponding file name on the OK).

After the batch file is invoked, the proto file is generated, and we need to generate the. as file here. The other end of the communication also needs to generate the corresponding file based on its platform.

Writing format for proto files: 1. Writing of messages (message)

1 2 3 4 5 6 7 The client submits the authentication message to the server op_c_auth_session {Required String account_name = 1;    Required String password = 2; Optional Int32 somenumber = 3 [default = 0]; }

The above defines a login authentication message sent to the server by the client, which can carry information from three fields of account_name, password, and Somenumber.

The message begins with the definition of a message, followed by a string that is the name of the message, and as the generated AS3 class name, the generated class is the Com.netease.protobuf.Message subclass.

Specify field Rules

Required indicates that this field is required, and the field defined in required will create a public member variable in the corresponding AS3 class, for example, the Op_c_auth_session class above will have the following 2 fields:

1 2 public Var accountname:string;

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: info-contact@alibabacloud.com 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.