protoc-gen-as3 的as3 序列化和反序列化例子

茅桐
2023-12-01

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三种,其他语言就需要依靠插件来解决生成代码问题。



[plain]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"   
  3.                xmlns:s="library://ns.adobe.com/flex/spark"   
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">  
  5.     <fx:Declarations>  
  6.         <!-- 将非可视元素(例如服务、值对象)放在此处 -->  
  7.     </fx:Declarations>  
  8.     <fx:Script>  
  9.         <![CDATA[  
  10.             import tutorial.Person;  
  11.               
  12.             protected function button1_clickHandler(event:MouseEvent):void  
  13.             {  
  14.                 var person:Person = new Person();  
  15.                 person.email = "huangssssx@yahoo.com";  
  16.                 person.id = 1;  
  17.                 person.name = "huangchuanjian";  
  18.                 var b:ByteArray = new ByteArray();  
  19.                 person.writeTo(b);  
  20.                 var person2:Person = new Person();  
  21.                 b.position = 0;  
  22.                 person2.mergeFrom(b);  
  23.                 trace(person2.name+","+person2.email);//huangchuanjian,huangssssx@yahoo.com反序列化成功  
  24.             }  
  25.               
  26.         ]]>  
  27.     </fx:Script>  
  28.       
  29.     <s:Button click="button1_clickHandler(event)"/>  
  30. </s:Application>  
 类似资料: