You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2014/11/09 01:59:18 UTC
[4/8] thrift git commit: THRIFT-2644 Haxe support Client: Haxe Patch:
Jens Geyer
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index c49cb60..9f104fa 100755
--- a/configure.ac
+++ b/configure.ac
@@ -114,6 +114,7 @@ if test "$enable_libs" = "no"; then
with_python="no"
with_ruby="no"
with_haskell="no"
+ with_haxe="no"
with_perl="no"
with_php="no"
with_php_extension="no"
@@ -318,6 +319,16 @@ fi
AM_CONDITIONAL(WITH_GO, [test "$have_go" = "yes"])
+AX_THRIFT_LIB(haxe, [Haxe], yes)
+if test "$with_haxe" = "yes"; then
+ AC_PATH_PROG([HAXE], [haxe])
+ if [[ -x "$HAXE" ]] ; then
+ have_haxe="yes"
+ fi
+fi
+AM_CONDITIONAL(WITH_HAXE, [test "$have_haxe" = "yes"])
+
+
AX_THRIFT_LIB(d, [D], yes)
if test "$with_d" = "yes"; then
AX_DMD
@@ -657,6 +668,7 @@ AC_CONFIG_FILES([
test/cpp/Makefile
test/erl/Makefile
test/go/Makefile
+ test/haxe/Makefile
test/hs/Makefile
test/php/Makefile
test/perl/Makefile
@@ -668,6 +680,7 @@ AC_CONFIG_FILES([
tutorial/c_glib/Makefile
tutorial/cpp/Makefile
tutorial/go/Makefile
+ tutorial/haxe/Makefile
tutorial/hs/Makefile
tutorial/java/Makefile
tutorial/js/Makefile
@@ -690,6 +703,7 @@ echo "Building Java Library ........ : $have_java"
echo "Building C# Library .......... : $have_csharp"
echo "Building Python Library ...... : $have_python"
echo "Building Ruby Library ........ : $have_ruby"
+echo "Building Haxe Library ........ : $have_haxe"
echo "Building Haskell Library ..... : $have_haskell"
echo "Building Perl Library ........ : $have_perl"
echo "Building PHP Library ......... : $have_php"
@@ -739,6 +753,11 @@ if test "$have_haskell" = "yes" ; then
echo " Using Haskell ............. : $RUNHASKELL"
echo " Using Cabal ............... : $CABAL"
fi
+if test "$have_haxe" = "yes" ; then
+ echo
+ echo "Haxe Library:"
+ echo " Using Haxe ................ : $HAXE"
+fi
if test "$have_perl" = "yes" ; then
echo
echo "Perl Library:"
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/README.md
----------------------------------------------------------------------
diff --git a/lib/haxe/README.md b/lib/haxe/README.md
new file mode 100644
index 0000000..3335b43
--- /dev/null
+++ b/lib/haxe/README.md
@@ -0,0 +1,75 @@
+Thrift Haxe Software Library
+
+License
+=======
+
+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.
+
+Using Thrift with Haxe
+========================
+
+Thrift requires Haxe 3.1.3.
+
+To get started, visit the /tutorial/haxe and /test/haxe dirs for examples.
+If you are using HIDE, you'll find the HIDE project files in these folders.
+
+
+Current status
+========================
+- tested with Haxe C++ target
+- transports: socket
+- protocols: binary, JSON
+- tutorial client and server available
+- cross-test client and server available
+
+
+Further developments
+========================
+- add HTTP transport, update tutorial and tests accordingly
+- improve to work with C#, Java and JavaScript Haxe/OpenFL targets
+- improve to work with more (ideally all) Haxe/OpenFL targets
+
+
+Dependencies
+========================
+
+Haxe Targets:
+Depending on the desired targets, you may have to install the appropriate HaxeLibs
+after installing Haxe itself. For example, if you plan to target C#, Java and C++,
+enter the following commands after installing Haxe:
+
+ haxelib install hxcpp
+ haxelib install hxjava
+ haxelib install hxcs
+
+For other targets, please consult the Haxe documentation whether or not any additional
+target libraries need to be installed and how to achieve this.
+
+Haxe Libraries:
+- None (at the time of writing)
+
+
+Known restrictions
+========================
+
+Although designed with maximum portability in mind, for technical reasons some platforms
+may only support parts of the library, or not be compatible at all.
+
+Javascript:
+- tutorial fails to build because of unsupported Sys.args
+
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/AbstractMethodError.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/AbstractMethodError.hx b/lib/haxe/src/org/apache/thrift/AbstractMethodError.hx
new file mode 100644
index 0000000..9fb9bbb
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/AbstractMethodError.hx
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+#if flash
+import flash.errors.IllegalOperationError;
+#else
+import org.apache.thrift.TException;
+#end
+
+class AbstractMethodError
+#if flash
+extends IllegalOperationError
+#else
+extends TException
+#end
+{
+
+ public function new(message : String="") {
+ super("Attempt to call an abstract method");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/ArgumentError.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/ArgumentError.hx b/lib/haxe/src/org/apache/thrift/ArgumentError.hx
new file mode 100644
index 0000000..8a5df6f
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/ArgumentError.hx
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+#if ! flash
+// predefined for flash only
+class ArgumentError extends TException {
+ public function new(msg : String = "") {
+ super(msg);
+ }
+}
+#end
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/Limits.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/Limits.hx b/lib/haxe/src/org/apache/thrift/Limits.hx
new file mode 100644
index 0000000..7d2aa5d
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/Limits.hx
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+class Limits {
+
+ // Haxe limits are not fixed values, they depend on the target platform
+ // For example, neko limits an int to 31 bits instead of 32. So we detect
+ // the values once during intialisation in order to
+ // (a) get the right values for the current platform, and
+ // (b) prevent us from dependecies to a bunch of defines
+
+ public static var I32_MAX = {
+ var last : Int = 0;
+ var next : Int = 0;
+ for(bit in 0 ... 32) {
+ last = next;
+ next = last | (1 << bit);
+ if(next < 0) {
+ break;
+ }
+ }
+ last; // final value
+ }
+
+ // add whatever you need
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/TApplicationException.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/TApplicationException.hx b/lib/haxe/src/org/apache/thrift/TApplicationException.hx
new file mode 100644
index 0000000..012a802
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/TApplicationException.hx
@@ -0,0 +1,102 @@
+/*
+ * 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 org.apache.thrift.protocol.TField;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.protocol.TProtocolUtil;
+import org.apache.thrift.protocol.TStruct;
+import org.apache.thrift.protocol.TType;
+
+ /**
+ * Application level exception
+ */
+class TApplicationException extends TException {
+
+ private static var TAPPLICATION_EXCEPTION_STRUCT = { new TStruct("TApplicationException"); };
+ private static var MESSAGE_FIELD = { new TField("message", TType.STRING, 1); };
+ private static var TYPE_FIELD = { new TField("type", TType.I32, 2); };
+
+ public static inline var UNKNOWN : Int = 0;
+ public static inline var UNKNOWN_METHOD : Int = 1;
+ public static inline var INVALID_MESSAGE_TYPE : Int = 2;
+ public static inline var WRONG_METHOD_NAME : Int = 3;
+ public static inline var BAD_SEQUENCE_ID : Int = 4;
+ public static inline var MISSING_RESULT : Int = 5;
+ public static inline var INTERNAL_ERROR : Int = 6;
+ public static inline var PROTOCOL_ERROR : Int = 7;
+ public static inline var INVALID_TRANSFORM : Int = 8;
+ public static inline var INVALID_PROTOCOL : Int = 9;
+ public static inline var UNSUPPORTED_CLIENT_TYPE : Int = 10;
+
+ public function new(type : Int = UNKNOWN, message : String = "") {
+ super(message, type);
+ }
+
+ public static function read(iprot:TProtocol) : TApplicationException {
+ var field:TField;
+ iprot.readStructBegin();
+
+ var message : String = null;
+ var type : Int = UNKNOWN;
+
+ while (true) {
+ field = iprot.readFieldBegin();
+ if (field.type == TType.STOP) {
+ break;
+ }
+ switch (field.id) {
+ case 1:
+ if (field.type == TType.STRING) {
+ message = iprot.readString();
+ }
+ else {
+ TProtocolUtil.skip(iprot, field.type);
+ }
+ case 2:
+ if (field.type == TType.I32) {
+ type = iprot.readI32();
+ }
+ else {
+ TProtocolUtil.skip(iprot, field.type);
+ }
+ default:
+ TProtocolUtil.skip(iprot, field.type);
+ }
+ iprot.readFieldEnd();
+ }
+ iprot.readStructEnd();
+ return new TApplicationException(type, message);
+ }
+
+ public function write(oprot:TProtocol) : Void {
+ oprot.writeStructBegin(TAPPLICATION_EXCEPTION_STRUCT);
+ if (errorMsg != null) {
+ oprot.writeFieldBegin(MESSAGE_FIELD);
+ oprot.writeString(errorMsg);
+ oprot.writeFieldEnd();
+ }
+ oprot.writeFieldBegin(TYPE_FIELD);
+ oprot.writeI32(errorID);
+ oprot.writeFieldEnd();
+ oprot.writeFieldStop();
+ oprot.writeStructEnd();
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/TBase.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/TBase.hx b/lib/haxe/src/org/apache/thrift/TBase.hx
new file mode 100644
index 0000000..5d8bfc1
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/TBase.hx
@@ -0,0 +1,66 @@
+/*
+ * 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 org.apache.thrift.protocol.TProtocol;
+
+ /**
+ * Generic base interface for generated Thrift objects.
+ *
+ */
+interface TBase {
+
+ /**
+ * Reads the TObject from the given input protocol.
+ *
+ * @param iprot Input protocol
+ */
+ function read(iprot:TProtocol) : Void;
+
+ /**
+ * Writes the objects out to the protocol
+ *
+ * @param oprot Output protocol
+ */
+ function write(oprot:TProtocol) : Void;
+
+ /**
+ * Check if a field is currently set or unset.
+ *
+ * @param fieldId The field's id tag as found in the IDL.
+ */
+ function isSet(fieldId : Int) : Bool;
+
+ /**
+ * Get a field's value by id. Primitive types will be wrapped in the
+ * appropriate "boxed" types.
+ *
+ * @param fieldId The field's id tag as found in the IDL.
+ */
+ function getFieldValue(fieldId : Int) : Dynamic;
+
+ /**
+ * Set a field's value by id. Primitive types must be "boxed" in the
+ * appropriate object wrapper type.
+ *
+ * @param fieldId The field's id tag as found in the IDL.
+ */
+ function setFieldValue(fieldId : Int, value : Dynamic) : Void;
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/TException.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/TException.hx b/lib/haxe/src/org/apache/thrift/TException.hx
new file mode 100644
index 0000000..ed630ba
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/TException.hx
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+class TException {
+
+ @:isVar
+ public var errorID(default,null) : Int;
+ @:isVar
+ public var errorMsg(default,null) : String;
+
+
+ public function new(msg : String = "", id : Int = 0) {
+ errorID = id;
+ errorMsg = msg;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/TFieldRequirementType.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/TFieldRequirementType.hx b/lib/haxe/src/org/apache/thrift/TFieldRequirementType.hx
new file mode 100644
index 0000000..70f698f
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/TFieldRequirementType.hx
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+ /**
+ * Requirement type constants.
+ *
+ */
+class TFieldRequirementType {
+ public static inline var REQUIRED : Int = 1;
+ public static inline var OPTIONAL : Int = 2;
+ public static inline var DEFAULT : Int = 3;
+
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/TProcessor.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/TProcessor.hx b/lib/haxe/src/org/apache/thrift/TProcessor.hx
new file mode 100644
index 0000000..78ce5a7
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/TProcessor.hx
@@ -0,0 +1,30 @@
+/*
+ * 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 org.apache.thrift.protocol.TProtocol;
+
+/**
+ * A processor is a generic object which operates upon an input stream and
+ * writes to some output stream.
+ */
+interface TProcessor {
+ function process(input:TProtocol, output:TProtocol) : Bool;
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/helper/Int64Map.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/helper/Int64Map.hx b/lib/haxe/src/org/apache/thrift/helper/Int64Map.hx
new file mode 100644
index 0000000..8d9e4e1
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/helper/Int64Map.hx
@@ -0,0 +1,265 @@
+/*
+ * 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.helper;
+
+import Map;
+import haxe.Int64;
+import haxe.ds.IntMap;
+
+
+// Int64Map allows mapping of Int64 keys to arbitrary values.
+// ObjectMap<> cannot be used, since we want to compare by value, not address
+
+class Int64Map<T> implements IMap< Int64, T> {
+
+ private var SubMaps : IntMap< IntMap< T>>; // Hi -> Lo -> Value
+
+ public function new() : Void {
+ SubMaps = new IntMap< IntMap< T>>();
+ };
+
+ private function GetSubMap( hi : haxe.Int32, canCreate : Bool) : IntMap< T> {
+ if( SubMaps.exists(hi)) {
+ return SubMaps.get(hi);
+ }
+
+ if( ! canCreate) {
+ return null;
+ }
+
+ var lomap = new IntMap< T>();
+ SubMaps.set( hi, lomap);
+ return lomap;
+ }
+
+ /**
+ Maps `key` to `value`.
+ If `key` already has a mapping, the previous value disappears.
+ If `key` is null, the result is unspecified.
+ **/
+ public function set( key : Int64, value : T ) : Void {
+ if( key == null) {
+ return;
+ }
+
+ var lomap = GetSubMap( Int64.getHigh(key), true);
+ lomap.set( Int64.getLow(key), value);
+ }
+
+
+ /**
+ Returns the current mapping of `key`.
+ If no such mapping exists, null is returned.
+ If `key` is null, the result is unspecified.
+
+ Note that a check like `map.get(key) == null` can hold for two reasons:
+
+ 1. the map has no mapping for `key`
+ 2. the map has a mapping with a value of `null`
+
+ If it is important to distinguish these cases, `exists()` should be
+ used.
+
+ **/
+ public function get( key : Int64) : Null<T> {
+ if( key == null) {
+ return null;
+ }
+
+ var lomap = GetSubMap( Int64.getHigh(key), false);
+ if( lomap == null) {
+ return null;
+ }
+
+ return lomap.get( Int64.getLow(key));
+ }
+
+ /**
+ Returns true if `key` has a mapping, false otherwise.
+ If `key` is null, the result is unspecified.
+ **/
+ public function exists( key : Int64) : Bool {
+ if( key == null) {
+ return false;
+ }
+
+ var lomap = GetSubMap( Int64.getHigh(key), false);
+ if( lomap == null) {
+ return false;
+ }
+
+ return lomap.exists( Int64.getLow(key));
+ }
+
+ /**
+ Removes the mapping of `key` and returns true if such a mapping existed,
+ false otherwise. If `key` is null, the result is unspecified.
+ **/
+ public function remove( key : Int64) : Bool {
+ if( key == null) {
+ return false;
+ }
+
+ var lomap = GetSubMap( Int64.getHigh(key), false);
+ if( lomap == null) {
+ return false;
+ }
+
+ return lomap.remove( Int64.getLow(key));
+ }
+
+
+ /**
+ Returns an Iterator over the keys of `this` Map.
+ The order of keys is undefined.
+ **/
+ public function keys() : Iterator<Int64> {
+ return new Int64KeyIterator<T>(SubMaps);
+ }
+
+ /**
+ Returns an Iterator over the values of `this` Map.
+ The order of values is undefined.
+ **/
+ public function iterator() : Iterator<T> {
+ return new Int64ValueIterator<T>(SubMaps);
+ }
+
+ /**
+ Returns a String representation of `this` Map.
+ The exact representation depends on the platform and key-type.
+ **/
+ public function toString() : String {
+ var result : String = "{";
+
+ var first = true;
+ for( key in this.keys()) {
+ if( first) {
+ first = false;
+ } else {
+ result += ", ";
+ }
+
+ var value = this.get(key);
+ result += Int64.toStr(key) + ' => $value';
+ }
+
+ return result + "}";
+ }
+
+}
+
+
+// internal helper class for Int64Map<T>
+// all class with matching methods can be used as iterator (duck typing)
+private class Int64MapIteratorBase<T> {
+
+ private var SubMaps : IntMap< IntMap< T>>; // Hi -> Lo -> Value
+
+ private var HiIterator : Iterator< Int> = null;
+ private var LoIterator : Iterator< Int> = null;
+ private var CurrentHi : Int = 0;
+
+ public function new( data : IntMap< IntMap< T>>) : Void {
+ SubMaps = data;
+ HiIterator = SubMaps.keys();
+ LoIterator = null;
+ CurrentHi = 0;
+ };
+
+ /**
+ Returns false if the iteration is complete, true otherwise.
+
+ Usually iteration is considered to be complete if all elements of the
+ underlying data structure were handled through calls to next(). However,
+ in custom iterators any logic may be used to determine the completion
+ state.
+ **/
+ public function hasNext() : Bool {
+
+ if( (LoIterator != null) && LoIterator.hasNext()) {
+ return true;
+ }
+
+ while( (HiIterator != null) && HiIterator.hasNext()) {
+ CurrentHi = HiIterator.next();
+ LoIterator = SubMaps.get(CurrentHi).keys();
+ if( (LoIterator != null) && LoIterator.hasNext()) {
+ return true;
+ }
+ }
+
+ HiIterator = null;
+ LoIterator = null;
+ return false;
+ }
+
+}
+
+
+// internal helper class for Int64Map<T>
+// all class with matching methods can be used as iterator (duck typing)
+private class Int64KeyIterator<T>extends Int64MapIteratorBase<T> {
+
+ public function new( data : IntMap< IntMap< T>>) : Void {
+ super(data);
+ };
+
+ /**
+ Returns the current item of the Iterator and advances to the next one.
+
+ This method is not required to check hasNext() first. A call to this
+ method while hasNext() is false yields unspecified behavior.
+ **/
+ public function next() : Int64 {
+ if( hasNext()) {
+ return Int64.make( CurrentHi, LoIterator.next());
+ } else {
+ throw "no more elements";
+ }
+ }
+}
+
+
+// internal helper class for Int64Map<T>
+// all class with matching methods can be used as iterator (duck typing)
+private class Int64ValueIterator<T> extends Int64MapIteratorBase<T> {
+
+ public function new( data : IntMap< IntMap< T>>) : Void {
+ super(data);
+ };
+
+ /**
+ Returns the current item of the Iterator and advances to the next one.
+
+ This method is not required to check hasNext() first. A call to this
+ method while hasNext() is false yields unspecified behavior.
+ **/
+ public function next() : T {
+ if( hasNext()) {
+ return SubMaps.get(CurrentHi).get(LoIterator.next());
+ } else {
+ throw "no more elements";
+ }
+ }
+}
+
+
+// EOF
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/helper/IntSet.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/helper/IntSet.hx b/lib/haxe/src/org/apache/thrift/helper/IntSet.hx
new file mode 100644
index 0000000..214f3bd
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/helper/IntSet.hx
@@ -0,0 +1,96 @@
+/*
+ * 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.helper;
+
+import Map;
+
+
+class IntSet {
+
+ private var _elements = new haxe.ds.IntMap<Int>();
+ private var _size : Int = 0;
+ public var size(get,never) : Int;
+
+ public function new( values : Array<Int> = null) {
+ if ( values != null) {
+ for ( value in values) {
+ add(value);
+ }
+ }
+ }
+
+ public function iterator():Iterator<Int> {
+ return _elements.keys();
+ }
+
+ public function traceAll() : Void {
+ trace('$_size entries');
+ for(entry in this) {
+ var yes = contains(entry);
+ trace('- $entry, contains() = $yes');
+ }
+ }
+
+ public function add(o : Int) : Bool {
+ if( _elements.exists(o)) {
+ return false;
+ }
+ _size++;
+ _elements.set(o,_size);
+ return true;
+ }
+
+ public function clear() : Void {
+ while( _size > 0) {
+ remove( _elements.keys().next());
+ }
+ }
+
+ public function contains(o : Int) : Bool {
+ return _elements.exists(o);
+ }
+
+ public function isEmpty() : Bool {
+ return _size == 0;
+ }
+
+ public function remove(o : Int) : Bool {
+ if (contains(o)) {
+ _elements.remove(o);
+ _size--;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public function toArray() : Array<Int> {
+ var ret : Array<Int> = new Array<Int>();
+ for (key in _elements.keys()) {
+ ret.push(key);
+ }
+ return ret;
+ }
+
+ public function get_size() : Int {
+ return _size;
+ }
+}
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/helper/ObjectSet.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/helper/ObjectSet.hx b/lib/haxe/src/org/apache/thrift/helper/ObjectSet.hx
new file mode 100644
index 0000000..c590c75
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/helper/ObjectSet.hx
@@ -0,0 +1,96 @@
+/*
+ * 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.helper;
+
+import Map;
+
+
+class ObjectSet<K> {
+
+ private var _elements = new haxe.ds.ObjectMap<K,Int>();
+ private var _size : Int = 0;
+ public var size(get,never) : Int;
+
+ public function new( values : Array<K> = null) {
+ if ( values != null) {
+ for ( value in values) {
+ add(value);
+ }
+ }
+ }
+
+ public function iterator():Iterator<K> {
+ return _elements.keys();
+ }
+
+ public function traceAll() : Void {
+ trace('$_size entries');
+ for(entry in this) {
+ var yes = contains(entry);
+ trace('- $entry, contains() = $yes');
+ }
+ }
+
+ public function add(o : K) : Bool {
+ if( _elements.exists(o)) {
+ return false;
+ }
+ _size++;
+ _elements.set(o,_size);
+ return true;
+ }
+
+ public function clear() : Void {
+ while( _size > 0) {
+ remove( _elements.keys().next());
+ }
+ }
+
+ public function contains(o : K) : Bool {
+ return _elements.exists(o);
+ }
+
+ public function isEmpty() : Bool {
+ return _size == 0;
+ }
+
+ public function remove(o : K) : Bool {
+ if (contains(o)) {
+ _elements.remove(o);
+ _size--;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public function toArray() : Array<K> {
+ var ret : Array<K> = new Array<K>();
+ for (key in _elements.keys()) {
+ ret.push(key);
+ }
+ return ret;
+ }
+
+ public function get_size() : Int {
+ return _size;
+ }
+}
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/helper/StringSet.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/helper/StringSet.hx b/lib/haxe/src/org/apache/thrift/helper/StringSet.hx
new file mode 100644
index 0000000..ee772c7
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/helper/StringSet.hx
@@ -0,0 +1,96 @@
+/*
+ * 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.helper;
+
+import Map;
+
+
+class StringSet {
+
+ private var _elements = new haxe.ds.StringMap<Int>();
+ private var _size : Int = 0;
+ public var size(get,never) : Int;
+
+ public function new( values : Array<String> = null) {
+ if ( values != null) {
+ for ( value in values) {
+ add(value);
+ }
+ }
+ }
+
+ public function iterator():Iterator<String> {
+ return _elements.keys();
+ }
+
+ public function traceAll() : Void {
+ trace('$_size entries');
+ for(entry in this) {
+ var yes = contains(entry);
+ trace('- $entry, contains() = $yes');
+ }
+ }
+
+ public function add(o : String) : Bool {
+ if( _elements.exists(o)) {
+ return false;
+ }
+ _size++;
+ _elements.set(o,_size);
+ return true;
+ }
+
+ public function clear() : Void {
+ while( _size > 0) {
+ remove( _elements.keys().next());
+ }
+ }
+
+ public function contains(o : String) : Bool {
+ return _elements.exists(o);
+ }
+
+ public function isEmpty() : Bool {
+ return _size == 0;
+ }
+
+ public function remove(o : String) : Bool {
+ if (contains(o)) {
+ _elements.remove(o);
+ _size--;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public function toArray() : Array<String> {
+ var ret : Array<String> = new Array<String>();
+ for (key in _elements.keys()) {
+ ret.push(key);
+ }
+ return ret;
+ }
+
+ public function get_size() : String {
+ return _size;
+ }
+}
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/meta_data/FieldMetaData.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/meta_data/FieldMetaData.hx b/lib/haxe/src/org/apache/thrift/meta_data/FieldMetaData.hx
new file mode 100644
index 0000000..147eed9
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/meta_data/FieldMetaData.hx
@@ -0,0 +1,56 @@
+/*
+ * 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.meta_data;
+
+import flash.utils.Dictionary;
+
+/**
+* This class is used to store meta data about thrift fields. Every field in a
+* a struct should have a corresponding instance of this class describing it.
+*
+*/
+class FieldMetaData {
+
+ public var fieldName : String;
+ public var requirementType : Int;
+ public var valueMetaData:FieldValueMetaData;
+
+ private static var structMap:Dictionary = new Dictionary();
+
+ public function FieldMetaData(name : String, req : Int, vMetaData:FieldValueMetaData) {
+ this.fieldName = name;
+ this.requirementType = req;
+ this.valueMetaData = vMetaData;
+ }
+
+ public static function addStructMetaDataMap(sClass:Class, map:Dictionary) : Void{
+ structMap[sClass] = map;
+ }
+
+ /**
+ * Returns a map with metadata (i.e. instances of FieldMetaData) that
+ * describe the fields of the given class.
+ *
+ * @param sClass The TBase class for which the metadata map is requested
+ */
+ public static function getStructMetaDataMap(sClass:Class):Dictionary {
+ return structMap[sClass];
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/meta_data/FieldValueMetaData.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/meta_data/FieldValueMetaData.hx b/lib/haxe/src/org/apache/thrift/meta_data/FieldValueMetaData.hx
new file mode 100644
index 0000000..06c7f48
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/meta_data/FieldValueMetaData.hx
@@ -0,0 +1,43 @@
+/*
+ * 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.meta_data;
+
+import org.apache.thrift.protocol.TType;
+
+/**
+ * FieldValueMetaData and collection of subclasses to store metadata about
+ * the value(s) of a field
+ */
+class FieldValueMetaData {
+
+ public var type : Int;
+
+ public function FieldValueMetaData(type : Int) {
+ this.type = type;
+ }
+
+ public function isStruct() : Bool {
+ return type == TType.STRUCT;
+ }
+
+ public function isContainer() : Bool {
+ return type == TType.LIST || type == TType.MAP || type == TType.SET;
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/meta_data/ListMetaData.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/meta_data/ListMetaData.hx b/lib/haxe/src/org/apache/thrift/meta_data/ListMetaData.hx
new file mode 100644
index 0000000..36bb2d1
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/meta_data/ListMetaData.hx
@@ -0,0 +1,30 @@
+/*
+ * 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.meta_data;
+
+class ListMetaData extends FieldValueMetaData {
+
+ public var elemMetaData:FieldValueMetaData;
+
+ public function ListMetaData(type : Int, eMetaData:FieldValueMetaData) {
+ super(type);
+ this.elemMetaData = eMetaData;
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/meta_data/MapMetaData.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/meta_data/MapMetaData.hx b/lib/haxe/src/org/apache/thrift/meta_data/MapMetaData.hx
new file mode 100644
index 0000000..bf0502a
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/meta_data/MapMetaData.hx
@@ -0,0 +1,32 @@
+/*
+ * 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.meta_data;
+
+class MapMetaData extends FieldValueMetaData {
+
+ public var keyMetaData:FieldValueMetaData;
+ public var valueMetaData:FieldValueMetaData;
+
+ public function MapMetaData(type : Int, kMetaData:FieldValueMetaData, vMetaData:FieldValueMetaData) {
+ super(type);
+ this.keyMetaData = kMetaData;
+ this.valueMetaData = vMetaData;
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/meta_data/SetMetaData.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/meta_data/SetMetaData.hx b/lib/haxe/src/org/apache/thrift/meta_data/SetMetaData.hx
new file mode 100644
index 0000000..0ee6c93
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/meta_data/SetMetaData.hx
@@ -0,0 +1,30 @@
+/*
+ * 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.meta_data;
+
+class SetMetaData extends FieldValueMetaData {
+
+ public var elemMetaData:FieldValueMetaData;
+
+ public function SetMetaData(type : Int, eMetaData:FieldValueMetaData) {
+ super(type);
+ this.elemMetaData = eMetaData;
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/meta_data/StructMetaData.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/meta_data/StructMetaData.hx b/lib/haxe/src/org/apache/thrift/meta_data/StructMetaData.hx
new file mode 100644
index 0000000..bbf11e7
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/meta_data/StructMetaData.hx
@@ -0,0 +1,30 @@
+/*
+ * 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.meta_data;
+
+class StructMetaData extends FieldValueMetaData {
+
+ public var structClass:Class;
+
+ public function StructMetaData(type : Int, sClass:Class) {
+ super(type);
+ this.structClass = sClass;
+ }
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocol.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocol.hx b/lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocol.hx
new file mode 100644
index 0000000..9693b35
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocol.hx
@@ -0,0 +1,296 @@
+/*
+ * 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.protocol;
+
+import haxe.io.Bytes;
+import haxe.io.BytesInput;
+import haxe.io.BytesOutput;
+import haxe.io.BytesBuffer;
+import haxe.Int64;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.transport.TTransport;
+
+/**
+* Binary protocol implementation for thrift.
+*/
+class TBinaryProtocol implements TProtocol {
+
+ private static var ANONYMOUS_STRUCT:TStruct = new TStruct();
+
+ private static inline var VERSION_MASK : haxe.Int32 = 0xffff0000;
+ private static inline var VERSION_1 : haxe.Int32 = 0x80010000;
+
+ private var strictRead_ : Bool = false;
+ private var strictWrite_ : Bool = true;
+ private var trans_ : TTransport;
+
+ /**
+ * Constructor
+ */
+ public function new(trans:TTransport, strictRead : Bool=false, strictWrite : Bool=true) {
+ trans_ = trans;
+ strictRead_ = strictRead;
+ strictWrite_ = strictWrite;
+ }
+
+ public function getTransport():TTransport {
+ return trans_;
+ }
+
+ public function writeMessageBegin(message:TMessage) : Void {
+ if (strictWrite_) {
+ var version : Int = VERSION_1 | message.type;
+ writeI32(version);
+ writeString(message.name);
+ writeI32(message.seqid);
+ } else {
+ writeString(message.name);
+ writeByte(message.type);
+ writeI32(message.seqid);
+ }
+ }
+
+ public function writeMessageEnd() : Void {}
+
+ public function writeStructBegin(struct:TStruct) : Void {}
+
+ public function writeStructEnd() : Void {}
+
+ public function writeFieldBegin(field:TField) : Void {
+ writeByte(field.type);
+ writeI16(field.id);
+ }
+
+ public function writeFieldEnd() : Void {}
+
+ public function writeFieldStop() : Void {
+ writeByte(TType.STOP);
+ }
+
+ public function writeMapBegin(map:TMap) : Void {
+ writeByte(map.keyType);
+ writeByte(map.valueType);
+ writeI32(map.size);
+ }
+
+ public function writeMapEnd() : Void {}
+
+ public function writeListBegin(list:TList) : Void {
+ writeByte(list.elemType);
+ writeI32(list.size);
+ }
+
+ public function writeListEnd() : Void {}
+
+ public function writeSetBegin(set:TSet) : Void {
+ writeByte(set.elemType);
+ writeI32(set.size);
+ }
+
+ public function writeSetEnd() : Void {}
+
+ public function writeBool(b : Bool) : Void {
+ writeByte(b ? 1 : 0);
+ }
+
+
+ public function writeByte(b : Int) : Void {
+ var out = new BytesOutput();
+ out.bigEndian = true;
+ out.writeByte(b);
+ trans_.write(out.getBytes(), 0, 1);
+ }
+
+ public function writeI16(i16 : Int) : Void {
+ var out = new BytesOutput();
+ out.bigEndian = true;
+ out.writeInt16(i16);
+ trans_.write(out.getBytes(), 0, 2);
+ }
+
+ public function writeI32(i32 : Int) : Void {
+ var out = new BytesOutput();
+ out.bigEndian = true;
+ out.writeInt32(i32);
+ trans_.write(out.getBytes(), 0, 4);
+ }
+
+ public function writeI64(i64 : haxe.Int64) : Void {
+ var out = new BytesOutput();
+ out.bigEndian = true;
+ var hi = Int64.getHigh(i64);
+ var lo = Int64.getLow(i64);
+ out.writeInt32(hi);
+ out.writeInt32(lo);
+ trans_.write(out.getBytes(), 0, 8);
+ }
+
+ public function writeDouble(dub:Float) : Void {
+ var out = new BytesOutput();
+ out.bigEndian = true;
+ out.writeDouble(dub);
+ trans_.write(out.getBytes(), 0, 8);
+ }
+
+ public function writeString(str : String) : Void {
+ var out = new BytesOutput();
+ out.bigEndian = true;
+ out.writeString(str);
+ var bytes = out.getBytes();
+ writeI32( bytes.length);
+ trans_.write( bytes, 0, bytes.length);
+ }
+
+ public function writeBinary(bin:Bytes) : Void {
+ writeI32(bin.length);
+ trans_.write(bin, 0, bin.length);
+ }
+
+ /**
+ * Reading methods.
+ */
+
+ public function readMessageBegin():TMessage {
+ var size : Int = readI32();
+ if (size < 0) {
+ var version : Int = size & VERSION_MASK;
+ if (version != VERSION_1) {
+ throw new TProtocolException(TProtocolException.BAD_VERSION, "Bad version in readMessageBegin");
+ }
+ return new TMessage(readString(), size & 0x000000ff, readI32());
+ } else {
+ if (strictRead_) {
+ throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?");
+ }
+ return new TMessage(readStringBody(size), readByte(), readI32());
+ }
+ }
+
+ public function readMessageEnd() : Void {}
+
+ public function readStructBegin():TStruct {
+ return ANONYMOUS_STRUCT;
+ }
+
+ public function readStructEnd() : Void {}
+
+ public function readFieldBegin() : TField {
+ var type : Int = readByte();
+ var id : Int = 0;
+ if (type != TType.STOP)
+ {
+ id = readI16();
+ }
+ return new TField("", type, id);
+ }
+
+ public function readFieldEnd() : Void {}
+
+ public function readMapBegin() : TMap {
+ return new TMap(readByte(), readByte(), readI32());
+ }
+
+ public function readMapEnd() : Void {}
+
+ public function readListBegin():TList {
+ return new TList(readByte(), readI32());
+ }
+
+ public function readListEnd() : Void {}
+
+ public function readSetBegin() : TSet {
+ return new TSet(readByte(), readI32());
+ }
+
+ public function readSetEnd() : Void {}
+
+ public function readBool() : Bool {
+ return (readByte() == 1);
+ }
+
+
+ public function readByte() : Int {
+ var buffer = new BytesBuffer();
+ var len = trans_.readAll( buffer, 0, 1);
+ var inp = new BytesInput( buffer.getBytes(), 0, 1);
+ inp.bigEndian = true;
+ return inp.readByte();
+ }
+
+ public function readI16() : Int {
+ var buffer = new BytesBuffer();
+ var len = trans_.readAll( buffer, 0, 2);
+ var inp = new BytesInput( buffer.getBytes(), 0, 2);
+ inp.bigEndian = true;
+ return inp.readInt16();
+ }
+
+ public function readI32() : Int {
+ var buffer = new BytesBuffer();
+ var len = trans_.readAll( buffer, 0, 4);
+ var inp = new BytesInput( buffer.getBytes(), 0, 4);
+ inp.bigEndian = true;
+ return inp.readInt32();
+ }
+
+ public function readI64() : haxe.Int64 {
+ var buffer = new BytesBuffer();
+ var len = trans_.readAll( buffer, 0, 8);
+ var inp = new BytesInput( buffer.getBytes(), 0, 8);
+ inp.bigEndian = true;
+ var hi = inp.readInt32();
+ var lo = inp.readInt32();
+ return Int64.make(hi,lo);
+ }
+
+ public function readDouble():Float {
+ var buffer = new BytesBuffer();
+ var len = trans_.readAll( buffer, 0, 8);
+ var inp = new BytesInput( buffer.getBytes(), 0, 8);
+ inp.bigEndian = true;
+ return inp.readDouble();
+ }
+
+ public function readString() : String {
+ return readStringBody( readI32());
+ }
+
+ public function readStringBody(len : Int) : String {
+ if( len > 0) {
+ var buffer = new BytesBuffer();
+ trans_.readAll( buffer, 0, len);
+ var inp = new BytesInput( buffer.getBytes(), 0, len);
+ inp.bigEndian = true;
+ return inp.readString(len);
+ } else {
+ return "";
+ }
+ }
+
+ public function readBinary() : Bytes {
+ var len : Int = readI32();
+ var buffer = new BytesBuffer();
+ trans_.readAll( buffer, 0, len);
+ return buffer.getBytes();
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocolFactory.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocolFactory.hx b/lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocolFactory.hx
new file mode 100644
index 0000000..0d7c7c5
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocolFactory.hx
@@ -0,0 +1,45 @@
+/*
+ * 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.protocol;
+
+import org.apache.thrift.transport.TTransport;
+
+
+/**
+* Binary Protocol Factory
+*/
+class TBinaryProtocolFactory implements TProtocolFactory {
+
+ private var strictRead_ : Bool = false;
+ private var strictWrite_ : Bool = true;
+
+ public function new( strictRead : Bool = false, strictWrite : Bool = true) {
+ strictRead_ = strictRead;
+ strictWrite_ = strictWrite;
+ }
+
+ public function getProtocol( trans : TTransport) : TProtocol {
+ return new TBinaryProtocol( trans, strictRead_, strictWrite_);
+ }
+}
+
+
+
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/protocol/TField.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/protocol/TField.hx b/lib/haxe/src/org/apache/thrift/protocol/TField.hx
new file mode 100644
index 0000000..20f3fb9
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/protocol/TField.hx
@@ -0,0 +1,43 @@
+/*
+ * 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.protocol;
+
+class TField {
+
+ public var name : String;
+ public var type : Int;
+ public var id : Int;
+
+ public function new(n : String = "", t : Int = 0, i : Int = 0) {
+ name = n;
+ type = t;
+ id = i;
+ }
+
+ public function toString() : String {
+ return '<TField name:"$name" type:"$type" field-id:"$id">';
+ }
+
+ public function equals( otherField : TField) : Bool {
+ return (type == otherField.type)
+ && (id == otherField.id);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx b/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
new file mode 100644
index 0000000..edd5e12
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
@@ -0,0 +1,1074 @@
+/**
+ * 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.protocol;
+
+import haxe.io.Bytes;
+import haxe.io.BytesInput;
+import haxe.io.BytesOutput;
+import haxe.io.BytesBuffer;
+import haxe.ds.GenericStack;
+import haxe.Utf8;
+import haxe.crypto.Base64;
+import haxe.Int64;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TMessage;
+import org.apache.thrift.protocol.TField;
+import org.apache.thrift.protocol.TMap;
+import org.apache.thrift.protocol.TSet;
+import org.apache.thrift.protocol.TList;
+import org.apache.thrift.transport.TTransport;
+
+
+
+/* JSON protocol implementation for thrift.
+* This is a full-featured protocol supporting Write and Read.
+*
+* Please see the C++ class header for a detailed description of the wire format.
+*
+* Adapted from the Java version.
+*/
+class TJSONProtocol implements TProtocol {
+
+ public var trans(default,null) : TTransport;
+
+ // Stack of nested contexts that we may be in
+ private var contextStack : GenericStack<JSONBaseContext> = new GenericStack<JSONBaseContext>();
+
+ // Current context that we are in
+ private var context : JSONBaseContext;
+
+ // Reader that manages a 1-byte buffer
+ private var reader : LookaheadReader;
+
+
+ // TJSONProtocol Constructor
+ public function new( trans : TTransport)
+ {
+ this.trans = trans;
+ this.context = new JSONBaseContext(this);
+ this.reader = new LookaheadReader(this);
+ }
+
+ public function getTransport() : TTransport {
+ return trans;
+ }
+
+ public function writeMessageBegin(message:TMessage) : Void {
+ WriteJSONArrayStart();
+ WriteJSONInteger( JSONConstants.VERSION);
+ WriteJSONString( Utf8Encode(message.name));
+ WriteJSONInteger( message.type);
+ WriteJSONInteger( message.seqid);
+ }
+
+ public function writeMessageEnd() : Void {
+ WriteJSONArrayEnd();
+ }
+
+ public function writeStructBegin(struct:TStruct) : Void {
+ WriteJSONObjectStart();
+ }
+
+ public function writeStructEnd() : Void {
+ WriteJSONObjectEnd();
+ }
+
+ public function writeFieldBegin(field:TField) : Void {
+ WriteJSONInteger( field.id );
+ WriteJSONObjectStart();
+ WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( field.type)));
+ }
+
+ public function writeFieldEnd() : Void {
+ WriteJSONObjectEnd();
+ }
+
+ public function writeFieldStop() : Void { }
+
+ public function writeMapBegin(map:TMap) : Void {
+ WriteJSONArrayStart();
+ WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( map.keyType)));
+ WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( map.valueType)));
+ WriteJSONInteger( map.size);
+ WriteJSONObjectStart();
+ }
+
+ public function writeMapEnd() : Void {
+ WriteJSONObjectEnd();
+ WriteJSONArrayEnd();
+ }
+
+ public function writeListBegin(list:TList) : Void {
+ WriteJSONArrayStart();
+ WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( list.elemType )));
+ WriteJSONInteger( list.size);
+ }
+
+ public function writeListEnd() : Void {
+ WriteJSONArrayEnd();
+ }
+
+ public function writeSetBegin(set:TSet) : Void {
+ WriteJSONArrayStart();
+ WriteJSONString( Utf8Encode( JSONConstants.GetTypeNameForTypeID( set.elemType)));
+ WriteJSONInteger( set.size);
+ }
+
+ public function writeSetEnd() : Void {
+ WriteJSONArrayEnd();
+ }
+
+ public function writeBool(b : Bool) : Void {
+ if( b)
+ WriteJSONInteger( 1);
+ else
+ WriteJSONInteger( 0);
+ }
+
+ public function writeByte(b : Int) : Void {
+ WriteJSONInteger( b);
+ }
+
+ public function writeI16(i16 : Int) : Void {
+ WriteJSONInteger( i16);
+ }
+
+ public function writeI32(i32 : Int) : Void {
+ WriteJSONInteger( i32);
+ }
+
+ public function writeI64(i64 : haxe.Int64) : Void {
+ WriteJSONInt64( i64);
+ }
+
+ public function writeDouble(dub:Float) : Void {
+ WriteJSONDouble(dub);
+ }
+
+ public function writeString(str : String) : Void {
+ WriteJSONString( Utf8Encode(str));
+ }
+
+ public function writeBinary(bin:Bytes) : Void {
+ WriteJSONBase64(bin);
+ }
+
+ public function readMessageBegin():TMessage {
+ var message : TMessage = new TMessage();
+ ReadJSONArrayStart();
+ if (ReadJSONInteger() != JSONConstants.VERSION)
+ {
+ throw new TProtocolException(TProtocolException.BAD_VERSION,
+ "Message contained bad version.");
+ }
+
+ var buf = ReadJSONString(false);
+ message.name = Utf8Decode(buf);
+ message.type = ReadJSONInteger();
+ message.seqid = ReadJSONInteger();
+ return message;
+ }
+
+ public function readMessageEnd() : Void {
+ ReadJSONArrayEnd();
+ }
+
+ public function readStructBegin():TStruct {
+ ReadJSONObjectStart();
+ return new TStruct();
+ }
+
+ public function readStructEnd() : Void {
+ ReadJSONObjectEnd();
+ }
+
+ public function readFieldBegin() : TField {
+ var field : TField = new TField();
+ var ch = reader.Peek();
+ if (StringFromBytes(ch) == JSONConstants.RBRACE)
+ {
+ field.type = TType.STOP;
+ }
+ else
+ {
+ field.id = ReadJSONInteger();
+ ReadJSONObjectStart();
+ field.type = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+ }
+ return field;
+ }
+
+ public function readFieldEnd() : Void {
+ ReadJSONObjectEnd();
+ }
+
+ public function readMapBegin() : TMap {
+ ReadJSONArrayStart();
+ var KeyType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+ var ValueType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+ var Count : Int = ReadJSONInteger();
+ ReadJSONObjectStart();
+
+ var map = new TMap( KeyType, ValueType, Count);
+ return map;
+ }
+
+ public function readMapEnd() : Void {
+ ReadJSONObjectEnd();
+ ReadJSONArrayEnd();
+ }
+
+ public function readListBegin():TList {
+ ReadJSONArrayStart();
+ var ElementType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+ var Count : Int = ReadJSONInteger();
+
+ var list = new TList( ElementType, Count);
+ return list;
+ }
+
+ public function readListEnd() : Void {
+ ReadJSONArrayEnd();
+ }
+
+ public function readSetBegin() : TSet {
+ ReadJSONArrayStart();
+ var ElementType = JSONConstants.GetTypeIDForTypeName( Utf8Decode( ReadJSONString(false)));
+ var Count : Int = ReadJSONInteger();
+
+ var set = new TSet( ElementType, Count);
+ return set;
+ }
+
+ public function readSetEnd() : Void {
+ ReadJSONArrayEnd();
+ }
+
+ public function readBool() : Bool {
+ return (ReadJSONInteger() == 0 ? false : true);
+ }
+
+ public function readByte() : Int {
+ return ReadJSONInteger();
+ }
+
+ public function readI16() : Int {
+ return ReadJSONInteger();
+ }
+
+ public function readI32() : Int {
+ return ReadJSONInteger();
+ }
+
+ public function readI64() : haxe.Int64 {
+ return ReadJSONInt64();
+ }
+
+ public function readDouble():Float {
+ return ReadJSONDouble();
+ }
+
+ public function readString() : String {
+ var buf = ReadJSONString(false);
+ return Utf8Decode(buf);
+ }
+
+ public function readBinary() : Bytes {
+ return ReadJSONBase64();
+ }
+
+ // Push a new JSON context onto the stack.
+ private function PushContext(c : JSONBaseContext) : Void {
+ contextStack.add(context);
+ context = c;
+ }
+
+ // Pop the last JSON context off the stack
+ private function PopContext() : Void {
+ context = contextStack.pop();
+ }
+
+
+ // Write the bytes in array buf as a JSON characters, escaping as needed
+ private function WriteJSONString( b : Bytes) : Void {
+ context.Write();
+
+ var tmp = BytesFromString( JSONConstants.QUOTE);
+ trans.write( tmp, 0, tmp.length);
+
+ for (i in 0 ... b.length) {
+ var value = b.get(i);
+
+ if ((value & 0x00FF) >= 0x30)
+ {
+ if (String.fromCharCode(value) == JSONConstants.BACKSLASH.charAt(0))
+ {
+ tmp = BytesFromString( JSONConstants.BACKSLASH + JSONConstants.BACKSLASH);
+ trans.write( tmp, 0, tmp.length);
+ }
+ else
+ {
+ trans.write( b, i, 1);
+ }
+ }
+ else
+ {
+ var num = JSONConstants.JSON_CHAR_TABLE[value];
+ if (num == 1)
+ {
+ trans.write( b, i, 1);
+ }
+ else if (num > 1)
+ {
+ var buf = new BytesBuffer();
+ buf.addString( JSONConstants.BACKSLASH);
+ buf.addByte( num);
+ tmp = buf.getBytes();
+ trans.write( tmp, 0, tmp.length);
+ }
+ else
+ {
+ var buf = new BytesBuffer();
+ buf.addString( JSONConstants.ESCSEQ);
+ buf.addString( HexChar( (value & 0xFF000000) >> 12));
+ buf.addString( HexChar( (value & 0x00FF0000) >> 8));
+ buf.addString( HexChar( (value & 0x0000FF00) >> 4));
+ buf.addString( HexChar( value & 0x000000FF));
+ tmp = buf.getBytes();
+ trans.write( tmp, 0, tmp.length);
+ }
+ }
+ }
+
+ tmp = BytesFromString( JSONConstants.QUOTE);
+ trans.write( tmp, 0, tmp.length);
+ }
+
+ // Write out number as a JSON value. If the context dictates so,
+ // it will be wrapped in quotes to output as a JSON string.
+ private function WriteJSONInteger( num : Int) : Void {
+ context.Write();
+
+ var str : String = "";
+ var escapeNum : Bool = context.EscapeNumbers();
+
+ if (escapeNum) {
+ str += JSONConstants.QUOTE;
+ }
+
+ str += Std.string(num);
+
+ if (escapeNum) {
+ str += JSONConstants.QUOTE;
+ }
+
+ var tmp = BytesFromString( str);
+ trans.write( tmp, 0, tmp.length);
+ }
+
+ // Write out number as a JSON value. If the context dictates so,
+ // it will be wrapped in quotes to output as a JSON string.
+ private function WriteJSONInt64( num : Int64) : Void {
+ context.Write();
+
+ var str : String = "";
+ var escapeNum : Bool = context.EscapeNumbers();
+
+ if (escapeNum) {
+ str += JSONConstants.QUOTE;
+ }
+
+ str += Std.string(num);
+
+ if (escapeNum) {
+ str += JSONConstants.QUOTE;
+ }
+
+trace('WriteJSONInt64($str)');
+ var tmp = BytesFromString( str);
+ trans.write( tmp, 0, tmp.length);
+ }
+
+ // Write out a double as a JSON value. If it is NaN or infinity or if the
+ // context dictates escaping, Write out as JSON string.
+ private function WriteJSONDouble(num : Float) : Void {
+ context.Write();
+
+
+ var special : Bool = false;
+ var rendered : String = "";
+ if( Math.isNaN(num)) {
+ special = true;
+ rendered = JSONConstants.FLOAT_IS_NAN;
+ } else if (! Math.isFinite(num)) {
+ special = true;
+ if( num > 0) {
+ rendered = JSONConstants.FLOAT_IS_POS_INF;
+ } else {
+ rendered = JSONConstants.FLOAT_IS_NEG_INF;
+ }
+ } else {
+ rendered = Std.string(num); // plain and simple float number
+ }
+
+ // compose output
+ var escapeNum : Bool = special || context.EscapeNumbers();
+ var str : String = "";
+ if (escapeNum) {
+ str += JSONConstants.QUOTE;
+ }
+ str += rendered;
+ if (escapeNum) {
+ str += JSONConstants.QUOTE;
+ }
+
+ var tmp = BytesFromString( str);
+ trans.write( tmp, 0, tmp.length);
+ }
+
+ // Write out contents of byte array b as a JSON string with base-64 encoded data
+ private function WriteJSONBase64( b : Bytes) : Void {
+ context.Write();
+
+ var buf = new BytesBuffer();
+ buf.addString( JSONConstants.QUOTE);
+ buf.addString( Base64.encode(b));
+ buf.addString( JSONConstants.QUOTE);
+
+ var tmp = buf.getBytes();
+ trans.write( tmp, 0, tmp.length);
+ }
+
+ private function WriteJSONObjectStart() : Void {
+ context.Write();
+ var tmp = BytesFromString( JSONConstants.LBRACE);
+ trans.write( tmp, 0, tmp.length);
+ PushContext( new JSONPairContext(this));
+ }
+
+ private function WriteJSONObjectEnd() : Void {
+ PopContext();
+ var tmp = BytesFromString( JSONConstants.RBRACE);
+ trans.write( tmp, 0, tmp.length);
+ }
+
+ private function WriteJSONArrayStart() : Void {
+ context.Write();
+ var tmp = BytesFromString( JSONConstants.LBRACKET);
+ trans.write( tmp, 0, tmp.length);
+ PushContext( new JSONListContext(this));
+ }
+
+ private function WriteJSONArrayEnd() : Void {
+ PopContext();
+ var tmp = BytesFromString( JSONConstants.RBRACKET);
+ trans.write( tmp, 0, tmp.length);
+ }
+
+
+ /**
+ * Reading methods.
+ */
+
+ // Read a byte that must match char, otherwise an exception is thrown.
+ public function ReadJSONSyntaxChar( char : String) : Void {
+ var b = BytesFromString( char);
+
+ var ch = reader.Read();
+ if (ch.get(0) != b.get(0))
+ {
+ throw new TProtocolException(TProtocolException.INVALID_DATA,
+ 'Unexpected character: $ch');
+ }
+ }
+
+ // Read in a JSON string, unescaping as appropriate.
+ // Skip Reading from the context if skipContext is true.
+ private function ReadJSONString(skipContext : Bool) : Bytes
+ {
+ if (!skipContext)
+ {
+ context.Read();
+ }
+
+ var buffer : BytesBuffer = new BytesBuffer();
+
+ ReadJSONSyntaxChar( JSONConstants.QUOTE);
+ while (true)
+ {
+ var ch = reader.Read();
+
+ // end of string?
+ if (StringFromBytes(ch) == JSONConstants.QUOTE)
+ {
+ break;
+ }
+
+ // escaped?
+ if (StringFromBytes(ch) != JSONConstants.ESCSEQ.charAt(0))
+ {
+ buffer.addByte( ch.get(0));
+ continue;
+ }
+
+ // distinguish between \uXXXX (hex unicode) and \X (control chars)
+ ch = reader.Read();
+ if (StringFromBytes(ch) != JSONConstants.ESCSEQ.charAt(1))
+ {
+ var value = JSONConstants.ESCAPE_CHARS_TO_VALUES[ch.get(0)];
+ if( value == null)
+ {
+ throw new TProtocolException( TProtocolException.INVALID_DATA, "Expected control char");
+ }
+ buffer.addByte( value);
+ continue;
+ }
+
+
+ // it's \uXXXX
+ var hexbuf = new BytesBuffer();
+ var hexlen = trans.readAll( hexbuf, 0, 4);
+ if( hexlen != 4)
+ {
+ throw new TProtocolException( TProtocolException.INVALID_DATA, "Not enough data for \\uNNNN sequence");
+ }
+
+ var hexdigits = hexbuf.getBytes();
+ var charcode = 0;
+ charcode = (charcode << 4) + HexVal( String.fromCharCode(hexdigits.get(0)));
+ charcode = (charcode << 4) + HexVal( String.fromCharCode(hexdigits.get(1)));
+ charcode = (charcode << 4) + HexVal( String.fromCharCode(hexdigits.get(2)));
+ charcode = (charcode << 4) + HexVal( String.fromCharCode(hexdigits.get(3)));
+ buffer.addString( String.fromCharCode(charcode));
+ }
+
+ return buffer.getBytes();
+ }
+
+ // Return true if the given byte could be a valid part of a JSON number.
+ private function IsJSONNumeric(b : Int) : Bool {
+ switch (b)
+ {
+ case "+".code: return true;
+ case "-".code: return true;
+ case ".".code: return true;
+ case "0".code: return true;
+ case "1".code: return true;
+ case "2".code: return true;
+ case "3".code: return true;
+ case "4".code: return true;
+ case "5".code: return true;
+ case "6".code: return true;
+ case "7".code: return true;
+ case "8".code: return true;
+ case "9".code: return true;
+ case "E".code: return true;
+ case "e".code: return true;
+ }
+ return false;
+ }
+
+ // Read in a sequence of characters that are all valid in JSON numbers. Does
+ // not do a complete regex check to validate that this is actually a number.
+ private function ReadJSONNumericChars() : String
+ {
+ var buffer : BytesBuffer = new BytesBuffer();
+ while (true)
+ {
+ var ch = reader.Peek();
+ if( ! IsJSONNumeric( ch.get(0)))
+ {
+ break;
+ }
+ buffer.addByte( reader.Read().get(0));
+ }
+ return StringFromBytes( buffer.getBytes());
+ }
+
+ // Read in a JSON number. If the context dictates, Read in enclosing quotes.
+ private function ReadJSONInteger() : Int {
+ context.Read();
+
+ if (context.EscapeNumbers()) {
+ ReadJSONSyntaxChar( JSONConstants.QUOTE);
+ }
+
+ var str : String = ReadJSONNumericChars();
+
+ if (context.EscapeNumbers()) {
+ ReadJSONSyntaxChar( JSONConstants.QUOTE);
+ }
+
+ var value = Std.parseInt(str);
+ if( value == null) {
+ throw new TProtocolException(TProtocolException.INVALID_DATA, 'Bad numeric data: $str');
+ }
+
+ return value;
+ }
+
+ // Read in a JSON number. If the context dictates, Read in enclosing quotes.
+ private function ReadJSONInt64() : haxe.Int64 {
+ context.Read();
+
+ if (context.EscapeNumbers()) {
+ ReadJSONSyntaxChar( JSONConstants.QUOTE);
+ }
+
+ var str : String = ReadJSONNumericChars();
+ if( str.length == 0) {
+ throw new TProtocolException(TProtocolException.INVALID_DATA, 'Bad numeric data: $str');
+ }
+
+ if (context.EscapeNumbers()) {
+ ReadJSONSyntaxChar( JSONConstants.QUOTE);
+ }
+
+trace('ReadJSONInt64() = $str');
+
+ // process sign
+ var bMinus = false;
+ var startAt = 0;
+ if( (str.charAt(0) == "+") || (str.charAt(0) == "-")) {
+ bMinus = (str.charAt(0) == "-");
+ startAt++;
+ }
+
+ // process digits
+ var value : Int64 = Int64.make(0,0);
+ var bGotDigits = false;
+ for( i in startAt ... str.length) {
+ var ch = str.charAt(i);
+ var digit = JSONConstants.DECIMAL_DIGITS[ch];
+ if( digit == null) {
+ throw new TProtocolException(TProtocolException.INVALID_DATA, 'Bad numeric data: $str');
+ }
+ bGotDigits = true;
+
+ // these are decimal digits
+ value = Int64.mul( value, Int64.make(0,10));
+ value = Int64.add( value, Int64.make(0,digit));
+ }
+
+ // process pending minus sign, if applicable
+ // this should also handle the edge case MIN_INT64 correctly
+ if( bMinus && (Int64.compare(value,Int64.make(0,0)) > 0)) {
+ value = Int64.neg( value);
+ bMinus = false;
+ }
+
+ if( ! bGotDigits) {
+ throw new TProtocolException(TProtocolException.INVALID_DATA, 'Bad numeric data: $str');
+ }
+
+ return value;
+ }
+
+ // Read in a JSON double value. Throw if the value is not wrapped in quotes
+ // when expected or if wrapped in quotes when not expected.
+ private function ReadJSONDouble() : Float {
+ context.Read();
+
+ var str : String = "";
+ if (StringFromBytes(reader.Peek()) == JSONConstants.QUOTE) {
+ str = StringFromBytes( ReadJSONString(true));
+
+ // special cases
+ if( str == JSONConstants.FLOAT_IS_NAN) {
+ return Math.NaN;
+ }
+ if( str == JSONConstants.FLOAT_IS_POS_INF) {
+ return Math.POSITIVE_INFINITY;
+ }
+ if( str == JSONConstants.FLOAT_IS_NEG_INF) {
+ return Math.NEGATIVE_INFINITY;
+ }
+
+ if( ! context.EscapeNumbers()) {
+ // throw - we should not be in a string in this case
+ throw new TProtocolException(TProtocolException.INVALID_DATA, "Numeric data unexpectedly quoted");
+ }
+ }
+ else
+ {
+ if( context.EscapeNumbers()) {
+ // This will throw - we should have had a quote if EscapeNumbers() == true
+ ReadJSONSyntaxChar( JSONConstants.QUOTE);
+ }
+
+ str = ReadJSONNumericChars();
+ }
+
+ // parse and check - we should have at least one valid digit
+ var dub = Std.parseFloat( str);
+ if( (str.length == 0) || Math.isNaN(dub)) {
+ throw new TProtocolException(TProtocolException.INVALID_DATA, 'Bad numeric data: $str');
+ }
+
+ return dub;
+ }
+
+ // Read in a JSON string containing base-64 encoded data and decode it.
+ private function ReadJSONBase64() : Bytes
+ {
+ var str = StringFromBytes( ReadJSONString(false));
+ return Base64.decode( str);
+ }
+
+ private function ReadJSONObjectStart() : Void {
+ context.Read();
+ ReadJSONSyntaxChar( JSONConstants.LBRACE);
+ PushContext(new JSONPairContext(this));
+ }
+
+ private function ReadJSONObjectEnd() : Void {
+ ReadJSONSyntaxChar( JSONConstants.RBRACE);
+ PopContext();
+ }
+
+ private function ReadJSONArrayStart() : Void {
+ context.Read();
+ ReadJSONSyntaxChar( JSONConstants.LBRACKET);
+ PushContext(new JSONListContext(this));
+ }
+
+ private function ReadJSONArrayEnd() : Void {
+ ReadJSONSyntaxChar( JSONConstants.RBRACKET);
+ PopContext();
+ }
+
+
+ public static function BytesFromString( str : String) : Bytes {
+ var buf = new BytesBuffer();
+ buf.addString( str);
+ return buf.getBytes();
+ }
+
+ public static function StringFromBytes( buf : Bytes) : String {
+ var inp = new BytesInput( buf);
+ return inp.readString( buf.length);
+ }
+
+ public static function Utf8Encode(str : String) : Bytes {
+ return BytesFromString( Utf8.encode( str));
+ }
+
+ public static function Utf8Decode( buf : Bytes) : String {
+ return Utf8.decode( StringFromBytes( buf));
+ }
+
+ // Convert a byte containing a hex char ('0'-'9' or 'a'-'f') into its corresponding hex value
+ private static function HexVal(char : String) : Int {
+ var value = JSONConstants.HEX_DIGITS[char];
+ if( value == null) {
+ throw new TProtocolException(TProtocolException.INVALID_DATA, 'Expected hex character: $char');
+ }
+ return value;
+ }
+
+ // Convert a byte containing a hex nibble to its corresponding hex character
+ private static function HexChar(nibble : Int) : String
+ {
+ return "0123456789abcdef".charAt(nibble & 0x0F);
+ }
+
+
+}
+
+
+@:allow(TJSONProtocol)
+class JSONConstants {
+ public static var COMMA = ",";
+ public static var COLON = ":";
+ public static var LBRACE = "{";
+ public static var RBRACE = "}";
+ public static var LBRACKET = "[";
+ public static var RBRACKET = "]";
+ public static var QUOTE = "\"";
+ public static var BACKSLASH = "\\";
+
+ public static var ESCSEQ = "\\u";
+
+ public static var FLOAT_IS_NAN = "NaN";
+ public static var FLOAT_IS_POS_INF = "Infinity";
+ public static var FLOAT_IS_NEG_INF = "-Infinity";
+
+ public static var VERSION = 1;
+ public static var JSON_CHAR_TABLE = [
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ "b".code, "t".code, "n".code, 0, "f".code, "r".code, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, "\"".code, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ ];
+
+ public static var ESCAPE_CHARS = ['"','\\','/','b','f','n','r','t'];
+ public static var ESCAPE_CHARS_TO_VALUES = [
+ "\"".code => 0x22,
+ "\\".code => 0x5C,
+ "/".code => 0x2F,
+ "b".code => 0x08,
+ "f".code => 0x0C,
+ "n".code => 0x0A,
+ "r".code => 0x0D,
+ "t".code => 0x09
+ ];
+
+ public static var DECIMAL_DIGITS = [
+ "0" => 0,
+ "1" => 1,
+ "2" => 2,
+ "3" => 3,
+ "4" => 4,
+ "5" => 5,
+ "6" => 6,
+ "7" => 7,
+ "8" => 8,
+ "9" => 9
+ ];
+
+ public static var HEX_DIGITS = [
+ "0" => 0,
+ "1" => 1,
+ "2" => 2,
+ "3" => 3,
+ "4" => 4,
+ "5" => 5,
+ "6" => 6,
+ "7" => 7,
+ "8" => 8,
+ "9" => 9,
+ "A" => 10,
+ "a" => 10,
+ "B" => 11,
+ "b" => 11,
+ "C" => 12,
+ "c" => 12,
+ "D" => 13,
+ "d" => 13,
+ "E" => 14,
+ "e" => 14,
+ "F" => 15,
+ "f" => 15
+ ];
+
+
+ public static var DEF_STRING_SIZE = 16;
+
+ public static var NAME_BOOL = 'tf';
+ public static var NAME_BYTE = 'i8';
+ public static var NAME_I16 = 'i16';
+ public static var NAME_I32 = 'i32';
+ public static var NAME_I64 = 'i64';
+ public static var NAME_DOUBLE = 'dbl';
+ public static var NAME_STRUCT = 'rec';
+ public static var NAME_STRING = 'str';
+ public static var NAME_MAP = 'map';
+ public static var NAME_LIST = 'lst';
+ public static var NAME_SET = 'set';
+
+ public static function GetTypeNameForTypeID(typeID : Int) : String {
+ switch (typeID)
+ {
+ case TType.BOOL: return NAME_BOOL;
+ case TType.BYTE: return NAME_BYTE;
+ case TType.I16: return NAME_I16;
+ case TType.I32: return NAME_I32;
+ case TType.I64: return NAME_I64;
+ case TType.DOUBLE: return NAME_DOUBLE;
+ case TType.STRING: return NAME_STRING;
+ case TType.STRUCT: return NAME_STRUCT;
+ case TType.MAP: return NAME_MAP;
+ case TType.SET: return NAME_SET;
+ case TType.LIST: return NAME_LIST;
+ }
+ throw new TProtocolException(TProtocolException.NOT_IMPLEMENTED, "Unrecognized type");
+ }
+
+ private static var NAMES_TO_TYPES = [
+ NAME_BOOL => TType.BOOL,
+ NAME_BYTE => TType.BYTE,
+ NAME_I16 => TType.I16,
+ NAME_I32 => TType.I32,
+ NAME_I64 => TType.I64,
+ NAME_DOUBLE => TType.DOUBLE,
+ NAME_STRING => TType.STRING,
+ NAME_STRUCT => TType.STRUCT,
+ NAME_MAP => TType.MAP,
+ NAME_SET => TType.SET,
+ NAME_LIST => TType.LIST
+ ];
+
+ public static function GetTypeIDForTypeName(name : String) : Int
+ {
+ var type = NAMES_TO_TYPES[name];
+ if( null != type) {
+ return type;
+ }
+ throw new TProtocolException(TProtocolException.NOT_IMPLEMENTED, "Unrecognized type");
+ }
+
+}
+
+
+// Base class for tracking JSON contexts that may require inserting/Reading
+// additional JSON syntax characters. This base context does nothing.
+@:allow(TJSONProtocol)
+class JSONBaseContext
+{
+ private var proto : TJSONProtocol;
+
+ public function new(proto : TJSONProtocol )
+ {
+ this.proto = proto;
+ }
+
+ public function Write() : Void { }
+ public function Read() : Void { }
+
+ public function EscapeNumbers() : Bool {
+ return false;
+ }
+}
+
+
+// Context for JSON lists.
+// Will insert/Read commas before each item except for the first one
+@:allow(TJSONProtocol)
+class JSONListContext extends JSONBaseContext
+{
+ public function new( proto : TJSONProtocol) {
+ super(proto);
+ }
+
+ private var first : Bool = true;
+
+ public override function Write() : Void {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ var buf = new BytesBuffer();
+ buf.addString( JSONConstants.COMMA);
+ var tmp = buf.getBytes();
+ proto.trans.write( tmp, 0, tmp.length);
+ }
+ }
+
+ public override function Read() : Void {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ proto.ReadJSONSyntaxChar( JSONConstants.COMMA);
+ }
+ }
+}
+
+
+// Context for JSON records.
+// Will insert/Read colons before the value portion of each record
+// pair, and commas before each key except the first. In addition,
+// will indicate that numbers in the key position need to be escaped
+// in quotes (since JSON keys must be strings).
+@:allow(TJSONProtocol)
+class JSONPairContext extends JSONBaseContext
+{
+ public function new( proto : TJSONProtocol ) {
+ super( proto);
+ }
+
+ private var first : Bool = true;
+ private var colon : Bool = true;
+
+ public override function Write() : Void {
+ if (first)
+ {
+ first = false;
+ colon = true;
+ }
+ else
+ {
+ var buf = new BytesBuffer();
+ buf.addString( colon ? JSONConstants.COLON : JSONConstants.COMMA);
+ var tmp = buf.getBytes();
+ proto.trans.write( tmp, 0, tmp.length);
+ colon = !colon;
+ }
+ }
+
+ public override function Read() : Void {
+ if (first)
+ {
+ first = false;
+ colon = true;
+ }
+ else
+ {
+ proto.ReadJSONSyntaxChar( colon ? JSONConstants.COLON : JSONConstants.COMMA);
+ colon = !colon;
+ }
+ }
+
+ public override function EscapeNumbers() : Bool
+ {
+ return colon;
+ }
+}
+
+// Holds up to one byte from the transport
+@:allow(TJSONProtocol)
+class LookaheadReader {
+
+ private var proto : TJSONProtocol;
+ private var data : Bytes;
+
+ public function new( proto : TJSONProtocol ) {
+ this.proto = proto;
+ data = null;
+ }
+
+
+ // Return and consume the next byte to be Read, either taking it from the
+ // data buffer if present or getting it from the transport otherwise.
+ public function Read() : Bytes {
+ var retval = Peek();
+ data = null;
+ return retval;
+ }
+
+ // Return the next byte to be Read without consuming, filling the data
+ // buffer if it has not been filled alReady.
+ public function Peek() : Bytes {
+ if (data == null) {
+ var buf = new BytesBuffer();
+ proto.trans.readAll(buf, 0, 1);
+ data = buf.getBytes();
+ }
+ return data;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/thrift/blob/bd52f1a1/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocolFactory.hx
----------------------------------------------------------------------
diff --git a/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocolFactory.hx b/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocolFactory.hx
new file mode 100644
index 0000000..169629a
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/protocol/TJSONProtocolFactory.hx
@@ -0,0 +1,40 @@
+/*
+ * 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.protocol;
+
+import org.apache.thrift.transport.TTransport;
+
+
+/**
+* JSON Protocol Factory
+*/
+class TJSONProtocolFactory implements TProtocolFactory {
+
+ public function new() {
+ }
+
+ public function getProtocol( trans : TTransport) : TProtocol {
+ return new TJSONProtocol( trans);
+ }
+}
+
+
+
+
\ No newline at end of file