Thrift-1079:Support i64 in AS3
Client: as3
Patch: Reverting 

Reverting patch due to usage of non public library which breaks ability to export as3 client to maven central during a release.



git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1337007 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_as3_generator.cc b/compiler/cpp/src/generate/t_as3_generator.cc
index 29ac98a..05514f1 100644
--- a/compiler/cpp/src/generate/t_as3_generator.cc
+++ b/compiler/cpp/src/generate/t_as3_generator.cc
@@ -193,8 +193,7 @@
       ttype->is_container() ||
       ttype->is_struct() ||
       ttype->is_xception() ||
-      ttype->is_string() ||
-      (ttype->is_base_type() && ((t_base_type*)ttype)->get_base() == t_base_type::TYPE_I64);//for using the new BigInteger library
+      ttype->is_string();
   }
 
   std::string constant_name(std::string name);
@@ -262,8 +261,7 @@
     string() +
     "import org.apache.thrift.Set;\n" +
     "import flash.utils.ByteArray;\n" +
-    "import flash.utils.Dictionary;\n" +
-    "import com.hurlant.math.BigInteger;\n\n";
+    "import flash.utils.Dictionary;\n\n";
 }
 
 /**
@@ -486,13 +484,7 @@
     vector<t_field*>::const_iterator f_iter;
     const map<t_const_value*, t_const_value*>& val = value->get_map();
     map<t_const_value*, t_const_value*>::const_iterator v_iter;
-
-    out << name;
-    if(!defval){
-      out << ":" << type_name(type);
-    }
-    out << " = new " << type_name(type, false, true) << "();" << endl;
-
+    out << name << ":" << type_name(type) << " = new " << type_name(type, false, true) << "();" << endl;
     if (!in_static) {
       indent(out) << "{" << endl;
       indent_up();
@@ -599,20 +591,20 @@
           render << ((value->get_integer() > 0) ? "true" : "false");
           break;
         case t_base_type::TYPE_BYTE:
-          render << "int(" << value->get_integer() << ")";
+          render << "(byte)" << value->get_integer();
           break;
         case t_base_type::TYPE_I16:
-          render << "int(" << value->get_integer() << ")";
+          render << "(short)" << value->get_integer();
           break;
         case t_base_type::TYPE_I32:
           render << value->get_integer();
           break;
         case t_base_type::TYPE_I64:
-          render << "new BigInteger(\"" << hex << value->get_integer() << dec << "\")";
+          render << value->get_integer() << "L";
           break;
         case t_base_type::TYPE_DOUBLE:
           if (value->get_type() == t_const_value::CV_INTEGER) {
-            render << "Number(" << value->get_integer() << ")";
+            render << "(double)" << value->get_integer();
           } else {
             render << value->get_double();
           }
@@ -2473,7 +2465,7 @@
   case t_base_type::TYPE_I32:
     return "int";
   case t_base_type::TYPE_I64:
-    return "BigInteger";
+    throw "i64 is not yet supported in as3";
   case t_base_type::TYPE_DOUBLE:
     return "Number";
   default:
@@ -2508,10 +2500,8 @@
       case t_base_type::TYPE_BYTE:
       case t_base_type::TYPE_I16:
       case t_base_type::TYPE_I32:
-        result += " = 0"; //leaving this here even though it doesn't work with BigInteger because it's never called by the generator.
-        break;
       case t_base_type::TYPE_I64:
-        result += " = new BigInteger(\"0x0\")";
+        result += " = 0";
         break;
       case t_base_type::TYPE_DOUBLE:
         result += " = (double)0";
diff --git a/lib/as3/build.xml b/lib/as3/build.xml
index 98c654a..aa523f0 100644
--- a/lib/as3/build.xml
+++ b/lib/as3/build.xml
@@ -41,7 +41,6 @@
 
   <property name="src" value="${basedir}/src"/>
   <property name="build.dir" value="${basedir}/build"/>
-  <property name="lib.dir" value="${basedir}/lib"/>
 
   <property name="as3.swc.file" location="${build.dir}/${as3.final.name}.swc"/>
   <property name="as3.pom.xml" location="${build.dir}/${as3.final.name}.pom"/>
@@ -82,9 +81,6 @@
 
     <compc output="${as3.swc.file}" include-classes="${as.src.classes}">
       <source-path path-element="${src}"/>
-      <compiler.include-libraries dir="${lib.dir}" append="true">
-          <include name="as3crypto-1.3.0-library.swc" />
-      </compiler.include-libraries>
     </compc>
   </target>
 
diff --git a/lib/as3/src/org/apache/thrift/TDeserializer.as b/lib/as3/src/org/apache/thrift/TDeserializer.as
deleted file mode 100644
index a31aa0b..0000000
--- a/lib/as3/src/org/apache/thrift/TDeserializer.as
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.thrift {
-	import flash.utils.ByteArray;
-	
-	import org.apache.thrift.protocol.TBinaryProtocol;
-	import org.apache.thrift.protocol.TProtocol;
-	import org.apache.thrift.transport.TMemoryBuffer;
-	
-	public class TDeserializer {
-		private var _protocol:TProtocol;
-		private var _transport:TMemoryBuffer;
-		
-		public function TDeserializer() {
-			_transport = new TMemoryBuffer();
-			_protocol = new TBinaryProtocol(_transport);
-		}
-		
-		/**
-		 * Take the bytes from the ByteArray <code>bytes</code> and populate <code>base</code> with it.
-		 */
-		public function deserialize(base:TBase, bytes:ByteArray):void {
-			bytes.position = 0; //make sure we're at the beginning. It's a very good place to start
-			_transport.reset();
-			_transport.write(bytes, 0, bytes.bytesAvailable); //write the ByteArray into the transport object
-			_transport.reset();
-			base.read(_protocol); // Read the data from the transport into the TBase object via the protocol
-		}
-
-	}
-}
diff --git a/lib/as3/src/org/apache/thrift/TSerializer.as b/lib/as3/src/org/apache/thrift/TSerializer.as
deleted file mode 100644
index c243d0b..0000000
--- a/lib/as3/src/org/apache/thrift/TSerializer.as
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.thrift {
-	import flash.utils.ByteArray;
-
-	import org.apache.thrift.protocol.TBinaryProtocol;
-	import org.apache.thrift.protocol.TProtocol;
-	import org.apache.thrift.transport.TMemoryBuffer;
-	import org.apache.thrift.transport.TTransport;
-
-	public class TSerializer {
-		private var _protocol:TProtocol;
-		private var _transport:TTransport;
-
-		public function TSerializer() {
-			_transport = new TMemoryBuffer();
-			_protocol = new TBinaryProtocol( _transport );
-		}
-
-		public function serialize( message:TBase ):ByteArray {
-			( _transport as TMemoryBuffer ).reset();
-			message.write( _protocol );
-			return ( _transport as TMemoryBuffer ).getArray();
-		}
-
-		public function toString( message:TBase ):String {
-			return serialize( message ).toString();
-		}
-	}
-}
diff --git a/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as b/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
index f6acdb7..4412479 100644
--- a/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
+++ b/lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
@@ -21,7 +21,6 @@
 
   import flash.utils.ByteArray;
   
