protoc-gen-as3 (http://code.google.com/p/protoc-gen-as3/)是国人自己写的protocol buffers插件,用于生成as3端的protoc代码,比官方的插件效率更高、bug更少。不过网上例子比较少,我这里抛砖引玉写下一份例子,给大家做个参考。
ps:http://baike.baidu.com/view/1708160.htm是对 protocol buffers的介绍。现在官方只支持java,c++,physon三种,其他语言就需要依靠插件来解决生成代码问题。
- <?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"
- xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
- <fx:Declarations>
- <!-- 将非可视元素(例如服务、值对象)放在此处 -->
- </fx:Declarations>
- <fx:Script>
- <![CDATA[
- import tutorial.Person;
-
- protected function button1_clickHandler(event:MouseEvent):void
- {
- var person:Person = new Person();
- person.email = "huangssssx@yahoo.com";
- person.id = 1;
- person.name = "huangchuanjian";
- var b:ByteArray = new ByteArray();
- person.writeTo(b);
- var person2:Person = new Person();
- b.position = 0;
- person2.mergeFrom(b);
- trace(person2.name+","+person2.email);//huangchuanjian,huangssssx@yahoo.com反序列化成功
- }
-
- ]]>
- </fx:Script>
-
- <s:Button click="button1_clickHandler(event)"/>
- </s:Application>