How DELPHI, FLASH, AS3, flex use Protobuf (Google Protocol buffers)

Source: Internet
Author: User

Recently, I have studied the need to apply protobuf in different development environments because of job requirements. To prevent yourself from forgetting these things, now record here! Need friends can draw on some, because these things in Google and Baidu search up really laborious!

First of all, say Delphi.

Because Delphi now use a lot of people, so find this thing really bad looking! Fortunately, added a few QQ groups, useful friends told me!

The steps are as follows:

1, download the Delphi use Protobuf required items.

Address is here: http://sourceforge.NET/projects/fundementals/files/Fundamentals4/

2. Compiling ProtoCodeGen.exe
After downloading the above file, locate the PROTOCOLBUFFERS\CODEGENAPP\PROTOCODEGEN.DPR in the subdirectory-----compile it

I use the Delphi 2007 open the project will be prompted not to open anything, it doesn't matter, delete protocodegen.dproj, and then open it. No, just open it with Notepad, copy the code and build a new project ...

3, after compiling, get ProtoCodeGen.exe one. It will be able to put the *.proto file, born into a pas file.

4, in the D drive, I created a new Google folder, the newly generated protocodegen.exe put in

In this folder, I created a new file with Notepad, the contents are as follows

Message person {
Required String name = 1;
Required Int32 id = 2;
}

Save As Message.proto

Again, I'm using the Google folder to create a folder called Pas_out.

The specific compiled instructions are like this.

Open CMD. (DOS command line that, at the beginning-"Run-" cmd--"return)

Typing commands

This time, go to D:\google\pas_out down to find, will find generated a Pbmessagemessages.pas file.

Done!!!!!

5. How to use

Create a new project

Copy the files in the fundamentals.protobuf.4.0.01 (pressurized folder) Protocolbuffers and Utils directories to our new project and add them to the project.

Well, not all of them can be used, actually. This one looks at the generated pbmessagemessages.pas other IT needs 3 references

Cutils,
CStrings,
Cprotobufutils;

Encrypt or decrypt (the code for serialization or deserialization is as follows)

var P1,p2:tpersonrecord;
Len:integer;
Bt:tbytes;
Begin
P1. Name: = Edtname.text;
P1. Id: = Strtoint (Edtid.text);
SetLength (bt,100);
Encryption
Len: = Pbencodevaluepersonrecord (BT[0],100,P1);
Len: = Pbencodevaluepersonrecord (BT[0],100,P1);
SetLength (Bt,len);
Mmo1. Lines.add (IntToStr (len));
Decrypt
Personrecordinit (p2);
Len: =pbdecodevaluepersonrecord (BT[0],LEN,P2);
Mmo1. Lines.add (IntToStr (len));
Mmo1. Lines.add (P2. Name);
End

Completely accomplished!!!!!

==================================================================================================

Second, say Flash

1, or download the plugin.

In other words, this flash version and development tools are many, this block is used Flash Builder 4.7

In other words, the Flash uses Google's PROTOBUF plug-in also has 2.

PROTOBUF-ACTIONSCRIPT3 (said to be official, but not official)

PROTOC-GEN-AS3 (written by the Chinese-need to be tough)

Online comments said that the Chinese people write good, updated and timely, fewer bugs, support is also wide, and the so-called official, seemingly can make the use of-quite do!

This seat specially went to 2 open source address to see a bit.
Http://code.google.com/p/protobuf-actionscript3/downloads/list (the so-called official)

Last update date is OCT 2009

Looking at our countrymen's
Https://code.google.com/p/protoc-gen-as3/downloads/list
Last Updated date is Mar 2013

What else can you say? Decisive with the people!!!!

2. How do I do it after downloading?

I'm not going to write this part myself, just quote the previous article.
HTTP://BLOG.CSDN.NET/LUNA84/ARTICLE/DETAILS/8696217---Environment configuration and compilation directives

http://blog.csdn.Net/luna84/article/details/8695418

Note that you need to have the Java SDK as an environment, or you will be prompted when you tap the cmd command

' Java ' is not an internal or external command, or a program or batch file that can be run
Go to http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html to download the JDK installation, more than 100 m. 3, compilation and use of the method is copied from other people's blog, the details refer to the above 2 connections

The following content is from http://www.cnblogs.com/vincent-lee/archive/2012/01/23/2328866.html

PROTOC-GEN-AS3 steps for using ActionScript under window
1) Download protoc-gen-as3-1.0.0-rc6-bin.tar.gz and unzip to D:\google\as_plugin directory
2) Download Protoc-2.4.1-win32.zip and unzip to d:\google\
3) Create d:\google\as_out\ directory
4) Create D:\google\message.proto

message Person {      required string name = 1;      required int32 id = 2; }

5) Run cmd command

protoc.exe --plugin=protoc-gen-as3="protoc-gen-as3.bat" --as3_out=d:\google\as_out message.proto

Automatic generation of initializer.as.inc,person.as files under directory d:\google\as_out\
6) Open Flash Builder to create the app and introduce the D:\GOOGLE\AS_PLUGIN\PROTOBUF.SWC file

<?xml version= "1.0" encoding= "Utf-8"?
<s:application xmlns:fx= "http://ns.adobe.com/mxml/2009"  
  xmlns:s= "Library://ns.adobe.com/flex/spark" &NBSP;
  xmlns:mx= "library://ns.adobe.com/ Flex/mx "minwidth=" 955 "minheight=";

<fx:script>
<![ cdata[
Import Mx.controls.Alert;

Import Protocol.person;
Protected function Test_clickhandler (event:mouseevent): void
{
//TODO auto-generated method stub
var p: Person=new person ();
P.id=1;
P.name= "Tommy";
var b:bytearray=new ByteArray ();
P.writeto (b);
B.position = 0;
var pp:person=new person ();
Pp.mergefrom (b);
Alert.show ("pp.id=" +pp.id+ "\ r \ n" + "Pp.name=" +pp.name, "person");
}
]]>
</fx:script>

<fx:declarations>
<!--place non-visual elements (such as services, value objects) here-->
</fx:declarations>
<s:button x= "y=" id= "test" label= "test" click= "Test_clickhandler (event)"/
</s:application>

How DELPHI, FLASH, AS3, flex use Protobuf (Google Protocol buffers)

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.