-  import com.hurlant.math.BigInteger;
   import org.apache.thrift.TError;
   import org.apache.thrift.transport.THttpClient;
   import org.apache.thrift.transport.TTransport;
@@ -155,20 +154,18 @@
         trans_.write(out, 0, 4);
       }
       
-      public function writeI64(i64:BigInteger):void {
-        reset(out);
-        var ba:ByteArray = i64.toByteArray();
-        ba.position = 0;
-
-        // pad the output to make sure this 64-bit number takes 
-        // all 64-bits, and no more since BigInteger can handle more
-        var difference:int = 8 - Math.min(8, ba.length);
-        for( ; difference > 0; difference-- ){
-          out.writeByte(0);
-        }
-        out.writeBytes(ba, 0, Math.min(8, ba.bytesAvailable));
-        trans_.write(out, 0, 8);
-      }
+      //private byte[] i64out = new byte[8];
+      //public function writeI64(i64:Number):void {
+        //i64out[0] = (byte)(0xff & (i64 >> 56));
+        //i64out[1] = (byte)(0xff & (i64 >> 48));
+        //i64out[2] = (byte)(0xff & (i64 >> 40));
+        //i64out[3] = (byte)(0xff & (i64 >> 32));
+        //i64out[4] = (byte)(0xff & (i64 >> 24));
+        //i64out[5] = (byte)(0xff & (i64 >> 16));
+        //i64out[6] = (byte)(0xff & (i64 >> 8));
+        //i64out[7] = (byte)(0xff & (i64));
+        //trans_.write(i64out, 0, 8);
+      //}
       
       public function writeDouble(dub:Number):void {
         reset(out);
@@ -267,10 +264,21 @@
       return bytes.readInt();
     }
   
-    public function readI64():BigInteger {
-      readAll(8);
-      return new BigInteger(bytes);
+    //private byte[] i64rd = new byte[8];
+    /*
+    public function readI64() throws TException {
+      readAll(i64rd, 0, 8);
+      return
+        ((long)(i64rd[0] & 0xff) << 56) |
+        ((long)(i64rd[1] & 0xff) << 48) |
+        ((long)(i64rd[2] & 0xff) << 40) |
+        ((long)(i64rd[3] & 0xff) << 32) |
+        ((long)(i64rd[4] & 0xff) << 24) |
+        ((long)(i64rd[5] & 0xff) << 16) |
+        ((long)(i64rd[6] & 0xff) <<  8) |
+        ((long)(i64rd[7] & 0xff));
     }
+    */
   
     public function readDouble():Number {
       readAll(8);
diff --git a/lib/as3/src/org/apache/thrift/protocol/TProtocol.as b/lib/as3/src/org/apache/thrift/protocol/TProtocol.as
index 53499dc..bb9d744 100644
--- a/lib/as3/src/org/apache/thrift/protocol/TProtocol.as
+++ b/lib/as3/src/org/apache/thrift/protocol/TProtocol.as
@@ -22,8 +22,6 @@
   import org.apache.thrift.TError;
   import org.apache.thrift.transport.TTransport;
 
-  import com.hurlant.math.BigInteger;
-
   import flash.utils.ByteArray;
   
   /**
@@ -72,7 +70,7 @@
     
     function writeI32(i32:int):void;
     
-    function writeI64(i64:BigInteger):void;
+    //function writeI64(i64:Number):void;
     
     function writeDouble(dub:Number):void;
     
@@ -115,7 +113,7 @@
     
     function readI32():int;
     
-    function readI64():BigInteger;
+    //function readI64():Number;
     
     function readDouble():Number;
     
@@ -123,4 +121,4 @@
     
     function readBinary():ByteArray;
   }
-}
+}
\ No newline at end of file
diff --git a/lib/as3/src/org/apache/thrift/transport/TMemoryBuffer.as b/lib/as3/src/org/apache/thrift/transport/TMemoryBuffer.as
deleted file mode 100644
index 8338e13..0000000
--- a/lib/as3/src/org/apache/thrift/transport/TMemoryBuffer.as
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.thrift.transport {
-	import flash.utils.ByteArray;
-	
-	public class TMemoryBuffer extends TTransport {
-		private var _barray:ByteArray;
-		
-		public function TMemoryBuffer() {
-			super();
-			_barray = new ByteArray();
-		}
-	
-		/**
-		 * @param buf the ByteArray to read into
-		 * @param buf the off to start writing
-		 * @param len the number of bytes to write into buf
-		 */
-	    override public function read(buf:ByteArray, off:int, len:int):int {
-		    buf.position = 0;
-		    
-		    var amtToRead:int = Math.min(len, _barray.bytesAvailable);
-		    
-		    if (amtToRead > 0) {
-		    	// offset, in writeBytes refers to the position of the array to read from
-		    	buf.writeBytes( _barray, _barray.position, amtToRead );
-		    	_barray.position += amtToRead; //we need to remember where we are in order to read the next thing
-		    }
-		    return amtToRead;
-		}
-		
-		/**
-		 * @param buf the ByteArray to read from
-		 * @param off the position to start reading from
-		 * @param len the number of bytes to read
-		 */
-	    override public function write(buf:ByteArray, off:int, len:int):void {
-	    	buf.position = off;
-	    	// offset in readBytes() refers to where to start _writing_ in the ByteArray you pass in.
-	    	buf.readBytes(_barray, _barray.length, len);
-	    	_barray.position = _barray.length; //put the position at the end of the used bytes in order to allow appending
-	    }
-	    
-	    override public function flush(callback:Function=null):void {
-	    	if ( callback != null ){
-	    		callback( null );
-	    	}
-	    	reset();
-	    }
-	    
-	    public function getArray():ByteArray {
-	    	var ret:ByteArray = new ByteArray();
-	    	ret.writeBytes(_barray); //copy _barray
-	    	ret.position = 0;
-	    	return ret;
-	    }
-	    
-	    public function reset():void {
-	    	_barray.position = 0;
-	    }
-	}
-}