mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-06 18:35:19 +00:00
THRIFT-2644 Haxe support
Client: Haxe Patch: Jens Geyer This closes #214
This commit is contained in:
parent
4712f8c2e3
commit
bd52f1a1dd
2
.gitignore
vendored
2
.gitignore
vendored
@ -229,6 +229,7 @@ test-driver
|
||||
/test/go/src/code.google.com/
|
||||
/test/go/src/gen/
|
||||
/test/go/src/thrift
|
||||
/test/haxe/bin
|
||||
/test/hs/TestClient
|
||||
/test/hs/TestServer
|
||||
/test/py.twisted/_trial_temp/
|
||||
@ -250,6 +251,7 @@ test-driver
|
||||
/tutorial/go/src/shared
|
||||
/tutorial/go/src/tutorial
|
||||
/tutorial/go/src/git.apache.org
|
||||
/tutorial/haxe/bin
|
||||
/tutorial/hs/dist/
|
||||
/tutorial/java/build/
|
||||
/tutorial/js/build/
|
||||
|
@ -120,6 +120,7 @@ THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
|
||||
THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
|
||||
THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
|
||||
THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
|
||||
THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON)
|
||||
THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
|
||||
THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
|
||||
THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
|
||||
|
@ -72,6 +72,7 @@ thrift_SOURCES += src/generate/t_c_glib_generator.cc \
|
||||
src/generate/t_java_generator.cc \
|
||||
src/generate/t_json_generator.cc \
|
||||
src/generate/t_as3_generator.cc \
|
||||
src/generate/t_haxe_generator.cc \
|
||||
src/generate/t_csharp_generator.cc \
|
||||
src/generate/t_py_generator.cc \
|
||||
src/generate/t_rb_generator.cc \
|
||||
|
@ -61,6 +61,7 @@
|
||||
<ClCompile Include="src\generate\t_generator.cc" />
|
||||
<ClCompile Include="src\generate\t_go_generator.cc" />
|
||||
<ClCompile Include="src\generate\t_gv_generator.cc" />
|
||||
<ClCompile Include="src\generate\t_haxe_generator.cc" />
|
||||
<ClCompile Include="src\generate\t_hs_generator.cc" />
|
||||
<ClCompile Include="src\generate\t_html_generator.cc" />
|
||||
<ClCompile Include="src\generate\t_javame_generator.cc" />
|
||||
|
@ -124,6 +124,9 @@
|
||||
<ClCompile Include="src\generate\t_gv_generator.cc">
|
||||
<Filter>generate</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\generate\t_haxe_generator.cc">
|
||||
<Filter>generate</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\generate\t_hs_generator.cc">
|
||||
<Filter>generate</Filter>
|
||||
</ClCompile>
|
||||
|
2949
compiler/cpp/src/generate/t_haxe_generator.cc
Normal file
2949
compiler/cpp/src/generate/t_haxe_generator.cc
Normal file
File diff suppressed because it is too large
Load Diff
19
configure.ac
19
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:"
|
||||
|
75
lib/haxe/README.md
Normal file
75
lib/haxe/README.md
Normal file
@ -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
|
||||
|
40
lib/haxe/src/org/apache/thrift/AbstractMethodError.hx
Normal file
40
lib/haxe/src/org/apache/thrift/AbstractMethodError.hx
Normal file
@ -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");
|
||||
}
|
||||
|
||||
}
|
29
lib/haxe/src/org/apache/thrift/ArgumentError.hx
Normal file
29
lib/haxe/src/org/apache/thrift/ArgumentError.hx
Normal file
@ -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
|
44
lib/haxe/src/org/apache/thrift/Limits.hx
Normal file
44
lib/haxe/src/org/apache/thrift/Limits.hx
Normal file
@ -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
|
||||
}
|
102
lib/haxe/src/org/apache/thrift/TApplicationException.hx
Normal file
102
lib/haxe/src/org/apache/thrift/TApplicationException.hx
Normal file
@ -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();
|
||||
}
|
||||
}
|
66
lib/haxe/src/org/apache/thrift/TBase.hx
Normal file
66
lib/haxe/src/org/apache/thrift/TBase.hx
Normal file
@ -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;
|
||||
}
|
35
lib/haxe/src/org/apache/thrift/TException.hx
Normal file
35
lib/haxe/src/org/apache/thrift/TException.hx
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
31
lib/haxe/src/org/apache/thrift/TFieldRequirementType.hx
Normal file
31
lib/haxe/src/org/apache/thrift/TFieldRequirementType.hx
Normal file
@ -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;
|
||||
|
||||
}
|
30
lib/haxe/src/org/apache/thrift/TProcessor.hx
Normal file
30
lib/haxe/src/org/apache/thrift/TProcessor.hx
Normal file
@ -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;
|
||||
}
|
265
lib/haxe/src/org/apache/thrift/helper/Int64Map.hx
Normal file
265
lib/haxe/src/org/apache/thrift/helper/Int64Map.hx
Normal file
@ -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
|
96
lib/haxe/src/org/apache/thrift/helper/IntSet.hx
Normal file
96
lib/haxe/src/org/apache/thrift/helper/IntSet.hx
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
|
96
lib/haxe/src/org/apache/thrift/helper/ObjectSet.hx
Normal file
96
lib/haxe/src/org/apache/thrift/helper/ObjectSet.hx
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
|
96
lib/haxe/src/org/apache/thrift/helper/StringSet.hx
Normal file
96
lib/haxe/src/org/apache/thrift/helper/StringSet.hx
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
|
56
lib/haxe/src/org/apache/thrift/meta_data/FieldMetaData.hx
Normal file
56
lib/haxe/src/org/apache/thrift/meta_data/FieldMetaData.hx
Normal file
@ -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];
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
30
lib/haxe/src/org/apache/thrift/meta_data/ListMetaData.hx
Normal file
30
lib/haxe/src/org/apache/thrift/meta_data/ListMetaData.hx
Normal file
@ -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;
|
||||
}
|
||||
}
|
32
lib/haxe/src/org/apache/thrift/meta_data/MapMetaData.hx
Normal file
32
lib/haxe/src/org/apache/thrift/meta_data/MapMetaData.hx
Normal file
@ -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;
|
||||
}
|
||||
}
|
30
lib/haxe/src/org/apache/thrift/meta_data/SetMetaData.hx
Normal file
30
lib/haxe/src/org/apache/thrift/meta_data/SetMetaData.hx
Normal file
@ -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;
|
||||
}
|
||||
}
|
30
lib/haxe/src/org/apache/thrift/meta_data/StructMetaData.hx
Normal file
30
lib/haxe/src/org/apache/thrift/meta_data/StructMetaData.hx
Normal file
@ -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;
|
||||
}
|
||||
}
|
296
lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocol.hx
Normal file
296
lib/haxe/src/org/apache/thrift/protocol/TBinaryProtocol.hx
Normal file
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
43
lib/haxe/src/org/apache/thrift/protocol/TField.hx
Normal file
43
lib/haxe/src/org/apache/thrift/protocol/TField.hx
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
1074
lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
Normal file
1074
lib/haxe/src/org/apache/thrift/protocol/TJSONProtocol.hx
Normal file
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
32
lib/haxe/src/org/apache/thrift/protocol/TList.hx
Normal file
32
lib/haxe/src/org/apache/thrift/protocol/TList.hx
Normal file
@ -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.protocol;
|
||||
|
||||
class TList {
|
||||
|
||||
public var elemType : Int;
|
||||
public var size : Int;
|
||||
|
||||
public function new(t : Int = 0, s : Int = 0) {
|
||||
elemType = t;
|
||||
size = s;
|
||||
}
|
||||
|
||||
}
|
34
lib/haxe/src/org/apache/thrift/protocol/TMap.hx
Normal file
34
lib/haxe/src/org/apache/thrift/protocol/TMap.hx
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 TMap {
|
||||
|
||||
public var keyType : Int;
|
||||
public var valueType : Int;
|
||||
public var size : Int;
|
||||
|
||||
public function new(k : Int = 0, v : Int = 0, s : Int = 0) {
|
||||
keyType = k;
|
||||
valueType = v;
|
||||
size = s;
|
||||
}
|
||||
|
||||
}
|
41
lib/haxe/src/org/apache/thrift/protocol/TMessage.hx
Normal file
41
lib/haxe/src/org/apache/thrift/protocol/TMessage.hx
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 TMessage {
|
||||
|
||||
public var name : String;
|
||||
public var type : Int;
|
||||
public var seqid : Int;
|
||||
|
||||
public function new(n : String = "", t : Int = 0, s : Int = 0) {
|
||||
name = n;
|
||||
type = t;
|
||||
seqid = s;
|
||||
}
|
||||
|
||||
public function toString() : String {
|
||||
return "<TMessage name:'" + name + "' type: " + type + " seqid:" + seqid + ">";
|
||||
}
|
||||
|
||||
public function equals(other:TMessage) : Bool {
|
||||
return name == other.name && type == other.type && seqid == other.seqid;
|
||||
}
|
||||
}
|
27
lib/haxe/src/org/apache/thrift/protocol/TMessageType.hx
Normal file
27
lib/haxe/src/org/apache/thrift/protocol/TMessageType.hx
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 TMessageType {
|
||||
public static inline var CALL : Int = 1;
|
||||
public static inline var REPLY : Int = 2;
|
||||
public static inline var EXCEPTION : Int = 3;
|
||||
public static inline var ONEWAY : Int = 4;
|
||||
}
|
82
lib/haxe/src/org/apache/thrift/protocol/TProtocol.hx
Normal file
82
lib/haxe/src/org/apache/thrift/protocol/TProtocol.hx
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 org.apache.thrift.TException;
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
|
||||
/**
|
||||
* Protocol interface definition
|
||||
*/
|
||||
interface TProtocol {
|
||||
|
||||
function getTransport() : TTransport;
|
||||
|
||||
/**
|
||||
* Writing methods.
|
||||
*/
|
||||
function writeMessageBegin(message:TMessage) : Void;
|
||||
function writeMessageEnd() : Void;
|
||||
function writeStructBegin(struct:TStruct) : Void;
|
||||
function writeStructEnd() : Void;
|
||||
function writeFieldBegin(field:TField) : Void;
|
||||
function writeFieldEnd() : Void;
|
||||
function writeFieldStop() : Void;
|
||||
function writeMapBegin(map:TMap) : Void;
|
||||
function writeMapEnd() : Void;
|
||||
function writeListBegin(list:TList) : Void;
|
||||
function writeListEnd() : Void;
|
||||
function writeSetBegin(set:TSet) : Void;
|
||||
function writeSetEnd() : Void;
|
||||
function writeBool(b : Bool) : Void;
|
||||
function writeByte(b : Int) : Void;
|
||||
function writeI16(i16 : Int) : Void;
|
||||
function writeI32(i32 : Int) : Void;
|
||||
function writeI64(i64 : haxe.Int64) : Void;
|
||||
function writeDouble(dub : Float) : Void;
|
||||
function writeString(str : String) : Void;
|
||||
function writeBinary(bin : Bytes) : Void;
|
||||
|
||||
/**
|
||||
* Reading methods.
|
||||
*/
|
||||
function readMessageBegin():TMessage;
|
||||
function readMessageEnd() : Void;
|
||||
function readStructBegin():TStruct;
|
||||
function readStructEnd() : Void;
|
||||
function readFieldBegin():TField;
|
||||
function readFieldEnd() : Void;
|
||||
function readMapBegin():TMap;
|
||||
function readMapEnd() : Void;
|
||||
function readListBegin():TList;
|
||||
function readListEnd() : Void;
|
||||
function readSetBegin():TSet;
|
||||
function readSetEnd() : Void;
|
||||
function readBool() : Bool;
|
||||
function readByte() : Int;
|
||||
function readI16() : Int;
|
||||
function readI32() : Int;
|
||||
function readI64() : haxe.Int64;
|
||||
function readDouble() : Float;
|
||||
function readString() : String;
|
||||
function readBinary() : Bytes;
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.TException;
|
||||
|
||||
class TProtocolException extends TException {
|
||||
|
||||
public static inline var UNKNOWN : Int = 0;
|
||||
public static inline var INVALID_DATA : Int = 1;
|
||||
public static inline var NEGATIVE_SIZE : Int = 2;
|
||||
public static inline var SIZE_LIMIT : Int = 3;
|
||||
public static inline var BAD_VERSION : Int = 4;
|
||||
public static inline var NOT_IMPLEMENTED : Int = 5;
|
||||
public static inline var DEPTH_LIMIT : Int = 6;
|
||||
|
||||
public function new(error : Int = UNKNOWN, message : String = "") {
|
||||
super(message, error);
|
||||
}
|
||||
|
||||
|
||||
}
|
26
lib/haxe/src/org/apache/thrift/protocol/TProtocolFactory.hx
Normal file
26
lib/haxe/src/org/apache/thrift/protocol/TProtocolFactory.hx
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
interface TProtocolFactory {
|
||||
function getProtocol(trans:TTransport):TProtocol;
|
||||
}
|
135
lib/haxe/src/org/apache/thrift/protocol/TProtocolUtil.hx
Normal file
135
lib/haxe/src/org/apache/thrift/protocol/TProtocolUtil.hx
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Utility class with static methods for interacting with protocol data
|
||||
* streams.
|
||||
*
|
||||
*/
|
||||
class TProtocolUtil {
|
||||
|
||||
/**
|
||||
* The maximum recursive depth the skip() function will traverse before
|
||||
* throwing a TException.
|
||||
*/
|
||||
private static var maxSkipDepth : Int = Limits.I32_MAX;
|
||||
|
||||
/**
|
||||
* Specifies the maximum recursive depth that the skip function will
|
||||
* traverse before throwing a TException. This is a global setting, so
|
||||
* any call to skip in this JVM will enforce this value.
|
||||
*
|
||||
* @param depth the maximum recursive depth. A value of 2 would allow
|
||||
* the skip function to skip a structure or collection with basic children,
|
||||
* but it would not permit skipping a struct that had a field containing
|
||||
* a child struct. A value of 1 would only allow skipping of simple
|
||||
* types and empty structs/collections.
|
||||
*/
|
||||
public function setMaxSkipDepth(depth : Int) : Void {
|
||||
maxSkipDepth = depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips over the next data element from the provided input TProtocol object.
|
||||
*
|
||||
* @param prot the protocol object to read from
|
||||
* @param type the next value will be intepreted as this TType value.
|
||||
*/
|
||||
public static function skip(prot:TProtocol, type : Int) : Void {
|
||||
skipMaxDepth(prot, type, maxSkipDepth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips over the next data element from the provided input TProtocol object.
|
||||
*
|
||||
* @param prot the protocol object to read from
|
||||
* @param type the next value will be intepreted as this TType value.
|
||||
* @param maxDepth this function will only skip complex objects to this
|
||||
* recursive depth, to prevent Java stack overflow.
|
||||
*/
|
||||
public static function skipMaxDepth(prot:TProtocol, type : Int, maxDepth : Int) : Void {
|
||||
if (maxDepth <= 0) {
|
||||
throw new TException("Maximum skip depth exceeded");
|
||||
}
|
||||
switch (type) {
|
||||
case TType.BOOL: {
|
||||
prot.readBool();
|
||||
}
|
||||
case TType.BYTE: {
|
||||
prot.readByte();
|
||||
}
|
||||
case TType.I16: {
|
||||
prot.readI16();
|
||||
}
|
||||
case TType.I32: {
|
||||
prot.readI32();
|
||||
}
|
||||
case TType.I64: {
|
||||
prot.readI64();
|
||||
}
|
||||
case TType.DOUBLE: {
|
||||
prot.readDouble();
|
||||
}
|
||||
case TType.STRING: {
|
||||
prot.readBinary();
|
||||
}
|
||||
case TType.STRUCT: {
|
||||
prot.readStructBegin();
|
||||
while (true) {
|
||||
var field:TField = prot.readFieldBegin();
|
||||
if (field.type == TType.STOP) {
|
||||
break;
|
||||
}
|
||||
skipMaxDepth(prot, field.type, maxDepth - 1);
|
||||
prot.readFieldEnd();
|
||||
}
|
||||
prot.readStructEnd();
|
||||
}
|
||||
case TType.MAP: {
|
||||
var map:TMap = prot.readMapBegin();
|
||||
for (i in 0 ... map.size) {
|
||||
skipMaxDepth(prot, map.keyType, maxDepth - 1);
|
||||
skipMaxDepth(prot, map.valueType, maxDepth - 1);
|
||||
}
|
||||
prot.readMapEnd();
|
||||
}
|
||||
case TType.SET: {
|
||||
var set:TSet = prot.readSetBegin();
|
||||
for (j in 0 ... set.size) {
|
||||
skipMaxDepth(prot, set.elemType, maxDepth - 1);
|
||||
}
|
||||
prot.readSetEnd();
|
||||
}
|
||||
case TType.LIST: {
|
||||
var list:TList = prot.readListBegin();
|
||||
for (k in 0 ... list.size) {
|
||||
skipMaxDepth(prot, list.elemType, maxDepth - 1);
|
||||
}
|
||||
prot.readListEnd();
|
||||
}
|
||||
default:
|
||||
trace("Unknown field type ",type," in skipMaxDepth()");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
32
lib/haxe/src/org/apache/thrift/protocol/TSet.hx
Normal file
32
lib/haxe/src/org/apache/thrift/protocol/TSet.hx
Normal file
@ -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.protocol;
|
||||
|
||||
class TSet {
|
||||
|
||||
public var elemType : Int;
|
||||
public var size : Int;
|
||||
|
||||
public function new(t : Int = 0, s : Int = 0) {
|
||||
elemType = t;
|
||||
size = s;
|
||||
}
|
||||
|
||||
}
|
30
lib/haxe/src/org/apache/thrift/protocol/TStruct.hx
Normal file
30
lib/haxe/src/org/apache/thrift/protocol/TStruct.hx
Normal file
@ -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.protocol;
|
||||
|
||||
class TStruct {
|
||||
|
||||
public var name : String;
|
||||
|
||||
public function new(n : String = "") {
|
||||
name = n;
|
||||
}
|
||||
|
||||
}
|
38
lib/haxe/src/org/apache/thrift/protocol/TType.hx
Normal file
38
lib/haxe/src/org/apache/thrift/protocol/TType.hx
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 TType {
|
||||
|
||||
public static inline var STOP : Int = 0;
|
||||
public static inline var VOID : Int = 1;
|
||||
public static inline var BOOL : Int = 2;
|
||||
public static inline var BYTE : Int = 3;
|
||||
public static inline var DOUBLE : Int = 4;
|
||||
public static inline var I16 : Int = 6;
|
||||
public static inline var I32 : Int = 8;
|
||||
public static inline var I64 : Int = 10;
|
||||
public static inline var STRING : Int = 11;
|
||||
public static inline var STRUCT : Int = 12;
|
||||
public static inline var MAP : Int = 13;
|
||||
public static inline var SET : Int = 14;
|
||||
public static inline var LIST : Int = 15;
|
||||
|
||||
}
|
105
lib/haxe/src/org/apache/thrift/server/TServer.hx
Normal file
105
lib/haxe/src/org/apache/thrift/server/TServer.hx
Normal file
@ -0,0 +1,105 @@
|
||||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
class TServer
|
||||
{
|
||||
private var processor : TProcessor = null;
|
||||
private var serverTransport : TServerTransport = null;
|
||||
private var inputTransportFactory : TTransportFactory = null;
|
||||
private var outputTransportFactory : TTransportFactory = null;
|
||||
private var inputProtocolFactory : TProtocolFactory = null;
|
||||
private var outputProtocolFactory : TProtocolFactory = null;
|
||||
|
||||
// server events
|
||||
public var serverEventHandler : TServerEventHandler = null;
|
||||
|
||||
// Log delegation
|
||||
private var _logDelegate : Dynamic->Void = null;
|
||||
public var logDelegate(default,set) : Dynamic->Void;
|
||||
|
||||
public function new( processor : TProcessor,
|
||||
serverTransport : TServerTransport,
|
||||
inputTransportFactory : TTransportFactory = null,
|
||||
outputTransportFactory : TTransportFactory = null,
|
||||
inputProtocolFactory : TProtocolFactory = null,
|
||||
outputProtocolFactory : TProtocolFactory = null,
|
||||
logDelegate : Dynamic->Void = null)
|
||||
{
|
||||
this.processor = processor;
|
||||
this.serverTransport = serverTransport;
|
||||
this.inputTransportFactory = inputTransportFactory;
|
||||
this.outputTransportFactory = outputTransportFactory;
|
||||
this.inputProtocolFactory = inputProtocolFactory;
|
||||
this.outputProtocolFactory = outputProtocolFactory;
|
||||
this.logDelegate = logDelegate;
|
||||
|
||||
ApplyMissingDefaults();
|
||||
}
|
||||
|
||||
private function ApplyMissingDefaults() {
|
||||
if( processor == null)
|
||||
throw "Invalid server configuration: processor missing";
|
||||
if( serverTransport == null)
|
||||
throw "Invalid server configuration: serverTransport missing";
|
||||
if( inputTransportFactory == null)
|
||||
inputTransportFactory = new TTransportFactory();
|
||||
if( outputTransportFactory == null)
|
||||
outputTransportFactory = new TTransportFactory();
|
||||
if( inputProtocolFactory == null)
|
||||
inputProtocolFactory = new TBinaryProtocolFactory();
|
||||
if( outputProtocolFactory == null)
|
||||
outputProtocolFactory= new TBinaryProtocolFactory();
|
||||
if( logDelegate == null)
|
||||
logDelegate = DefaultLogDelegate;
|
||||
}
|
||||
|
||||
|
||||
private function set_logDelegate(value : Dynamic->Void) : Dynamic->Void {
|
||||
if(value != null) {
|
||||
_logDelegate = value;
|
||||
} else {
|
||||
_logDelegate = DefaultLogDelegate;
|
||||
}
|
||||
return _logDelegate;
|
||||
}
|
||||
|
||||
|
||||
private function DefaultLogDelegate(value : Dynamic) : Void {
|
||||
trace( value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function Serve() : Void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
|
||||
public function Stop() : Void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
}
|
41
lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx
Normal file
41
lib/haxe/src/org/apache/thrift/server/TServerEventHandler.hx
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
|
||||
|
||||
// Interface implemented by server users to handle events from the server
|
||||
interface TServerEventHandler {
|
||||
|
||||
// Called before the server begins
|
||||
function preServe() : Void;
|
||||
|
||||
// Called when a new client has connected and is about to being processing
|
||||
function createContext( input : TProtocol, output : TProtocol) : Dynamic;
|
||||
|
||||
// Called when a client has finished request-handling to delete server context
|
||||
function deleteContext( serverContext : Dynamic, input : TProtocol, output : TProtocol) : Void;
|
||||
|
||||
// Called when a client is about to call the processor
|
||||
function processContext( serverContext : Dynamic, transport : TTransport) : Void;
|
||||
}
|
125
lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx
Normal file
125
lib/haxe/src/org/apache/thrift/server/TSimpleServer.hx
Normal file
@ -0,0 +1,125 @@
|
||||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
// Simple single-threaded server for testing
|
||||
class TSimpleServer extends TServer {
|
||||
|
||||
private var stop : Bool = false;
|
||||
|
||||
public function new( processor : TProcessor,
|
||||
serverTransport : TServerTransport,
|
||||
transportFactory : TTransportFactory = null,
|
||||
protocolFactory : TProtocolFactory = null,
|
||||
logDelegate : Dynamic->Void = null) {
|
||||
super( processor, serverTransport,
|
||||
transportFactory, transportFactory,
|
||||
protocolFactory, protocolFactory,
|
||||
logDelegate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override function Serve() : Void
|
||||
{
|
||||
try
|
||||
{
|
||||
serverTransport.Listen();
|
||||
}
|
||||
catch (ttx : TTransportException)
|
||||
{
|
||||
logDelegate(ttx);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fire the preServe server event when server is up,
|
||||
// but before any client connections
|
||||
if (serverEventHandler != null) {
|
||||
serverEventHandler.preServe();
|
||||
}
|
||||
|
||||
while( ! stop)
|
||||
{
|
||||
var client : TTransport = null;
|
||||
var inputTransport : TTransport = null;
|
||||
var outputTransport : TTransport = null;
|
||||
var inputProtocol : TProtocol = null;
|
||||
var outputProtocol : TProtocol = null;
|
||||
var connectionContext : Dynamic = null;
|
||||
try
|
||||
{
|
||||
client = serverTransport.Accept();
|
||||
if (client != null) {
|
||||
inputTransport = inputTransportFactory.getTransport( client);
|
||||
outputTransport = outputTransportFactory.getTransport( client);
|
||||
inputProtocol = inputProtocolFactory.getProtocol( inputTransport);
|
||||
outputProtocol = outputProtocolFactory.getProtocol( outputTransport);
|
||||
|
||||
// Recover event handler (if any) and fire createContext
|
||||
// server event when a client connects
|
||||
if (serverEventHandler != null) {
|
||||
connectionContext = serverEventHandler.createContext(inputProtocol, outputProtocol);
|
||||
}
|
||||
|
||||
// Process client requests until client disconnects
|
||||
while( true) {
|
||||
// Fire processContext server event
|
||||
// N.B. This is the pattern implemented in C++ and the event fires provisionally.
|
||||
// That is to say it may be many minutes between the event firing and the client request
|
||||
// actually arriving or the client may hang up without ever makeing a request.
|
||||
if (serverEventHandler != null) {
|
||||
serverEventHandler.processContext(connectionContext, inputTransport);
|
||||
}
|
||||
|
||||
//Process client request (blocks until transport is readable)
|
||||
if( ! processor.process( inputProtocol, outputProtocol)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( ttx : TTransportException)
|
||||
{
|
||||
// Usually a client disconnect, expected
|
||||
}
|
||||
catch( e : Dynamic)
|
||||
{
|
||||
// Unexpected
|
||||
logDelegate(e);
|
||||
}
|
||||
|
||||
// Fire deleteContext server event after client disconnects
|
||||
if (serverEventHandler != null) {
|
||||
serverEventHandler.deleteContext(connectionContext, inputProtocol, outputProtocol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override function Stop() : Void
|
||||
{
|
||||
stop = true;
|
||||
serverTransport.Close();
|
||||
}
|
||||
}
|
142
lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx
Normal file
142
lib/haxe/src/org/apache/thrift/transport/TFramedTransport.hx
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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 org.apache.thrift.transport.*;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.BytesBuffer;
|
||||
import haxe.io.BytesOutput;
|
||||
import haxe.io.BytesInput;
|
||||
|
||||
|
||||
/**
|
||||
* TFramedTransport is a buffered TTransport that ensures a fully read message
|
||||
* every time by preceding messages with a 4-byte frame size.
|
||||
*/
|
||||
class TFramedTransport extends TTransport
|
||||
{
|
||||
public static inline var DEFAULT_MAX_LENGTH = 16384000;
|
||||
|
||||
var maxLength_ : Int;
|
||||
|
||||
/**
|
||||
* Underlying transport
|
||||
*/
|
||||
var transport_ : TTransport = null;
|
||||
|
||||
/**
|
||||
* Buffer for output
|
||||
*/
|
||||
var writeBuffer_ : BytesOutput = new BytesOutput();
|
||||
|
||||
/**
|
||||
* Buffer for input
|
||||
*/
|
||||
var readBuffer_ : BytesInput = null;
|
||||
|
||||
/**
|
||||
* Constructor wraps around another transport
|
||||
*/
|
||||
public function new( transport : TTransport, maxLength : Int = DEFAULT_MAX_LENGTH) {
|
||||
transport_ = transport;
|
||||
maxLength_ = maxLength;
|
||||
}
|
||||
|
||||
public override function open() : Void {
|
||||
transport_.open();
|
||||
}
|
||||
|
||||
public override function isOpen() : Bool {
|
||||
return transport_.isOpen();
|
||||
}
|
||||
|
||||
public override function close() : Void {
|
||||
transport_.close();
|
||||
}
|
||||
|
||||
public override function read(buf : BytesBuffer, off : Int, len : Int) : Int {
|
||||
var data = Bytes.alloc(len);
|
||||
|
||||
if (readBuffer_ != null) {
|
||||
var got : Int = readBuffer_.readBytes(data, off, len);
|
||||
if (got > 0) {
|
||||
buf.addBytes(data,0,got);
|
||||
return got;
|
||||
};
|
||||
};
|
||||
|
||||
// Read another frame of data
|
||||
readFrame();
|
||||
|
||||
var got = readBuffer_.readBytes(data, off, len);
|
||||
buf.addBytes(data,0,got);
|
||||
return got;
|
||||
}
|
||||
|
||||
|
||||
function readFrameSize() : Int {
|
||||
var buffer = new BytesBuffer();
|
||||
var len = transport_.readAll( buffer, 0, 4);
|
||||
var inp = new BytesInput( buffer.getBytes(), 0, 4);
|
||||
inp.bigEndian = true;
|
||||
return inp.readInt32();
|
||||
}
|
||||
|
||||
|
||||
function readFrame() : Void {
|
||||
var size : Int = readFrameSize();
|
||||
|
||||
if (size < 0) {
|
||||
throw new TTransportException(TTransportException.UNKNOWN, 'Read a negative frame size ($size)!');
|
||||
};
|
||||
if (size > maxLength_) {
|
||||
throw new TTransportException(TTransportException.UNKNOWN, 'Frame size ($size) larger than max length ($maxLength_)!');
|
||||
};
|
||||
|
||||
var buffer = new BytesBuffer();
|
||||
size = transport_.readAll( buffer, 0, size);
|
||||
readBuffer_ = new BytesInput( buffer.getBytes(), 0, size);
|
||||
readBuffer_.bigEndian = true;
|
||||
}
|
||||
|
||||
public override function write(buf : Bytes, off : Int, len : Int) : Void {
|
||||
writeBuffer_.writeBytes(buf, off, len);
|
||||
}
|
||||
|
||||
function writeFrameSize(len : Int) : Void {
|
||||
var out = new BytesOutput();
|
||||
out.bigEndian = true;
|
||||
out.writeInt32(len);
|
||||
transport_.write(out.getBytes(), 0, 4);
|
||||
}
|
||||
|
||||
public override function flush( callback : Dynamic->Void =null) : Void {
|
||||
var buf : Bytes = writeBuffer_.getBytes();
|
||||
var len : Int = buf.length;
|
||||
writeBuffer_ = new BytesOutput();
|
||||
|
||||
writeFrameSize(len);
|
||||
transport_.write(buf, 0, len);
|
||||
transport_.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 org.apache.thrift.transport.*;
|
||||
|
||||
|
||||
class TFramedTransportFactory extends TTransportFactory {
|
||||
|
||||
var maxLength_ : Int;
|
||||
|
||||
public function new(maxLength : Int = TFramedTransport.DEFAULT_MAX_LENGTH) {
|
||||
super();
|
||||
maxLength_ = maxLength;
|
||||
}
|
||||
|
||||
public override function getTransport(base : TTransport) : TTransport {
|
||||
return new TFramedTransport(base, maxLength_);
|
||||
}
|
||||
}
|
@ -0,0 +1,247 @@
|
||||
/*
|
||||
* 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.errors.EOFError;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestMethod;
|
||||
import flash.utils.IDataInput;
|
||||
import flash.utils.IDataOutput;
|
||||
import haxe.io.Bytes;
|
||||
import flash.net.Socket;
|
||||
import flash.events.EventDispatcher;
|
||||
|
||||
|
||||
/**
|
||||
* HTTP implementation of the TTransport interface. Used for working with a
|
||||
* Thrift web services implementation.
|
||||
* Unlike Http Client, it uses a single POST, and chunk-encoding to transfer all messages.
|
||||
*/
|
||||
|
||||
public class TFullDuplexHttpClient extends TTransport
|
||||
{
|
||||
private var socket : Socket = null;
|
||||
private var host : String;
|
||||
private var port : Int;
|
||||
private var resource : String;
|
||||
private var stripped : Bool = false;
|
||||
private var obuffer : Bytes = new Bytes();
|
||||
private var input : IDataInput;
|
||||
private var output : IDataOutput;
|
||||
private var bytesInChunk : Int = 0;
|
||||
private var CRLF : Bytes = new Bytes();
|
||||
private var ioCallback : TException->Void = null;
|
||||
private var eventDispatcher : EventDispatcher = new EventDispatcher();
|
||||
|
||||
public function new(host : String, port : Int, resource : String) : Void
|
||||
{
|
||||
CRLF.writeByte(13);
|
||||
CRLF.writeByte(10);
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public override function close() : Void
|
||||
{
|
||||
this.input = null;
|
||||
this.output = null;
|
||||
this.stripped = false;
|
||||
socket.close()
|
||||
}
|
||||
|
||||
public override function peek() : Bool
|
||||
{
|
||||
if(socket.connected)
|
||||
{
|
||||
trace("Bytes remained:" + socket.bytesAvailable);
|
||||
return socket.bytesAvailable>0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override function read(buf : Bytes, off : Int, len : Int) : Int
|
||||
{
|
||||
var n1 : Int = 0, n2 : Int = 0, n3 : Int = 0, n4 : Int = 0, cidx : Int = 2;
|
||||
var chunkSize : Bytes = new Bytes();
|
||||
|
||||
try
|
||||
{
|
||||
while (!stripped)
|
||||
{
|
||||
n1 = n2;
|
||||
n2 = n3;
|
||||
n3 = n4;
|
||||
n4 = input.readByte();
|
||||
if ((n1 == 13) && (n2 == 10) && (n3 == 13) && (n4 == 10))
|
||||
{
|
||||
stripped = true;
|
||||
}
|
||||
}
|
||||
|
||||
// read chunk size
|
||||
if (bytesInChunk == 0)
|
||||
{
|
||||
n1 = input.readByte();
|
||||
n2 = input.readByte();
|
||||
|
||||
chunkSize.writeByte(n1);
|
||||
chunkSize.writeByte(n2);
|
||||
|
||||
while (!((n1 == 13) && (n2 == 10)))
|
||||
{
|
||||
n1 = n2;
|
||||
n2 = input.readByte();
|
||||
chunkSize.writeByte(n2);
|
||||
}
|
||||
|
||||
bytesInChunk = parseInt(chunkSize.toString(), 16);
|
||||
}
|
||||
|
||||
input.readBytes(buf, off, len);
|
||||
debugBuffer(buf);
|
||||
bytesInChunk -= len;
|
||||
|
||||
if (bytesInChunk == 0)
|
||||
{
|
||||
// advance the : "\r\n"
|
||||
input.readUTFBytes(2);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
catch (e : EOFError)
|
||||
{
|
||||
trace(e);
|
||||
throw new TTransportException(TTransportException.UNKNOWN, "No more data available.");
|
||||
}
|
||||
catch (e : TException)
|
||||
{
|
||||
trace('TException $e');
|
||||
throw e;
|
||||
}
|
||||
catch (e : Error)
|
||||
{
|
||||
trace(e);
|
||||
throw new TTransportException(TTransportException.UNKNOWN, 'Bad IO error: $e');
|
||||
}
|
||||
catch (e : Dynamic)
|
||||
{
|
||||
trace(e);
|
||||
throw new TTransportException(TTransportException.UNKNOWN, 'Bad IO error: $e');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function debugBuffer(buf : Bytes) : Void
|
||||
{
|
||||
var debug : String = "BUFFER >>";
|
||||
var i : Int;
|
||||
for (i = 0; i < buf.length; i++)
|
||||
{
|
||||
debug += buf[i] as int;
|
||||
debug += " ";
|
||||
}
|
||||
|
||||
trace(debug + "<<");
|
||||
}
|
||||
|
||||
public override function write(buf : Bytes, off : Int, len : Int) : Void
|
||||
{
|
||||
obuffer.writeBytes(buf, off, len);
|
||||
}
|
||||
|
||||
public function addEventListener(type : String, listener : Function, useCapture : Bool = false, priority : Int = 0, useWeakReference : Bool = false) : Void
|
||||
{
|
||||
this.eventDispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
|
||||
}
|
||||
|
||||
public override function open() : Void
|
||||
{
|
||||
this.socket = new Socket();
|
||||
this.socket.addEventListener(Event.CONNECT, socketConnected);
|
||||
this.socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
|
||||
this.socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, socketSecurityError);
|
||||
this.socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
|
||||
this.socket.connect(host, port);
|
||||
}
|
||||
|
||||
public function socketConnected(event : Event) : Void
|
||||
{
|
||||
this.output = this.socket;
|
||||
this.input = this.socket;
|
||||
this.output.writeUTF("CONNECT " + resource + " HTTP/1.1\n" + "Host : " + host + ":" + port + "\r\n" + "User-Agent : BattleNet\r\n" + "Transfer-Encoding : chunked\r\n" + "content-type : application/x-thrift\r\n" + "Accept : */*\r\n\r\n");
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function socketError(event : IOErrorEvent) : Void
|
||||
{
|
||||
trace("Error Connecting:" + event);
|
||||
this.close();
|
||||
if (ioCallback == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ioCallback(new TTransportException(TTransportException.UNKNOWN, "IOError : " + event.text));
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function socketSecurityError(event : SecurityErrorEvent) : Void
|
||||
{
|
||||
trace("Security Error Connecting:" + event);
|
||||
this.close();
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public function socketDataHandler(event : ProgressEvent) : Void
|
||||
{
|
||||
trace("Got Data call:" +ioCallback);
|
||||
if (ioCallback != null)
|
||||
{
|
||||
ioCallback(null);
|
||||
};
|
||||
this.eventDispatcher.dispatchEvent(event);
|
||||
}
|
||||
|
||||
public override function flush(callback : Error->Void = null) : Void
|
||||
{
|
||||
trace("set callback:" + callback);
|
||||
this.ioCallback = callback;
|
||||
this.output.writeUTF(this.obuffer.length.toString(16));
|
||||
this.output.writeBytes(CRLF);
|
||||
this.output.writeBytes(this.obuffer);
|
||||
this.output.writeBytes(CRLF);
|
||||
this.socket.flush();
|
||||
// waiting for new Flex sdk 3.5
|
||||
//this.obuffer.clear();
|
||||
this.obuffer = new Bytes();
|
||||
}
|
||||
|
||||
public override function isOpen() : Bool
|
||||
{
|
||||
return (this.socket == null ? false : this.socket.connected);
|
||||
}
|
||||
|
||||
}
|
183
lib/haxe/src/org/apache/thrift/transport/THttpClient.hx
Normal file
183
lib/haxe/src/org/apache/thrift/transport/THttpClient.hx
Normal file
@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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 haxe.io.Bytes;
|
||||
import haxe.io.BytesBuffer;
|
||||
import haxe.io.BytesOutput;
|
||||
import haxe.io.BytesInput;
|
||||
|
||||
#if openfl
|
||||
// OpenFL all targets
|
||||
import openfl.errors.EOFError;
|
||||
import openfl.events.Event;
|
||||
import openfl.events.IOErrorEvent;
|
||||
import openfl.events.SecurityErrorEvent;
|
||||
import openfl.net.URLLoader;
|
||||
import openfl.net.URLLoaderDataFormat;
|
||||
import openfl.net.URLRequest;
|
||||
import openfl.net.URLRequestMethod;
|
||||
#elseif flash
|
||||
// Haxe flash, no OpenFL
|
||||
import flash.errors.EOFError;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestMethod;
|
||||
#else
|
||||
// bare Haxe
|
||||
import haxe.Http;
|
||||
#end
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HTTP implementation of the TTransport interface. Used for working with a
|
||||
* Thrift web services implementation.
|
||||
*/
|
||||
|
||||
class THttpClient extends TTransport {
|
||||
|
||||
private var requestBuffer_ : BytesOutput = new BytesOutput();
|
||||
private var responseBuffer_ : BytesInput = null;
|
||||
|
||||
#if (flash || openfl)
|
||||
private var request_ : URLRequest = null;
|
||||
#else
|
||||
private var request_ : Http = null;
|
||||
#end
|
||||
|
||||
|
||||
#if (flash || openfl)
|
||||
|
||||
public function new( request : URLRequest) : Void {
|
||||
request.contentType = "application/x-thrift";
|
||||
request_ = request;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
public function new( requestUrl : String) : Void {
|
||||
request_ = new Http(requestUrl);
|
||||
request_.addHeader( "contentType", "application/x-thrift");
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
public override function open() : Void {
|
||||
}
|
||||
|
||||
public override function close() : Void {
|
||||
}
|
||||
|
||||
public override function isOpen() : Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override function read(buf:BytesBuffer, off : Int, len : Int) : Int {
|
||||
if (responseBuffer_ == null) {
|
||||
throw new TTransportException(TTransportException.UNKNOWN, "Response buffer is empty, no request.");
|
||||
}
|
||||
|
||||
#if flash
|
||||
try {
|
||||
var data = Bytes.alloc(len);
|
||||
responseBuffer_.readBytes(data, off, len);
|
||||
buf.addBytes(data,0,len);
|
||||
return len;
|
||||
} catch (e : EOFError) {
|
||||
throw new TTransportException(TTransportException.UNKNOWN, "No more data available.");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
var data =Bytes.alloc(len);
|
||||
len = responseBuffer_.readBytes(data, off, len);
|
||||
buf.addBytes(data,0,len);
|
||||
return len;
|
||||
|
||||
#end
|
||||
}
|
||||
|
||||
public override function write(buf:Bytes, off : Int, len : Int) : Void {
|
||||
requestBuffer_.writeBytes(buf, off, len);
|
||||
}
|
||||
|
||||
|
||||
#if (flash || openfl)
|
||||
|
||||
public override function flush(callback:Error->Void = null) : Void {
|
||||
var loader : URLLoader = new URLLoader();
|
||||
|
||||
if (callback != null) {
|
||||
loader.addEventListener(Event.COMPLETE, function(event:Event) : Void {
|
||||
responseBuffer_ = new URLLoader(event.target).data;
|
||||
callback(null);
|
||||
});
|
||||
loader.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent) : Void {
|
||||
callback(new TTransportException(TTransportException.UNKNOWN, "IOError: " + event.text));
|
||||
responseBuffer_ = null;
|
||||
});
|
||||
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(event:SecurityErrorEvent) : Void {
|
||||
callback(new TTransportException(TTransportException.UNKNOWN, "SecurityError: " + event.text));
|
||||
responseBuffer_ = null;
|
||||
});
|
||||
}
|
||||
|
||||
request_.method = URLRequestMethod.POST;
|
||||
loader.dataFormat = URLLoaderDataFormat.BINARY;
|
||||
//requestBuffer_.position = 0;
|
||||
request_.data = requestBuffer_;
|
||||
loader.load(request_);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
public override function flush(callback:Dynamic->Void = null) : Void {
|
||||
|
||||
var buffer = requestBuffer_;
|
||||
requestBuffer_ = new BytesOutput();
|
||||
responseBuffer_ = null;
|
||||
|
||||
request_.onData = function(data : String) {
|
||||
responseBuffer_ = new BytesInput(buffer.getBytes());
|
||||
callback(null);
|
||||
};
|
||||
request_.onError = function(msg : String) {
|
||||
callback(new TTransportException(TTransportException.UNKNOWN, "IOError: " + msg));
|
||||
};
|
||||
|
||||
#if js
|
||||
request_.setPostData(buffer.getBytes().toString());
|
||||
request_.request(true/*POST*/);
|
||||
#else
|
||||
request_.customRequest( true/*POST*/, buffer);
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
132
lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx
Normal file
132
lib/haxe/src/org/apache/thrift/transport/TServerSocket.hx
Normal file
@ -0,0 +1,132 @@
|
||||
/**
|
||||
* 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 haxe.remoting.SocketProtocol;
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.BytesBuffer;
|
||||
import haxe.io.BytesInput;
|
||||
import haxe.io.BytesOutput;
|
||||
import haxe.io.Input;
|
||||
import haxe.io.Output;
|
||||
import haxe.io.Eof;
|
||||
|
||||
//import flash.net.ServerSocket; - not yet available on Haxe 3.1.3
|
||||
#if ! (flash || html5)
|
||||
|
||||
import sys.net.Host;
|
||||
|
||||
|
||||
class TServerSocket extends TServerTransport {
|
||||
|
||||
// Underlying server with socket
|
||||
private var _socket : Socket= null;
|
||||
|
||||
// Port to listen on
|
||||
private var _port : Int = 0;
|
||||
|
||||
// Timeout for client sockets from accept
|
||||
private var _clientTimeout : Int = 0;
|
||||
|
||||
// Whether or not to wrap new TSocket connections in buffers
|
||||
private var _useBufferedSockets : Bool = false;
|
||||
|
||||
|
||||
public function new( port : Int, clientTimeout : Int = 0, useBufferedSockets : Bool = false)
|
||||
{
|
||||
_port = port;
|
||||
_clientTimeout = clientTimeout;
|
||||
_useBufferedSockets = useBufferedSockets;
|
||||
|
||||
try
|
||||
{
|
||||
_socket = new Socket();
|
||||
_socket.bind( new Host('localhost'), port);
|
||||
}
|
||||
catch (e : Dynamic)
|
||||
{
|
||||
_socket = null;
|
||||
throw new TTransportException( TTransportException.UNKNOWN, 'Could not create ServerSocket on port $port: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override function Listen() : Void
|
||||
{
|
||||
// Make sure not to block on accept
|
||||
if (_socket != null) {
|
||||
try
|
||||
{
|
||||
_socket.listen(1);
|
||||
}
|
||||
catch (e : Dynamic)
|
||||
{
|
||||
trace('Error $e');
|
||||
throw new TTransportException( TTransportException.UNKNOWN, 'Could not accept on listening socket: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private override function AcceptImpl() : TTransport
|
||||
{
|
||||
if (_socket == null) {
|
||||
throw new TTransportException( TTransportException.NOT_OPEN, "No underlying server socket.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var accepted = _socket.accept();
|
||||
var result = TSocket.fromSocket(accepted);
|
||||
accepted.setTimeout( _clientTimeout);
|
||||
|
||||
if( _useBufferedSockets)
|
||||
{
|
||||
throw "buffered transport not yet supported"; // TODO
|
||||
//result = new TBufferedTransport(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (e : Dynamic)
|
||||
{
|
||||
trace('Error $e');
|
||||
throw new TTransportException( TTransportException.UNKNOWN, '$e');
|
||||
}
|
||||
}
|
||||
|
||||
public override function Close() : Void
|
||||
{
|
||||
if (_socket != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_socket.close();
|
||||
}
|
||||
catch (e : Dynamic)
|
||||
{
|
||||
trace('Error $e');
|
||||
throw new TTransportException( TTransportException.UNKNOWN, 'WARNING: Could not close server socket: $e');
|
||||
}
|
||||
_socket = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#end
|
43
lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx
Normal file
43
lib/haxe/src/org/apache/thrift/transport/TServerTransport.hx
Normal file
@ -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.transport;
|
||||
|
||||
class TServerTransport {
|
||||
|
||||
public function Accept() : TTransport {
|
||||
var transport = AcceptImpl();
|
||||
if (transport == null) {
|
||||
throw new TTransportException( TTransportException.UNKNOWN, "accept() may not return NULL");
|
||||
}
|
||||
return transport;
|
||||
}
|
||||
|
||||
public function Listen() : Void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
public function Close() : Void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
private function AcceptImpl() : TTransport {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
}
|
296
lib/haxe/src/org/apache/thrift/transport/TSocket.hx
Normal file
296
lib/haxe/src/org/apache/thrift/transport/TSocket.hx
Normal file
@ -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.transport;
|
||||
|
||||
#if flash
|
||||
import flash.net.Socket;
|
||||
#elseif js
|
||||
import js.html.WebSocket;
|
||||
#else
|
||||
import haxe.remoting.SocketProtocol;
|
||||
#end
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.BytesBuffer;
|
||||
import haxe.io.BytesInput;
|
||||
import haxe.io.BytesOutput;
|
||||
import haxe.io.Input;
|
||||
import haxe.io.Output;
|
||||
import haxe.io.Eof;
|
||||
|
||||
|
||||
#if ! (flash || js)
|
||||
import sys.net.Host;
|
||||
#end
|
||||
|
||||
|
||||
/**
|
||||
* Socket implementation of the TTransport interface. Used for working with a
|
||||
* Thrift Socket Server based implementations.
|
||||
*/
|
||||
|
||||
class TSocket extends TTransport {
|
||||
|
||||
#if (flash || js)
|
||||
private var host : String;
|
||||
#else
|
||||
private var host : Host;
|
||||
#end
|
||||
|
||||
private var port : Int;
|
||||
|
||||
#if js
|
||||
private var socket : WebSocket = null;
|
||||
#else
|
||||
private var socket : Socket = null;
|
||||
#end
|
||||
|
||||
#if js
|
||||
private var input : Dynamic = null;
|
||||
private var output : WebSocket = null;
|
||||
#elseif flash
|
||||
private var input : Socket = null;
|
||||
private var output : Socket = null;
|
||||
#else
|
||||
private var input : Input = null;
|
||||
private var output : Output = null;
|
||||
#end
|
||||
|
||||
private var obuffer : BytesOutput = new BytesOutput();
|
||||
private var ioCallback : TException->Void = null;
|
||||
private var readCount : Int = 0;
|
||||
|
||||
public function new(host : String, port : Int) : Void {
|
||||
#if (flash || js)
|
||||
this.host = host;
|
||||
#else
|
||||
this.host = new Host(host);
|
||||
#end
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
#if ! (flash || js)
|
||||
// used by TSocketServer
|
||||
public static function fromSocket( socket : Socket) : TSocket {
|
||||
var result = new TSocket("",0);
|
||||
result.assignSocket(socket);
|
||||
return result;
|
||||
}
|
||||
#end
|
||||
|
||||
public override function close() : Void {
|
||||
input = null;
|
||||
output = null;
|
||||
socket.close();
|
||||
}
|
||||
|
||||
public override function peek() : Bool {
|
||||
if( (input == null) || (socket == null)) {
|
||||
return false;
|
||||
} else {
|
||||
#if flash
|
||||
return (input.bytesAvailable > 0);
|
||||
#elseif js
|
||||
return true;
|
||||
#else
|
||||
var ready = Socket.select( [socket], null, null, 0);
|
||||
return (ready.read.length > 0);
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override function read( buf : BytesBuffer, off : Int, len : Int) : Int {
|
||||
try
|
||||
{
|
||||
#if flash
|
||||
|
||||
var remaining = len;
|
||||
while( remaining > 0) {
|
||||
buf.addByte( input.readByte());
|
||||
--remaining;
|
||||
}
|
||||
return len;
|
||||
|
||||
#elseif js
|
||||
|
||||
if( input == null) {
|
||||
throw new TTransportException(TTransportException.UNKNOWN, "Still no data "); // don't block
|
||||
}
|
||||
var nr = len;
|
||||
while( nr < len) {
|
||||
buf.addByte( input.get(off+nr));
|
||||
++nr;
|
||||
}
|
||||
return len;
|
||||
|
||||
#else
|
||||
|
||||
socket.waitForRead();
|
||||
if(readCount < off) {
|
||||
input.read(off-readCount);
|
||||
readCount = off;
|
||||
}
|
||||
var data = input.read(len);
|
||||
readCount += data.length;
|
||||
buf.add(data);
|
||||
return data.length;
|
||||
|
||||
#end
|
||||
}
|
||||
catch (e : Eof)
|
||||
{
|
||||
trace('Eof $e');
|
||||
throw new TTransportException(TTransportException.END_OF_FILE, "No more data available.");
|
||||
}
|
||||
catch (e : TException)
|
||||
{
|
||||
trace('TException $e');
|
||||
throw e;
|
||||
}
|
||||
catch (e : Dynamic)
|
||||
{
|
||||
trace('Error $e');
|
||||
throw new TTransportException(TTransportException.UNKNOWN, 'Bad IO error : $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override function write(buf : Bytes, off : Int, len : Int) : Void
|
||||
{
|
||||
obuffer.writeBytes(buf, off, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override function flush(callback : Dynamic->Void = null) : Void
|
||||
{
|
||||
if( ! isOpen())
|
||||
{
|
||||
throw new TTransportException(TTransportException.NOT_OPEN, "Transport not open");
|
||||
}
|
||||
|
||||
#if flash
|
||||
|
||||
var bytes = new flash.utils.ByteArray();
|
||||
var data = obuffer.getBytes();
|
||||
var len = 0;
|
||||
while( len < data.length) {
|
||||
bytes.writeByte(data.get(len));
|
||||
++len;
|
||||
}
|
||||
|
||||
#elseif js
|
||||
|
||||
var data = obuffer.getBytes();
|
||||
var outbuf = new js.html.Int8Array(data.length);
|
||||
var len = 0;
|
||||
while( len < data.length) {
|
||||
outbuf.set( [data.get(len)], len);
|
||||
++len;
|
||||
}
|
||||
var bytes = outbuf.buffer;
|
||||
|
||||
|
||||
#else
|
||||
|
||||
var bytes = obuffer.getBytes();
|
||||
var len = bytes.length;
|
||||
|
||||
#end
|
||||
|
||||
obuffer = new BytesOutput();
|
||||
|
||||
|
||||
ioCallback = callback;
|
||||
try {
|
||||
readCount = 0;
|
||||
#if js
|
||||
output.send( bytes);
|
||||
#else
|
||||
output.writeBytes( bytes, 0, bytes.length);
|
||||
#end
|
||||
if(ioCallback != null) {
|
||||
ioCallback(null); // success call
|
||||
}
|
||||
}
|
||||
catch (e : TException)
|
||||
{
|
||||
trace('TException $e');
|
||||
if(ioCallback != null) {
|
||||
ioCallback(e);
|
||||
}
|
||||
}
|
||||
catch (e : Dynamic) {
|
||||
trace(e);
|
||||
if(ioCallback != null) {
|
||||
ioCallback(new TTransportException(TTransportException.UNKNOWN, 'Bad IO error : $e'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override function isOpen() : Bool
|
||||
{
|
||||
return (socket != null);
|
||||
}
|
||||
|
||||
public override function open() : Void
|
||||
{
|
||||
#if js
|
||||
var socket = new WebSocket();
|
||||
socket.onmessage = function( event : js.html.MessageEvent) {
|
||||
this.input = event.data;
|
||||
}
|
||||
|
||||
#elseif flash
|
||||
|
||||
var socket = new Socket();
|
||||
socket.connect(host, port);
|
||||
|
||||
#else
|
||||
|
||||
var socket = new Socket();
|
||||
socket.setBlocking(true);
|
||||
socket.setFastSend(true);
|
||||
socket.connect(host, port);
|
||||
|
||||
#end
|
||||
|
||||
assignSocket( socket);
|
||||
}
|
||||
|
||||
#if js
|
||||
private function assignSocket( socket : WebSocket) : Void
|
||||
#else
|
||||
private function assignSocket( socket : Socket) : Void
|
||||
#end
|
||||
{
|
||||
this.socket = socket;
|
||||
|
||||
#if (flash || js)
|
||||
output = socket;
|
||||
input = socket;
|
||||
#else
|
||||
output = socket.output;
|
||||
input = socket.input;
|
||||
#end
|
||||
}
|
||||
|
||||
}
|
133
lib/haxe/src/org/apache/thrift/transport/TTransport.hx
Normal file
133
lib/haxe/src/org/apache/thrift/transport/TTransport.hx
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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 haxe.io.Bytes;
|
||||
import haxe.io.BytesBuffer;
|
||||
import org.apache.thrift.AbstractMethodError;
|
||||
|
||||
class TTransport {
|
||||
|
||||
/**
|
||||
* Queries whether the transport is open.
|
||||
*
|
||||
* @return True if the transport is open.
|
||||
*/
|
||||
public function isOpen() : Bool {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there more data to be read?
|
||||
*
|
||||
* @return True if the remote side is still alive and feeding us
|
||||
*/
|
||||
public function peek() : Bool {
|
||||
return isOpen();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the transport for reading/writing.
|
||||
*
|
||||
* @throws TTransportException if the transport could not be opened
|
||||
*/
|
||||
public function open() : Void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the transport.
|
||||
*/
|
||||
public function close() : Void {
|
||||
throw new AbstractMethodError();
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads up to len bytes into buffer buf, starting att offset off.
|
||||
*
|
||||
* @param buf Array to read into
|
||||
* @param off Index to start reading at
|
||||
* @param len Maximum number of bytes to read
|
||||
* @return The bytes count actually read
|
||||
* @throws TTransportException if there was an error reading data
|
||||
*/
|
||||
public function read( buf : BytesBuffer, off : Int, len : Int) : Int {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Guarantees that all of len bytes are actually read off the transport.
|
||||
*
|
||||
* @param buf Array to read into
|
||||
* @param off Index to start reading at
|
||||
* @param len Maximum number of bytes to read
|
||||
* @return The number of bytes actually read, which must be equal to len
|
||||
* @throws TTransportException if there was an error reading data
|
||||
*/
|
||||
public function readAll(buf : BytesBuffer, off : Int, len : Int) : Int {
|
||||
var got : Int = 0;
|
||||
var ret : Int = 0;
|
||||
while (got < len) {
|
||||
ret = read(buf, off+got, len-got);
|
||||
if (ret <= 0) {
|
||||
throw new TTransportException(TTransportException.UNKNOWN,
|
||||
"Cannot read. Remote side has closed. Tried to read "
|
||||
+ len + " bytes, but only got " + got + " bytes.");
|
||||
}
|
||||
got += ret;
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the buffer to the output
|
||||
*
|
||||
* @param buf The output data buffer
|
||||
* @throws TTransportException if an error occurs writing data
|
||||
*/
|
||||
public function writeAll(buf:Bytes) : Void {
|
||||
write(buf, 0, buf.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes up to len bytes from the buffer.
|
||||
*
|
||||
* @param buf The output data buffer
|
||||
* @param off The offset to start writing from
|
||||
* @param len The number of bytes to write
|
||||
* @throws TTransportException if there was an error writing data
|
||||
*/
|
||||
public function write(buf:Bytes, off : Int, len : Int) : Void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush any pending data out of a transport buffer.
|
||||
*
|
||||
* @throws TTransportException if there was an error writing out data.
|
||||
*/
|
||||
public function flush(callback:Dynamic->Void =null) : Void {
|
||||
if(callback != null)
|
||||
callback(new AbstractMethodError());
|
||||
else
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 org.apache.thrift.TException;
|
||||
|
||||
class TTransportException extends TException {
|
||||
|
||||
public static inline var UNKNOWN : Int = 0;
|
||||
public static inline var NOT_OPEN : Int = 1;
|
||||
public static inline var ALREADY_OPEN : Int = 2;
|
||||
public static inline var TIMED_OUT : Int = 3;
|
||||
public static inline var END_OF_FILE : Int = 4;
|
||||
|
||||
public function new(error : Int = UNKNOWN, message : String = "") {
|
||||
super(message, error);
|
||||
}
|
||||
|
||||
}
|
@ -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.transport;
|
||||
|
||||
/**
|
||||
* Factory class used to create wrapped instance of Transports.
|
||||
* This is used primarily in servers, which get Transports from
|
||||
* a ServerTransport and then may want to mutate them (i.e. create
|
||||
* a BufferedTransport from the underlying base transport)
|
||||
*
|
||||
*/
|
||||
class TTransportFactory {
|
||||
|
||||
public function new() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a wrapped instance of the base Transport.
|
||||
*
|
||||
* @param trans The base transport
|
||||
* @return Wrapped Transport
|
||||
*/
|
||||
public function getTransport( trans : TTransport) : TTransport {
|
||||
return trans;
|
||||
}
|
||||
|
||||
}
|
@ -49,6 +49,10 @@ if WITH_HASKELL
|
||||
SUBDIRS += hs
|
||||
endif
|
||||
|
||||
if WITH_HAXE
|
||||
SUBDIRS += haxe
|
||||
endif
|
||||
|
||||
if WITH_GO
|
||||
SUBDIRS += go
|
||||
endif
|
||||
|
52
test/haxe/Makefile.am
Normal file
52
test/haxe/Makefile.am
Normal file
@ -0,0 +1,52 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
THRIFT = $(top_srcdir)/compiler/cpp/thrift
|
||||
THRIFTCMD = $(THRIFT) --gen haxe -r
|
||||
THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
|
||||
|
||||
BIN_CPP = bin/Main-debug
|
||||
|
||||
gen-haxe/ThriftTest/ThriftTest.hx: $(THRIFTTEST)
|
||||
$(THRIFTCMD) $(THRIFTTEST)
|
||||
|
||||
all-local: $(BIN_CPP)
|
||||
|
||||
$(BIN_CPP): gen-haxe/ThriftTest/ThriftTest.hx
|
||||
$(HAXE) --cwd . cpp.hxml
|
||||
|
||||
|
||||
#TODO: other haxe targets
|
||||
# $(HAXE) --cwd . csharp
|
||||
# $(HAXE) --cwd . flash
|
||||
# $(HAXE) --cwd . java
|
||||
# $(HAXE) --cwd . javascript
|
||||
# $(HAXE) --cwd . neko
|
||||
# $(HAXE) --cwd . php
|
||||
# $(HAXE) --cwd . python # needs Haxe 3.1.4
|
||||
|
||||
|
||||
clean-local:
|
||||
$(RM) -r gen-haxe bin
|
||||
|
||||
check: $(BIN_CPP)
|
||||
timeout 120 $(BIN_CPP) server &
|
||||
sleep 1
|
||||
$(BIN_CPP) client
|
||||
|
41
test/haxe/cpp.hxml
Normal file
41
test/haxe/cpp.hxml
Normal file
@ -0,0 +1,41 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#CPP target
|
||||
-cpp bin
|
||||
|
||||
#To produce 64 bit binaries the file should define the HXCPP_M64 compile variable:
|
||||
#-D HXCPP_M64
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
38
test/haxe/csharp.hxml
Normal file
38
test/haxe/csharp.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#CSHARP target
|
||||
-cs bin/Tutorial.exe
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
41
test/haxe/flash.hxml
Normal file
41
test/haxe/flash.hxml
Normal file
@ -0,0 +1,41 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#Flash target
|
||||
-swf bin/Tutorial.swf
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
# we need some goodies from sys.net
|
||||
# --macro allowPackage("sys")
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
38
test/haxe/java.hxml
Normal file
38
test/haxe/java.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#Java target
|
||||
-java bin/Tutorial.jar
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
44
test/haxe/javascript.hxml
Normal file
44
test/haxe/javascript.hxml
Normal file
@ -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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#JavaScript target
|
||||
-js bin/Tutorial.js
|
||||
|
||||
#You can use -D source-map-content (requires Haxe 3.1+) to have the .hx
|
||||
#files directly embedded into the map file, this way you only have to
|
||||
#upload it, and it will be always in sync with the compiled .js even if
|
||||
#you modify your .hx files.
|
||||
-D source-map-content
|
||||
|
||||
#Generate source map and add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
68
test/haxe/make_all.bat
Normal file
68
test/haxe/make_all.bat
Normal file
@ -0,0 +1,68 @@
|
||||
@echo off
|
||||
rem /*
|
||||
rem * Licensed to the Apache Software Foundation (ASF) under one
|
||||
rem * or more contributor license agreements. See the NOTICE file
|
||||
rem * distributed with this work for additional information
|
||||
rem * regarding copyright ownership. The ASF licenses this file
|
||||
rem * to you under the Apache License, Version 2.0 (the
|
||||
rem * "License"); you may not use this file except in compliance
|
||||
rem * with the License. You may obtain a copy of the License at
|
||||
rem *
|
||||
rem * http://www.apache.org/licenses/LICENSE-2.0
|
||||
rem *
|
||||
rem * Unless required by applicable law or agreed to in writing,
|
||||
rem * software distributed under the License is distributed on an
|
||||
rem * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
rem * KIND, either express or implied. See the License for the
|
||||
rem * specific language governing permissions and limitations
|
||||
rem * under the License.
|
||||
rem */
|
||||
|
||||
setlocal
|
||||
if "%HOMEDRIVE%"=="" goto MISSINGVARS
|
||||
if "%HOMEPATH%"=="" goto MISSINGVARS
|
||||
if "%HAXEPATH%"=="" goto NOTINSTALLED
|
||||
|
||||
set path=%HAXEPATH%;%HAXEPATH%\..\neko;%path%
|
||||
|
||||
rem # invoke Thrift comnpiler
|
||||
thrift -r -gen haxe ..\ThriftTest.thrift
|
||||
if errorlevel 1 goto STOP
|
||||
|
||||
rem # invoke Haxe compiler for all targets
|
||||
for %%a in (*.hxml) do (
|
||||
rem * filter Python, as it is not supported by Haxe 3.1.3 (but will be in 3.1.4)
|
||||
if not "%%a"=="python.hxml" (
|
||||
echo --------------------------
|
||||
echo Building %%a ...
|
||||
echo --------------------------
|
||||
haxe --cwd . %%a
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
echo.
|
||||
echo done.
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:NOTINSTALLED
|
||||
echo FATAL: Either Haxe is not installed, or the HAXEPATH variable is not set.
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:MISSINGVARS
|
||||
echo FATAL: Unable to locate home folder.
|
||||
echo.
|
||||
echo Both HOMEDRIVE and HOMEPATH need to be set to point to your Home folder.
|
||||
echo The current values are:
|
||||
echo HOMEDRIVE=%HOMEDRIVE%
|
||||
echo HOMEPATH=%HOMEPATH%
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:STOP
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:eof
|
41
test/haxe/make_all.sh
Normal file
41
test/haxe/make_all.sh
Normal file
@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# invoke Thrift comnpiler
|
||||
thrift -r -gen haxe ../ThriftTest.thrift
|
||||
|
||||
# output folder
|
||||
if [ ! -d bin ]; then
|
||||
mkdir bin
|
||||
fi
|
||||
|
||||
# invoke Haxe compiler
|
||||
for target in *.hxml; do
|
||||
echo --------------------------
|
||||
echo Building ${target} ...
|
||||
echo --------------------------
|
||||
if [ ! -d bin/${target} ]; then
|
||||
mkdir bin/${target}
|
||||
fi
|
||||
haxe --cwd . ${target}
|
||||
done
|
||||
|
||||
|
||||
#eof
|
38
test/haxe/neko.hxml
Normal file
38
test/haxe/neko.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#neko target
|
||||
-neko bin/Tutorial.n
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
38
test/haxe/php.hxml
Normal file
38
test/haxe/php.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#PHP target
|
||||
-php bin/Tutorial.php
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
85
test/haxe/project.hide
Normal file
85
test/haxe/project.hide
Normal file
@ -0,0 +1,85 @@
|
||||
{
|
||||
"type" : 0
|
||||
,"target" : 4
|
||||
,"name" : "Apache Thrift cross-platform test client/server"
|
||||
,"main" : null
|
||||
,"projectPackage" : ""
|
||||
,"company" : "Apache Software Foundation (ASF)"
|
||||
,"license" : "Apache License, Version 2.0"
|
||||
,"url" : "http://www.apache.org/licenses/LICENSE-2.0"
|
||||
,"targetData" : [
|
||||
{
|
||||
"pathToHxml" : "flash.hxml"
|
||||
,"runActionType" : 1
|
||||
,"runActionText" : "bin/Tutorial.swf"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "javascript.hxml"
|
||||
,"runActionType" : 1
|
||||
,"runActionText" : "bin\\index.html"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "neko.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "neko bin/Tutorial.n"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "php.hxml"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "cpp.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "bin/Main-debug.exe client --json"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "java.hxml"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "csharp.hxml"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "python.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "python bin/Tutorial.py"
|
||||
}
|
||||
]
|
||||
,"files" : [
|
||||
{
|
||||
"path" : "src\\Arguments.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 159
|
||||
}
|
||||
,{
|
||||
"path" : "..\\..\\lib\\haxe\\src\\org\\apache\\thrift\\protocol\\TJSONProtocol.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 665
|
||||
}
|
||||
,{
|
||||
"path" : "src\\TestClient.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 325
|
||||
}
|
||||
]
|
||||
,"activeFile" : "..\\..\\lib\\haxe\\src\\org\\apache\\thrift\\protocol\\TJSONProtocol.hx"
|
||||
,"openFLTarget" : null
|
||||
,"openFLBuildMode" : "Debug"
|
||||
,"runActionType" : null
|
||||
,"runActionText" : null
|
||||
,"buildActionCommand" : null
|
||||
,"hiddenItems" : [
|
||||
|
||||
]
|
||||
,"showHiddenItems" : false
|
||||
}
|
38
test/haxe/python.hxml
Normal file
38
test/haxe/python.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#Python target
|
||||
-python bin/Tutorial.py
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
181
test/haxe/src/Arguments.hx
Normal file
181
test/haxe/src/Arguments.hx
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
using StringTools;
|
||||
|
||||
|
||||
enum Prot {
|
||||
binary;
|
||||
json;
|
||||
}
|
||||
|
||||
enum Trns {
|
||||
socket;
|
||||
http;
|
||||
}
|
||||
|
||||
|
||||
class Arguments
|
||||
{
|
||||
public var server(default,null) : Bool = false;
|
||||
public var framed(default,null) : Bool = false;
|
||||
public var buffered(default,null) : Bool = false;
|
||||
public var protocol(default,null) : Prot = binary;
|
||||
public var transport(default,null) : Trns = socket;
|
||||
|
||||
public var host(default,null) : String = "localhost";
|
||||
public var port(default,null) : Int = 9090;
|
||||
|
||||
public var numIterations(default,null) : Int = 1;
|
||||
public var numThreads(default,null) : Int = 1;
|
||||
|
||||
|
||||
public function new() {
|
||||
#if sys
|
||||
try {
|
||||
ParseArgs();
|
||||
} catch (e : String) {
|
||||
trace(GetHelp());
|
||||
throw e;
|
||||
}
|
||||
#else
|
||||
trace("WN: Platform does not support program arguments, using defaults.");
|
||||
#end
|
||||
}
|
||||
|
||||
#if sys
|
||||
|
||||
private static function GetHelp() : String {
|
||||
return "\n"
|
||||
+Sys.executablePath()+" [client|server] [options]\n"
|
||||
+"Modus: Either client or server, the default is client.\n"
|
||||
+"\n"
|
||||
+"Options:\n"
|
||||
+" -f, --framed framed transport (supersedes buffered)\n"
|
||||
+" -b, --buffered buffered transport\n"
|
||||
+" --json JSON protocol\n"
|
||||
+" --protocol=<prot> Choose protocol: json, binary (default binary).\n"
|
||||
+" --port=<port> Port number for socket transport, default 9090\n"
|
||||
+"\n"
|
||||
+"Client only options:\n"
|
||||
+" --host=<host> Host name, IP or URL, default localhost\n"
|
||||
+" -n=<iterations> Number of test iterations\n"
|
||||
+" -t=<threads> Number of test threads\n"
|
||||
+" -u=<url> Target Host/URL (same as --host)\n"
|
||||
+"\n"
|
||||
+"All arguments are optional.\n";
|
||||
}
|
||||
|
||||
|
||||
private function ParseArgs() : Void {
|
||||
var step = 0;
|
||||
for (arg in Sys.args()) {
|
||||
|
||||
// server|client
|
||||
switch(step) {
|
||||
case 0:
|
||||
++step;
|
||||
if ( arg == "client")
|
||||
server = false;
|
||||
else if ( arg == "server")
|
||||
server = true;
|
||||
else
|
||||
throw "First argument must be 'server' or 'client'";
|
||||
|
||||
case 1:
|
||||
if ( (arg == "-f") || (arg == "--framed")) {
|
||||
framed = true;
|
||||
} else if (( arg == "-b") || ( arg == "--buffered")) {
|
||||
buffered = true;
|
||||
} else if (( arg == "--json") || (arg == "--protocol=json")){
|
||||
protocol = json;
|
||||
} else if (( arg == "--protocol=binary")){
|
||||
protocol = binary;
|
||||
} else if (arg.startsWith("--host=")) {
|
||||
ClientOnlyOption(arg);
|
||||
host = arg.substr(arg.indexOf("=") + 1);
|
||||
} else if (arg.startsWith("--port=")) {
|
||||
var tmp = Std.parseInt(arg.substr(arg.indexOf("=")+1));
|
||||
if( tmp != null)
|
||||
port = tmp;
|
||||
else
|
||||
throw "Invalid port number "+arg;
|
||||
} else if (arg == "-n") {
|
||||
ClientOnlyOption(arg);
|
||||
step = 2;
|
||||
} else if (arg == "-t") {
|
||||
ClientOnlyOption(arg);
|
||||
step = 3;
|
||||
} else if (arg == "-u") {
|
||||
ClientOnlyOption(arg);
|
||||
step = 4;
|
||||
} else {
|
||||
throw "Unexpected argument "+arg;
|
||||
}
|
||||
|
||||
case 2: // num iterations
|
||||
step = 1;
|
||||
var tmp = Std.parseInt(arg);
|
||||
if( tmp != null)
|
||||
numIterations = tmp;
|
||||
else
|
||||
throw "Invalid numeric value "+arg;
|
||||
|
||||
case 3: // num threads
|
||||
step = 1;
|
||||
var tmp = Std.parseInt(arg);
|
||||
if( tmp != null)
|
||||
numThreads = tmp;
|
||||
else
|
||||
throw "Invalid numeric value "+arg;
|
||||
|
||||
case 4: // url
|
||||
step = 1;
|
||||
host = arg;
|
||||
|
||||
default:
|
||||
throw "Unexpected state";
|
||||
}
|
||||
|
||||
|
||||
if ( framed && buffered)
|
||||
{
|
||||
trace("WN: framed supersedes buffered transport");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
|
||||
private function ClientOnlyOption( arg : String) {
|
||||
if( server) {
|
||||
throw "Unexpected argument in client mode: "+arg;
|
||||
}
|
||||
}
|
||||
}
|
48
test/haxe/src/Main.hx
Normal file
48
test/haxe/src/Main.hx
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
import thrift.test.*; // generated code
|
||||
|
||||
class Main
|
||||
{
|
||||
static function main() {
|
||||
try {
|
||||
var args = new Arguments();
|
||||
|
||||
if (args.server)
|
||||
TestServer.Execute(args);
|
||||
else
|
||||
TestClient.Execute(args);
|
||||
|
||||
trace("Completed.");
|
||||
} catch (e : String) {
|
||||
trace(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
696
test/haxe/src/TestClient.hx
Normal file
696
test/haxe/src/TestClient.hx
Normal file
@ -0,0 +1,696 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import haxe.Int32;
|
||||
import haxe.Int64;
|
||||
import haxe.Timer;
|
||||
import haxe.ds.IntMap;
|
||||
import haxe.ds.StringMap;
|
||||
import haxe.ds.ObjectMap;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.helper.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
#if cpp
|
||||
import cpp.vm.Thread;
|
||||
#else
|
||||
// no thread support (yet)
|
||||
#end
|
||||
|
||||
import thrift.test.*; // generated code
|
||||
|
||||
|
||||
class TestResults {
|
||||
private var successCnt : Int = 0;
|
||||
private var errorCnt : Int = 0;
|
||||
private var failedTests : String = "";
|
||||
private var print_direct : Bool = false;
|
||||
|
||||
public function new(direct : Bool) {
|
||||
print_direct = direct;
|
||||
}
|
||||
|
||||
public function Expect( expr : Bool, msg : String) : Void {
|
||||
if ( expr) {
|
||||
++successCnt;
|
||||
} else {
|
||||
++errorCnt;
|
||||
failedTests += "\n " + msg;
|
||||
if( print_direct) {
|
||||
trace('FAIL: $msg');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function PrintSummary() : Void {
|
||||
var total = successCnt + errorCnt;
|
||||
var sp = (100 * successCnt) / total;
|
||||
var ep = (100 * errorCnt) / total;
|
||||
|
||||
trace('===========================');
|
||||
trace('Tests executed $total');
|
||||
trace('Tests succeeded $successCnt ($sp%)');
|
||||
trace('Tests failed $errorCnt ($ep%)');
|
||||
if ( errorCnt > 0)
|
||||
{
|
||||
trace('===========================');
|
||||
trace('FAILED TESTS: $failedTests');
|
||||
}
|
||||
trace('===========================');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TestClient {
|
||||
|
||||
public static function Execute(args : Arguments) : Void
|
||||
{
|
||||
try
|
||||
{
|
||||
var difft = Timer.stamp();
|
||||
|
||||
if( args.numThreads > 1) {
|
||||
var threads = new List<Thread>();
|
||||
for( test in 0 ... args.numThreads) {
|
||||
threads.add( StartThread( args));
|
||||
}
|
||||
for( thread in threads) {
|
||||
Thread.readMessage(true);
|
||||
}
|
||||
} else {
|
||||
var rslt = new TestResults(true);
|
||||
RunClient(args,rslt);
|
||||
rslt.PrintSummary();
|
||||
}
|
||||
|
||||
difft = Timer.stamp() - difft;
|
||||
trace('total test time: $difft seconds');
|
||||
}
|
||||
catch (e : TException)
|
||||
{
|
||||
trace('$e');
|
||||
}
|
||||
catch (e : Dynamic)
|
||||
{
|
||||
trace('$e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function StartThread(args : Arguments) : Thread {
|
||||
var thread = Thread.create(
|
||||
function() : Void {
|
||||
var main : Thread = Thread.readMessage(true);
|
||||
try
|
||||
{
|
||||
var rslt = new TestResults(false);
|
||||
RunClient(args,rslt);
|
||||
// TODO: promote rslt values to main thread
|
||||
}
|
||||
catch (e : TException)
|
||||
{
|
||||
trace('$e');
|
||||
}
|
||||
catch (e : Dynamic)
|
||||
{
|
||||
trace('$e');
|
||||
}
|
||||
main.sendMessage("done");
|
||||
});
|
||||
|
||||
thread.sendMessage(Thread.current());
|
||||
return thread;
|
||||
}
|
||||
|
||||
|
||||
public static function RunClient(args : Arguments, rslt : TestResults)
|
||||
{
|
||||
var transport : TTransport = null;
|
||||
switch (args.transport)
|
||||
{
|
||||
case socket:
|
||||
transport = new TSocket(args.host, args.port);
|
||||
case http:
|
||||
throw "http transport not supported yet";
|
||||
//transport = new THttpClient(args.host);
|
||||
default:
|
||||
throw "Unhandled transport";
|
||||
}
|
||||
|
||||
// optional: layered transport
|
||||
if ( args.framed) {
|
||||
trace("- framed transport");
|
||||
transport = new TFramedTransport(transport);
|
||||
} else if ( args.buffered) {
|
||||
trace("- buffered transport");
|
||||
throw "TBufferedTransport not implemented yet";
|
||||
//transport = new TBufferedTransport(transport);
|
||||
}
|
||||
|
||||
// protocol
|
||||
var protocol : TProtocol = null;
|
||||
switch( args.protocol)
|
||||
{
|
||||
case binary:
|
||||
trace("- binary protocol");
|
||||
protocol = new TBinaryProtocol(transport);
|
||||
case json:
|
||||
trace("- json protocol");
|
||||
protocol = new TJSONProtocol(transport);
|
||||
default:
|
||||
throw "Unhandled protocol";
|
||||
}
|
||||
|
||||
|
||||
// run the test code
|
||||
HaxeBasicsTest( rslt);
|
||||
ClientTest( transport, protocol, rslt);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function HaxeBasicsTest( rslt : TestResults) : Void
|
||||
{
|
||||
// We need to test a few basic things used in the ClientTest
|
||||
// Anything else beyond this scope should go into /lib/haxe/ instead
|
||||
|
||||
var map32 = new IntMap<Int32>();
|
||||
var map64 = new Int64Map<Int32>();
|
||||
|
||||
rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #1");
|
||||
rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #2");
|
||||
rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #3");
|
||||
rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #4");
|
||||
|
||||
map32.set( 42, 815);
|
||||
map64.set( Int64.make(0,42), 815);
|
||||
map32.set( -517, 23);
|
||||
map64.set( Int64.make(-5,17), 23);
|
||||
map32.set( 0, -123);
|
||||
map64.set( Int64.make(0,0), -123);
|
||||
|
||||
rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #10");
|
||||
rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #11");
|
||||
rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #12");
|
||||
rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #13");
|
||||
rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #14");
|
||||
rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #15");
|
||||
rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #16");
|
||||
rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #Int64.make(-5,17)");
|
||||
rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #18");
|
||||
rslt.Expect( map32.remove( 4711) == map64.remove( Int64.make(47,11)), "Int64Map<Int32> Test #19");
|
||||
rslt.Expect( map32.remove( -517) == map64.remove( Int64.make(-5,17)), "Int64Map<Int32> Test #20");
|
||||
rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #21");
|
||||
rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #22");
|
||||
rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #23");
|
||||
rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #24");
|
||||
rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #25");
|
||||
rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #26");
|
||||
rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #27");
|
||||
rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #28");
|
||||
|
||||
map32.set( 42, 1);
|
||||
map64.set( Int64.make(0,42), 1);
|
||||
map32.set( -517, -2);
|
||||
map64.set( Int64.make(-5,17), -2);
|
||||
map32.set( 0, 3);
|
||||
map64.set( Int64.make(0,0), 3);
|
||||
|
||||
var c32 = 0;
|
||||
for (key in map32.keys()) {
|
||||
++c32;
|
||||
}
|
||||
var c64 = 0;
|
||||
for (key in map64.keys()) {
|
||||
++c64;
|
||||
}
|
||||
rslt.Expect( c32 == c64, "Int64Map<Int32> Test #30");
|
||||
|
||||
var s32 = map32.toString();
|
||||
var s64 = map64.toString();
|
||||
trace("Int64Map<Int32>.toString(): " + ' ("$s32" == "$s64")');
|
||||
|
||||
map32.remove( 42);
|
||||
map64.remove( Int64.make(0,42));
|
||||
map32.remove( -517);
|
||||
map64.remove( Int64.make(-5,17));
|
||||
map32.remove( 0);
|
||||
map64.remove( Int64.make(0,0));
|
||||
|
||||
rslt.Expect( map32.keys().hasNext() == map64.keys().hasNext(), "Int64Map<Int32> Test #90");
|
||||
rslt.Expect( map32.exists( 4711) == map64.exists( Int64.make(47,11)), "Int64Map<Int32> Test #91");
|
||||
rslt.Expect( map32.exists( -517) == map64.exists( Int64.make(-5,17)), "Int64Map<Int32> Test #92");
|
||||
rslt.Expect( map32.exists( 42) == map64.exists( Int64.make(0,42)), "Int64Map<Int32> Test #93");
|
||||
rslt.Expect( map32.exists( 0) == map64.exists( Int64.make(0,0)), "Int64Map<Int32> Test #94");
|
||||
rslt.Expect( map32.get( 4711) == map64.get( Int64.make(47,11)), "Int64Map<Int32> Test #95");
|
||||
rslt.Expect( map32.get( -517) == map64.get( Int64.make(-5,17)), "Int64Map<Int32> Test #96");
|
||||
rslt.Expect( map32.get( 42) == map64.get( Int64.make(0,42)), "Int64Map<Int32> Test #97");
|
||||
rslt.Expect( map32.get( 0) == map64.get( Int64.make(0,0)), "Int64Map<Int32> Test #98");
|
||||
}
|
||||
|
||||
|
||||
public static function ClientTest( transport : TTransport, protocol : TProtocol, rslt : TestResults) : Void
|
||||
{
|
||||
var client = new ThriftTestImpl(protocol,protocol);
|
||||
try
|
||||
{
|
||||
if (!transport.isOpen())
|
||||
{
|
||||
transport.open();
|
||||
}
|
||||
}
|
||||
catch (e : TException)
|
||||
{
|
||||
trace('$e');
|
||||
return;
|
||||
}
|
||||
catch (e : Dynamic)
|
||||
{
|
||||
trace('$e');
|
||||
return;
|
||||
}
|
||||
|
||||
var start = Date.now();
|
||||
|
||||
trace('testVoid()');
|
||||
client.testVoid();
|
||||
trace(' = void');
|
||||
rslt.Expect(true,"testVoid()"); // bump counter
|
||||
|
||||
trace('testString("Test")');
|
||||
var s = client.testString("Test");
|
||||
trace(' = "$s"');
|
||||
rslt.Expect(s == "Test", '$s == "Test"');
|
||||
|
||||
trace('testByte(1)');
|
||||
var i8 = client.testByte(1);
|
||||
trace(' = $i8');
|
||||
rslt.Expect(i8 == 1, '$i8 == 1');
|
||||
|
||||
trace('testI32(-1)');
|
||||
var i32 = client.testI32(-1);
|
||||
trace(' = $i32');
|
||||
rslt.Expect(i32 == -1, '$i32 == -1');
|
||||
|
||||
trace('testI64(-34359738368)');
|
||||
var i64 = client.testI64( Int64.make( 0xFFFFFFF8, 0x00000000)); // -34359738368
|
||||
trace(' = $i64');
|
||||
rslt.Expect( Int64.compare( i64, Int64.make( 0xFFFFFFF8, 0x00000000)) == 0,
|
||||
Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0xFFFFFFF8, 0x00000000)));
|
||||
|
||||
// edge case: the largest negative Int64 has no positive Int64 equivalent
|
||||
trace('testI64(-9223372036854775808)');
|
||||
i64 = client.testI64( Int64.make( 0x80000000, 0x00000000)); // -9223372036854775808
|
||||
trace(' = $i64');
|
||||
rslt.Expect( Int64.compare( i64, Int64.make( 0x80000000, 0x00000000)) == 0,
|
||||
Int64.toStr(i64) +" == "+Int64.toStr(Int64.make( 0x80000000, 0x00000000)));
|
||||
|
||||
trace('testDouble(5.325098235)');
|
||||
var dub = client.testDouble(5.325098235);
|
||||
trace(' = $dub');
|
||||
rslt.Expect(dub == 5.325098235, '$dub == 5.325098235');
|
||||
|
||||
trace('testStruct({"Zero", 1, -3, -5})');
|
||||
var o = new Xtruct();
|
||||
o.string_thing = "Zero";
|
||||
o.byte_thing = 1;
|
||||
o.i32_thing = -3;
|
||||
o.i64_thing = Int64.make(0,-5);
|
||||
var i = client.testStruct(o);
|
||||
trace(' = {"' + i.string_thing + '", ' + i.byte_thing +', '
|
||||
+ i.i32_thing +', '+ Int64.toStr(i.i64_thing) + '}');
|
||||
rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
|
||||
rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
|
||||
rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
|
||||
rslt.Expect( i.i32_thing == o.i32_thing, "i.i64_thing == o.i64_thing");
|
||||
|
||||
trace('testNest({1, {\"Zero\", 1, -3, -5}, 5})');
|
||||
var o2 = new Xtruct2();
|
||||
o2.byte_thing = 1;
|
||||
o2.struct_thing = o;
|
||||
o2.i32_thing = 5;
|
||||
var i2 = client.testNest(o2);
|
||||
i = i2.struct_thing;
|
||||
trace(" = {" + i2.byte_thing + ", {\"" + i.string_thing + "\", "
|
||||
+ i.byte_thing + ", " + i.i32_thing + ", " + Int64.toStr(i.i64_thing) + "}, "
|
||||
+ i2.i32_thing + "}");
|
||||
rslt.Expect( i2.byte_thing == o2.byte_thing, "i2.byte_thing == o2.byte_thing");
|
||||
rslt.Expect( i2.i32_thing == o2.i32_thing, "i2.i32_thing == o2.i32_thing");
|
||||
rslt.Expect( i.string_thing == o.string_thing, "i.string_thing == o.string_thing");
|
||||
rslt.Expect( i.byte_thing == o.byte_thing, "i.byte_thing == o.byte_thing");
|
||||
rslt.Expect( i.i32_thing == o.i32_thing, "i.i32_thing == o.i32_thing");
|
||||
rslt.Expect( Int64.compare( i.i64_thing, o.i64_thing) == 0, "i.i64_thing == o.i64_thing");
|
||||
|
||||
var mapout = new IntMap< haxe.Int32>();
|
||||
for ( j in 0 ... 5)
|
||||
{
|
||||
mapout.set(j, j - 10);
|
||||
}
|
||||
trace("testMap({");
|
||||
var first : Bool = true;
|
||||
for( key in mapout.keys())
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
trace(", ");
|
||||
}
|
||||
trace(key + " => " + mapout.get(key));
|
||||
}
|
||||
trace("})");
|
||||
|
||||
var mapin = client.testMap(mapout);
|
||||
|
||||
trace(" = {");
|
||||
first = true;
|
||||
for( key in mapin.keys())
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
trace(", ");
|
||||
}
|
||||
trace(key + " => " + mapin.get(key));
|
||||
rslt.Expect( mapin.get(key) == mapout.get(key), ' mapin.get($key) == mapout.get($key)');
|
||||
}
|
||||
trace("}");
|
||||
for( key in mapout.keys())
|
||||
{
|
||||
rslt.Expect(mapin.exists(key), 'mapin.exists($key)');
|
||||
}
|
||||
|
||||
var listout = new List<Int>();
|
||||
for (j in -2 ... 3)
|
||||
{
|
||||
listout.add(j);
|
||||
}
|
||||
trace("testList({");
|
||||
first = true;
|
||||
for( j in listout)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
trace(", ");
|
||||
}
|
||||
trace(j);
|
||||
}
|
||||
trace("})");
|
||||
|
||||
var listin = client.testList(listout);
|
||||
|
||||
trace(" = {");
|
||||
first = true;
|
||||
for( j in listin)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
trace(", ");
|
||||
}
|
||||
trace(j);
|
||||
}
|
||||
trace("}");
|
||||
|
||||
rslt.Expect(listin.length == listout.length, "listin.length == listout.length");
|
||||
var literout = listout.iterator();
|
||||
var literin = listin.iterator();
|
||||
while( literin.hasNext()) {
|
||||
rslt.Expect(literin.next() == literout.next(), "literin[i] == literout[i]");
|
||||
}
|
||||
|
||||
//set
|
||||
var setout = new IntSet();
|
||||
for (j in -2 ... 3)
|
||||
{
|
||||
setout.add(j);
|
||||
}
|
||||
trace("testSet({");
|
||||
first = true;
|
||||
for( j in setout)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
trace(", ");
|
||||
}
|
||||
trace(j);
|
||||
}
|
||||
trace("})");
|
||||
|
||||
var setin = client.testSet(setout);
|
||||
|
||||
trace(" = {");
|
||||
first = true;
|
||||
for( j in setin)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
trace(", ");
|
||||
}
|
||||
trace(j);
|
||||
rslt.Expect(setout.contains(j), 'setout.contains($j)');
|
||||
}
|
||||
trace("}");
|
||||
rslt.Expect(setin.size == setout.size, "setin.length == setout.length");
|
||||
|
||||
|
||||
trace("testEnum(ONE)");
|
||||
var ret = client.testEnum(Numberz.ONE);
|
||||
trace(" = " + ret);
|
||||
rslt.Expect(ret == Numberz.ONE, '$ret == Numberz.ONE');
|
||||
|
||||
trace("testEnum(TWO)");
|
||||
ret = client.testEnum(Numberz.TWO);
|
||||
trace(" = " + ret);
|
||||
rslt.Expect(ret == Numberz.TWO, '$ret == Numberz.TWO');
|
||||
|
||||
trace("testEnum(THREE)");
|
||||
ret = client.testEnum(Numberz.THREE);
|
||||
trace(" = " + ret);
|
||||
rslt.Expect(ret == Numberz.THREE, '$ret == Numberz.THREE');
|
||||
|
||||
trace("testEnum(FIVE)");
|
||||
ret = client.testEnum(Numberz.FIVE);
|
||||
trace(" = " + ret);
|
||||
rslt.Expect(ret == Numberz.FIVE, '$ret == Numberz.FIVE');
|
||||
|
||||
trace("testEnum(EIGHT)");
|
||||
ret = client.testEnum(Numberz.EIGHT);
|
||||
trace(" = " + ret);
|
||||
rslt.Expect(ret == Numberz.EIGHT, '$ret == Numberz.EIGHT');
|
||||
|
||||
trace("testTypedef(309858235082523)");
|
||||
var uid = client.testTypedef( Int64.make( 0x119D0, 0x7E08671B)); // 309858235082523
|
||||
trace(" = " + uid);
|
||||
rslt.Expect( Int64.compare( uid, Int64.make( 0x119D0, 0x7E08671B)) == 0,
|
||||
Int64.toStr(uid)+" == "+Int64.toStr(Int64.make( 0x119D0, 0x7E08671B)));
|
||||
|
||||
trace("testMapMap(1)");
|
||||
var mm = client.testMapMap(1);
|
||||
trace(" = {");
|
||||
for( key in mm.keys())
|
||||
{
|
||||
trace(key + " => {");
|
||||
var m2 = mm.get(key);
|
||||
for( k2 in m2.keys())
|
||||
{
|
||||
trace(k2 + " => " + m2.get(k2) + ", ");
|
||||
}
|
||||
trace("}, ");
|
||||
}
|
||||
trace("}");
|
||||
|
||||
var pos = mm.get(4);
|
||||
var neg = mm.get(-4);
|
||||
rslt.Expect( (pos != null) && (neg != null), "(pos != null) && (neg != null)");
|
||||
for (i in 0 ... 5) {
|
||||
rslt.Expect( pos.get(i) == i, 'pos.get($i) == $i');
|
||||
rslt.Expect( neg.get(-i) == -i, 'neg.get(-$i) == -$i');
|
||||
}
|
||||
|
||||
var insane = new Insanity();
|
||||
insane.userMap = new IntMap< Int64>();
|
||||
insane.userMap.set( Numberz.FIVE, Int64.make(0,5000));
|
||||
var truck = new Xtruct();
|
||||
truck.string_thing = "Truck";
|
||||
truck.byte_thing = 8;
|
||||
truck.i32_thing = 8;
|
||||
truck.i64_thing = Int64.make(0,8);
|
||||
insane.xtructs = new List<Xtruct>();
|
||||
insane.xtructs.add(truck);
|
||||
trace("testInsanity()");
|
||||
var whoa = client.testInsanity(insane);
|
||||
trace(" = {");
|
||||
for( key in whoa.keys())
|
||||
{
|
||||
var val = whoa.get(key);
|
||||
trace(key + " => {");
|
||||
|
||||
for( k2 in val.keys())
|
||||
{
|
||||
var v2 = val.get(k2);
|
||||
|
||||
trace(k2 + " => {");
|
||||
var userMap = v2.userMap;
|
||||
|
||||
trace("{");
|
||||
if (userMap != null)
|
||||
{
|
||||
for( k3 in userMap.keys())
|
||||
{
|
||||
trace(k3 + " => " + userMap.get(k3) + ", ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
trace("null");
|
||||
}
|
||||
trace("}, ");
|
||||
|
||||
var xtructs = v2.xtructs;
|
||||
|
||||
trace("{");
|
||||
if (xtructs != null)
|
||||
{
|
||||
for( x in xtructs)
|
||||
{
|
||||
trace("{\"" + x.string_thing + "\", "
|
||||
+ x.byte_thing + ", " + x.i32_thing + ", "
|
||||
+ x.i32_thing + "}, ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
trace("null");
|
||||
}
|
||||
trace("}");
|
||||
|
||||
trace("}, ");
|
||||
}
|
||||
trace("}, ");
|
||||
}
|
||||
trace("}");
|
||||
|
||||
var first_map = whoa.get(Int64.make(0,1));
|
||||
var second_map = whoa.get(Int64.make(0,2));
|
||||
rslt.Expect( (first_map != null) && (second_map != null), "(first_map != null) && (second_map != null)");
|
||||
if ((first_map != null) && (second_map != null))
|
||||
{
|
||||
var crazy2 = first_map.get(Numberz.TWO);
|
||||
var crazy3 = first_map.get(Numberz.THREE);
|
||||
var looney = second_map.get(Numberz.SIX);
|
||||
rslt.Expect( (crazy2 != null) && (crazy3 != null) && (looney != null),
|
||||
"(crazy2 != null) && (crazy3 != null) && (looney != null)");
|
||||
|
||||
rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
|
||||
"crazy2.UserMap.get(Numberz.EIGHT) == 8");
|
||||
rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.EIGHT), Int64.make(0,8)) == 0,
|
||||
"crazy3.UserMap.get(Numberz.EIGHT) == 8");
|
||||
rslt.Expect( Int64.compare( crazy2.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
|
||||
"crazy2.UserMap.get(Numberz.FIVE) == 5");
|
||||
rslt.Expect( Int64.compare( crazy3.userMap.get(Numberz.FIVE), Int64.make(0,5)) == 0,
|
||||
"crazy3.UserMap.get(Numberz.FIVE) == 5");
|
||||
|
||||
var crz2iter = crazy2.xtructs.iterator();
|
||||
var crz3iter = crazy3.xtructs.iterator();
|
||||
rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
|
||||
var goodbye2 = crz2iter.next();
|
||||
var goodbye3 = crz3iter.next();
|
||||
rslt.Expect( crz2iter.hasNext() && crz3iter.hasNext(), "crz2iter.hasNext() && crz3iter.hasNext()");
|
||||
var hello2 = crz2iter.next();
|
||||
var hello3 = crz3iter.next();
|
||||
rslt.Expect( ! (crz2iter.hasNext() || crz3iter.hasNext()), "! (crz2iter.hasNext() || crz3iter.hasNext())");
|
||||
|
||||
rslt.Expect( hello2.string_thing == "Hello2", 'hello2.String_thing == "Hello2"');
|
||||
rslt.Expect( hello2.byte_thing == 2, 'hello2.Byte_thing == 2');
|
||||
rslt.Expect( hello2.i32_thing == 2, 'hello2.I32_thing == 2');
|
||||
rslt.Expect( Int64.compare( hello2.i64_thing, Int64.make(0,2)) == 0, 'hello2.I64_thing == 2');
|
||||
rslt.Expect( hello3.string_thing == "Hello2", 'hello3.String_thing == "Hello2"');
|
||||
rslt.Expect( hello3.byte_thing == 2, 'hello3.Byte_thing == 2');
|
||||
rslt.Expect( hello3.i32_thing == 2, 'hello3.I32_thing == 2');
|
||||
rslt.Expect( Int64.compare( hello3.i64_thing, Int64.make(0,2)) == 0, 'hello3.I64_thing == 2');
|
||||
|
||||
rslt.Expect( goodbye2.string_thing == "Goodbye4", 'goodbye2.String_thing == "Goodbye4"');
|
||||
rslt.Expect( goodbye2.byte_thing == 4, 'goodbye2.Byte_thing == 4');
|
||||
rslt.Expect( goodbye2.i32_thing == 4, 'goodbye2.I32_thing == 4');
|
||||
rslt.Expect( Int64.compare( goodbye2.i64_thing, Int64.make(0,4)) == 0, 'goodbye2.I64_thing == 4');
|
||||
rslt.Expect( goodbye3.string_thing == "Goodbye4", 'goodbye3.String_thing == "Goodbye4"');
|
||||
rslt.Expect( goodbye3.byte_thing == 4, 'goodbye3.Byte_thing == 4');
|
||||
rslt.Expect( goodbye3.i32_thing == 4, 'goodbye3.I32_thing == 4');
|
||||
rslt.Expect( Int64.compare( goodbye3.i64_thing, Int64.make(0,4)) == 0, 'goodbye3.I64_thing == 4');
|
||||
}
|
||||
|
||||
var arg0 = 1;
|
||||
var arg1 = 2;
|
||||
var arg2 = Int64.make( 0x7FFFFFFF,0xFFFFFFFF);
|
||||
var multiDict = new IntMap< String>();
|
||||
multiDict.set(1, "one");
|
||||
var arg4 = Numberz.FIVE;
|
||||
var arg5 = Int64.make(0,5000000);
|
||||
trace("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")");
|
||||
var multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5);
|
||||
trace(" = Xtruct(byte_thing:" + multiResponse.byte_thing + ",string_thing:" + multiResponse.string_thing
|
||||
+ ",i32_thing:" + multiResponse.i32_thing
|
||||
+ ",i64_thing:" + Int64.toStr(multiResponse.i64_thing) + ")");
|
||||
|
||||
rslt.Expect( multiResponse.string_thing == "Hello2", 'multiResponse.String_thing == "Hello2"');
|
||||
rslt.Expect( multiResponse.byte_thing == arg0, 'multiResponse.Byte_thing == arg0');
|
||||
rslt.Expect( multiResponse.i32_thing == arg1, 'multiResponse.I32_thing == arg1');
|
||||
rslt.Expect( Int64.compare( multiResponse.i64_thing, arg2) == 0, 'multiResponse.I64_thing == arg2');
|
||||
|
||||
|
||||
trace("Test Oneway(1)");
|
||||
client.testOneway(1);
|
||||
|
||||
trace("Test Calltime()");
|
||||
var difft = Timer.stamp();
|
||||
for ( k in 0 ... 1000) {
|
||||
client.testVoid();
|
||||
}
|
||||
difft = Timer.stamp() - difft;
|
||||
trace('$difft ms per testVoid() call');
|
||||
}
|
||||
}
|
106
test/haxe/src/TestServer.hx
Normal file
106
test/haxe/src/TestServer.hx
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
import thrift.test.*; // generated code
|
||||
|
||||
|
||||
class TestServer
|
||||
{
|
||||
public static function Execute(args : Arguments) : Void
|
||||
{
|
||||
try
|
||||
{
|
||||
// Transport
|
||||
var transport : TServerTransport = null;
|
||||
switch( args.transport) {
|
||||
case socket:
|
||||
trace("- socket port "+args.port);
|
||||
transport = new TServerSocket( args.port);
|
||||
case http:
|
||||
trace("- http");
|
||||
throw "HTTP server not implemented yet";
|
||||
//transport = new THttpServer( targetHost);
|
||||
default:
|
||||
throw "Unhandled transport";
|
||||
}
|
||||
|
||||
// optional: layered transport
|
||||
var transfactory : TTransportFactory = null;
|
||||
if ( args.framed) {
|
||||
trace("- framed transport");
|
||||
transfactory = new TFramedTransportFactory();
|
||||
} else if ( args.buffered) {
|
||||
trace("- buffered transport");
|
||||
throw "TBufferedTransport not implemented yet";
|
||||
//transfactory = new TBufferedTransportFactory();
|
||||
}
|
||||
|
||||
// protocol
|
||||
var protfactory : TProtocolFactory = null;
|
||||
switch( args.protocol)
|
||||
{
|
||||
case binary:
|
||||
trace("- binary protocol");
|
||||
protfactory = new TBinaryProtocolFactory();
|
||||
case json:
|
||||
trace("- json protocol");
|
||||
protfactory = new TJSONProtocolFactory();
|
||||
default:
|
||||
throw "Unhandled protocol";
|
||||
}
|
||||
|
||||
|
||||
// Processor
|
||||
var handler = new TestServerHandler();
|
||||
var processor = new ThriftTestProcessor(handler);
|
||||
|
||||
// Simple Server
|
||||
var server = new TSimpleServer( processor, transport, transfactory, protfactory);
|
||||
|
||||
|
||||
/*
|
||||
// Server event handler
|
||||
var events = new TestServerEventHandler();
|
||||
server.setEventHandler(serverEvents);
|
||||
handler.server = serverEngine;
|
||||
*/
|
||||
|
||||
// Run it
|
||||
server.Serve();
|
||||
trace("done.");
|
||||
|
||||
}
|
||||
catch (x : TException)
|
||||
{
|
||||
trace('$x');
|
||||
}
|
||||
catch (x : Dynamic)
|
||||
{
|
||||
trace('$x');
|
||||
}
|
||||
}
|
||||
}
|
53
test/haxe/src/TestServerEventHandler.hx
Normal file
53
test/haxe/src/TestServerEventHandler.hx
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
import thrift.test.*; // generated code
|
||||
|
||||
|
||||
class TestServerEventHandler : TServerEventHandler
|
||||
{
|
||||
public int callCount = 0;
|
||||
public void preServe()
|
||||
{
|
||||
callCount++;
|
||||
}
|
||||
public Object createContext(Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output)
|
||||
{
|
||||
callCount++;
|
||||
return null;
|
||||
}
|
||||
public void deleteContext(Object serverContext, Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output)
|
||||
{
|
||||
callCount++;
|
||||
}
|
||||
public void processContext(Object serverContext, Thrift.Transport.TTransport transport)
|
||||
{
|
||||
callCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
470
test/haxe/src/TestServerHandler.hx
Normal file
470
test/haxe/src/TestServerHandler.hx
Normal file
@ -0,0 +1,470 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
import org.apache.thrift.helper.*;
|
||||
|
||||
import haxe.Int32;
|
||||
import haxe.Int64;
|
||||
import haxe.io.Bytes;
|
||||
import haxe.ds.IntMap;
|
||||
import haxe.ds.StringMap;
|
||||
import haxe.ds.ObjectMap;
|
||||
|
||||
import thrift.test.*; // generated code
|
||||
|
||||
|
||||
class TestServerHandler implements ThriftTest {
|
||||
|
||||
public var server:TServer;
|
||||
|
||||
public function new() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints "testVoid()" and returns nothing.
|
||||
*/
|
||||
public function testVoid():Void
|
||||
{
|
||||
trace("testVoid()");
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testString("%s")' with thing as '%s'
|
||||
* @param string thing - the string to print
|
||||
* @return string - returns the string 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testString(thing:String):String
|
||||
{
|
||||
trace("teststring(\"" + thing + "\")");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testByte("%d")' with thing as '%d'
|
||||
* @param byte thing - the byte to print
|
||||
* @return byte - returns the byte 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testByte(thing:haxe.Int32):haxe.Int32
|
||||
{
|
||||
trace("testByte(" + thing + ")");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testI32("%d")' with thing as '%d'
|
||||
* @param i32 thing - the i32 to print
|
||||
* @return i32 - returns the i32 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testI32(thing:haxe.Int32):haxe.Int32
|
||||
{
|
||||
trace("testI32(" + thing + ")");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testI64("%d")' with thing as '%d'
|
||||
* @param i64 thing - the i64 to print
|
||||
* @return i64 - returns the i64 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testI64(thing:haxe.Int64):haxe.Int64
|
||||
{
|
||||
trace("testI64(" + thing + ")");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testDouble("%f")' with thing as '%f'
|
||||
* @param double thing - the double to print
|
||||
* @return double - returns the double 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testDouble(thing:Float):Float
|
||||
{
|
||||
trace("testDouble(" + thing + ")");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testStruct("{%s}")' where thing has been formatted
|
||||
* into a string of comma seperated values
|
||||
* @param Xtruct thing - the Xtruct to print
|
||||
* @return Xtruct - returns the Xtruct 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testStruct(thing:Xtruct):Xtruct
|
||||
{
|
||||
trace("testStruct({" +
|
||||
"\"" + thing.string_thing + "\", " +
|
||||
thing.byte_thing + ", " +
|
||||
thing.i32_thing + ", " +
|
||||
Int64.toStr(thing.i64_thing) + "})");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testNest("{%s}")' where thing has been formatted
|
||||
* into a string of the nested struct
|
||||
* @param Xtruct2 thing - the Xtruct2 to print
|
||||
* @return Xtruct2 - returns the Xtruct2 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testNest(nest:Xtruct2):Xtruct2
|
||||
{
|
||||
var thing:Xtruct = nest.struct_thing;
|
||||
trace("testNest({" +
|
||||
nest.byte_thing + ", {" +
|
||||
"\"" + thing.string_thing + "\", " +
|
||||
thing.byte_thing + ", " +
|
||||
thing.i32_thing + ", " +
|
||||
Int64.toStr(thing.i64_thing) + "}, " +
|
||||
nest.i32_thing + "})");
|
||||
return nest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testMap("{%s")' where thing has been formatted
|
||||
* into a string of 'key => value' pairs
|
||||
* seperated by commas and new lines
|
||||
* @param map<i32,i32> thing - the map<i32,i32> to print
|
||||
* @return map<i32,i32> - returns the map<i32,i32> 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testMap(thing:IntMap<haxe.Int32>):IntMap<haxe.Int32>
|
||||
{
|
||||
trace("testMap({");
|
||||
var first:Bool = true;
|
||||
for (key in thing.keys()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
trace(", ");
|
||||
};
|
||||
trace(key + " => " + thing.get(key));
|
||||
};
|
||||
trace("})");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testStringMap("{%s}")' where thing has been formatted
|
||||
* into a string of 'key => value' pairs
|
||||
* seperated by commas and new lines
|
||||
* @param map<string,string> thing - the map<string,string> to print
|
||||
* @return map<string,string> - returns the map<string,string> 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testStringMap(thing:StringMap<String>):StringMap<String>
|
||||
{
|
||||
trace("testStringMap({");
|
||||
var first:Bool = true;
|
||||
for (key in thing.keys()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
trace(", ");
|
||||
};
|
||||
trace(key + " => " + thing.get(key));
|
||||
};
|
||||
trace("})");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testSet("{%s}")' where thing has been formatted
|
||||
* into a string of values
|
||||
* seperated by commas and new lines
|
||||
* @param set<i32> thing - the set<i32> to print
|
||||
* @return set<i32> - returns the set<i32> 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testSet(thing:IntSet):IntSet
|
||||
{
|
||||
trace("testSet({");
|
||||
var first:Bool = true;
|
||||
for (elem in thing) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
trace(", ");
|
||||
};
|
||||
trace(elem);
|
||||
};
|
||||
trace("})");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testList("{%s}")' where thing has been formatted
|
||||
* into a string of values
|
||||
* seperated by commas and new lines
|
||||
* @param list<i32> thing - the list<i32> to print
|
||||
* @return list<i32> - returns the list<i32> 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testList(thing:List<haxe.Int32>):List<haxe.Int32>
|
||||
{
|
||||
trace("testList({");
|
||||
var first:Bool = true;
|
||||
for (elem in thing) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
trace(", ");
|
||||
};
|
||||
trace(elem);
|
||||
};
|
||||
trace("})");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
|
||||
* @param Numberz thing - the Numberz to print
|
||||
* @return Numberz - returns the Numberz 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testEnum(thing:Int):Int
|
||||
{
|
||||
trace("testEnum(" + thing + ")");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testTypedef("%d")' with thing as '%d'
|
||||
* @param UserId thing - the UserId to print
|
||||
* @return UserId - returns the UserId 'thing'
|
||||
*
|
||||
* @param thing
|
||||
*/
|
||||
public function testTypedef(thing:haxe.Int64):haxe.Int64
|
||||
{
|
||||
trace("testTypedef(" + thing + ")");
|
||||
return thing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testMapMap("%d")' with hello as '%d'
|
||||
* @param i32 hello - the i32 to print
|
||||
* @return map<i32,map<i32,i32>> - returns a dictionary with these values:
|
||||
* {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, },
|
||||
* 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
|
||||
*
|
||||
* @param hello
|
||||
*/
|
||||
public function testMapMap(hello:haxe.Int32):IntMap<IntMap<haxe.Int32>>
|
||||
{
|
||||
trace("testMapMap(" + hello + ")");
|
||||
var mapmap = new IntMap<IntMap<Int>>();
|
||||
var pos = new IntMap<Int>();
|
||||
var neg = new IntMap<Int>();
|
||||
for (i in 1 ... 5) {
|
||||
pos.set(i, i);
|
||||
neg.set(-i, -i);
|
||||
};
|
||||
mapmap.set(4, pos);
|
||||
mapmap.set(-4, neg);
|
||||
return mapmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* So you think you've got this all worked, out eh?
|
||||
*
|
||||
* Creates a the returned map with these values and prints it out:
|
||||
* { 1 => { 2 => argument,
|
||||
* 3 => argument,
|
||||
* },
|
||||
* 2 => { 6 => <empty Insanity struct>, },
|
||||
* }
|
||||
* @return map<UserId, map<Numberz,Insanity>> - a map with the above values
|
||||
*
|
||||
* @param argument
|
||||
*/
|
||||
public function testInsanity(argument : Insanity) : Int64Map< IntMap< Insanity>>
|
||||
{
|
||||
trace("testInsanity()");
|
||||
|
||||
var hello = new Xtruct();
|
||||
hello.string_thing = "Hello2";
|
||||
hello.byte_thing = 2;
|
||||
hello.i32_thing = 2;
|
||||
hello.i64_thing = Int64.make(0, 2);
|
||||
|
||||
var goodbye = new Xtruct();
|
||||
goodbye.string_thing = "Goodbye4";
|
||||
goodbye.byte_thing = 4;
|
||||
goodbye.i32_thing = 4;
|
||||
goodbye.i64_thing = Int64.make(0, 4);
|
||||
|
||||
var crazy = new Insanity();
|
||||
crazy.userMap = new IntMap< haxe.Int64>();
|
||||
crazy.userMap.set(Numberz.EIGHT, Int64.make(0,8));
|
||||
crazy.xtructs = new List<Xtruct>();
|
||||
crazy.xtructs.add(goodbye);
|
||||
|
||||
var looney = new Insanity();
|
||||
crazy.userMap.set(Numberz.FIVE, Int64.make(0,5));
|
||||
crazy.xtructs.add(hello);
|
||||
|
||||
var first_map = new IntMap< Insanity>();
|
||||
first_map.set(Numberz.TWO, crazy);
|
||||
first_map.set(Numberz.THREE, crazy);
|
||||
|
||||
var second_map = new IntMap< Insanity>();
|
||||
second_map.set(Numberz.SIX, looney);
|
||||
|
||||
var insane = new Int64Map< IntMap< Insanity>>();
|
||||
insane.set( Int64.make(0,1), first_map);
|
||||
insane.set( Int64.make(0,2), second_map);
|
||||
|
||||
return insane;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints 'testMulti()'
|
||||
* @param byte arg0 -
|
||||
* @param i32 arg1 -
|
||||
* @param i64 arg2 -
|
||||
* @param map<i16, string> arg3 -
|
||||
* @param Numberz arg4 -
|
||||
* @param UserId arg5 -
|
||||
* @return Xtruct - returns an Xtruct
|
||||
* with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
|
||||
* and i64_thing = arg2
|
||||
*
|
||||
* @param arg0
|
||||
* @param arg1
|
||||
* @param arg2
|
||||
* @param arg3
|
||||
* @param arg4
|
||||
* @param arg5
|
||||
*/
|
||||
public function testMulti(arg0:haxe.Int32, arg1:haxe.Int32, arg2:haxe.Int64,
|
||||
arg3:IntMap<String>, arg4:Int, arg5:haxe.Int64):Xtruct
|
||||
{
|
||||
trace("testMulti()");
|
||||
var hello = new Xtruct();
|
||||
hello.string_thing = "Hello2";
|
||||
hello.byte_thing = arg0;
|
||||
hello.i32_thing = arg1;
|
||||
hello.i64_thing = arg2;
|
||||
return hello;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print 'testException(%s)' with arg as '%s'
|
||||
* @param string arg - a string indication what type of exception to throw
|
||||
* if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
|
||||
* elsen if arg == "TException" throw TException
|
||||
* else do not throw anything
|
||||
*
|
||||
* @param arg
|
||||
*/
|
||||
public function testException(arg:String):Void
|
||||
{
|
||||
trace("testException(" + arg + ")");
|
||||
if (arg == "Xception") {
|
||||
var x = new Xception();
|
||||
x.errorCode = 1001;
|
||||
x.message = arg;
|
||||
throw x;
|
||||
};
|
||||
if (arg == "TException") {
|
||||
throw new TException();
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
|
||||
* @param string arg - a string indication what type of exception to throw
|
||||
* if arg0 == "Xception"
|
||||
* throw Xception with errorCode = 1001 and message = "This is an Xception"
|
||||
* else if arg0 == "Xception2"
|
||||
* throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
|
||||
* else do not throw anything
|
||||
* @return Xtruct - an Xtruct with string_thing = arg1
|
||||
*
|
||||
* @param arg0
|
||||
* @param arg1
|
||||
*/
|
||||
public function testMultiException(arg0:String, arg1:String):Xtruct
|
||||
{
|
||||
trace("testMultiException(" + arg0 + ", " + arg1 + ")");
|
||||
if (arg0 == "Xception") {
|
||||
var x = new Xception();
|
||||
x.errorCode = 1001;
|
||||
x.message = "This is an Xception";
|
||||
throw x;
|
||||
} else if (arg0 == "Xception2") {
|
||||
var x = new Xception2();
|
||||
x.errorCode = 2002;
|
||||
x.struct_thing = new Xtruct();
|
||||
x.struct_thing.string_thing = "This is an Xception2";
|
||||
throw x;
|
||||
};
|
||||
var result = new Xtruct();
|
||||
result.string_thing = arg1;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
|
||||
* sleep 'secondsToSleep'
|
||||
* Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
|
||||
* @param i32 secondsToSleep - the number of seconds to sleep
|
||||
*
|
||||
* @param secondsToSleep
|
||||
*/
|
||||
public function testOneway(secondsToSleep:haxe.Int32):Void
|
||||
{
|
||||
trace("testOneway(" + secondsToSleep + "), sleeping...");
|
||||
Sys.sleep(secondsToSleep);
|
||||
trace("testOneway finished");
|
||||
}
|
||||
|
||||
public function testStop():Void
|
||||
{
|
||||
if (server != null) {
|
||||
server.Stop();
|
||||
};
|
||||
}
|
||||
}
|
@ -50,6 +50,10 @@ if WITH_HASKELL
|
||||
SUBDIRS += hs
|
||||
endif
|
||||
|
||||
if WITH_HAXE
|
||||
SUBDIRS += haxe
|
||||
endif
|
||||
|
||||
if WITH_GO
|
||||
SUBDIRS += go
|
||||
endif
|
||||
|
50
tutorial/haxe/Makefile.am
Normal file
50
tutorial/haxe/Makefile.am
Normal file
@ -0,0 +1,50 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
|
||||
gen-haxe/tutorial/calculator.hx gen-haxe/shared/shared_service.hx: $(top_srcdir)/tutorial/tutorial.thrift
|
||||
$(THRIFT) --gen haxe -r $<
|
||||
|
||||
all-local: bin/Main-debug
|
||||
|
||||
check: gen-haxe/tutorial/calculator.hx
|
||||
|
||||
bin/Main-debug: gen-haxe/tutorial/calculator.hx
|
||||
$(HAXE) --cwd . cpp.hxml
|
||||
|
||||
tutorialserver: all
|
||||
bin/Main-debug server
|
||||
|
||||
tutorialclient: all
|
||||
bin/Main-debug
|
||||
|
||||
tutorialsecureserver: all
|
||||
bin/Main-debug server secure
|
||||
|
||||
tutorialsecureclient: all
|
||||
bin/Main-debug secure
|
||||
|
||||
clean-local:
|
||||
$(RM) -r gen-haxe bin
|
||||
|
||||
EXTRA_DIST = \
|
||||
src/Main.hx \
|
||||
src/CalculatorHandler.hx
|
||||
|
41
tutorial/haxe/cpp.hxml
Normal file
41
tutorial/haxe/cpp.hxml
Normal file
@ -0,0 +1,41 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#CPP target
|
||||
-cpp bin
|
||||
|
||||
#To produce 64 bit binaries the file should define the HXCPP_M64 compile variable:
|
||||
#-D HXCPP_M64
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
38
tutorial/haxe/csharp.hxml
Normal file
38
tutorial/haxe/csharp.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#CSHARP target
|
||||
-cs bin/Tutorial.exe
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
41
tutorial/haxe/flash.hxml
Normal file
41
tutorial/haxe/flash.hxml
Normal file
@ -0,0 +1,41 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#Flash target
|
||||
-swf bin/Tutorial.swf
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
# we need some goodies from sys.net
|
||||
# --macro allowPackage("sys")
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
38
tutorial/haxe/java.hxml
Normal file
38
tutorial/haxe/java.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#Java target
|
||||
-java bin/Tutorial.jar
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
44
tutorial/haxe/javascript.hxml
Normal file
44
tutorial/haxe/javascript.hxml
Normal file
@ -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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#JavaScript target
|
||||
-js bin/Tutorial.js
|
||||
|
||||
#You can use -D source-map-content (requires Haxe 3.1+) to have the .hx
|
||||
#files directly embedded into the map file, this way you only have to
|
||||
#upload it, and it will be always in sync with the compiled .js even if
|
||||
#you modify your .hx files.
|
||||
-D source-map-content
|
||||
|
||||
#Generate source map and add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
68
tutorial/haxe/make_all.bat
Normal file
68
tutorial/haxe/make_all.bat
Normal file
@ -0,0 +1,68 @@
|
||||
@echo off
|
||||
rem /*
|
||||
rem * Licensed to the Apache Software Foundation (ASF) under one
|
||||
rem * or more contributor license agreements. See the NOTICE file
|
||||
rem * distributed with this work for additional information
|
||||
rem * regarding copyright ownership. The ASF licenses this file
|
||||
rem * to you under the Apache License, Version 2.0 (the
|
||||
rem * "License"); you may not use this file except in compliance
|
||||
rem * with the License. You may obtain a copy of the License at
|
||||
rem *
|
||||
rem * http://www.apache.org/licenses/LICENSE-2.0
|
||||
rem *
|
||||
rem * Unless required by applicable law or agreed to in writing,
|
||||
rem * software distributed under the License is distributed on an
|
||||
rem * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
rem * KIND, either express or implied. See the License for the
|
||||
rem * specific language governing permissions and limitations
|
||||
rem * under the License.
|
||||
rem */
|
||||
|
||||
setlocal
|
||||
if "%HOMEDRIVE%"=="" goto MISSINGVARS
|
||||
if "%HOMEPATH%"=="" goto MISSINGVARS
|
||||
if "%HAXEPATH%"=="" goto NOTINSTALLED
|
||||
|
||||
set path=%HAXEPATH%;%HAXEPATH%\..\neko;%path%
|
||||
|
||||
rem # invoke Thrift comnpiler
|
||||
thrift -r -gen haxe ..\tutorial.thrift
|
||||
if errorlevel 1 goto STOP
|
||||
|
||||
rem # invoke Haxe compiler for all targets
|
||||
for %%a in (*.hxml) do (
|
||||
rem * filter Python, as it is not supported by Haxe 3.1.3 (but will be in 3.1.4)
|
||||
if not "%%a"=="python.hxml" (
|
||||
echo --------------------------
|
||||
echo Building %%a ...
|
||||
echo --------------------------
|
||||
haxe --cwd . %%a
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
echo.
|
||||
echo done.
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:NOTINSTALLED
|
||||
echo FATAL: Either Haxe is not installed, or the HAXEPATH variable is not set.
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:MISSINGVARS
|
||||
echo FATAL: Unable to locate home folder.
|
||||
echo.
|
||||
echo Both HOMEDRIVE and HOMEPATH need to be set to point to your Home folder.
|
||||
echo The current values are:
|
||||
echo HOMEDRIVE=%HOMEDRIVE%
|
||||
echo HOMEPATH=%HOMEPATH%
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:STOP
|
||||
pause
|
||||
goto eof
|
||||
|
||||
:eof
|
41
tutorial/haxe/make_all.sh
Normal file
41
tutorial/haxe/make_all.sh
Normal file
@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# invoke Thrift comnpiler
|
||||
thrift -r -gen haxe ../tutorial.thrift
|
||||
|
||||
# output folder
|
||||
if [ ! -d bin ]; then
|
||||
mkdir bin
|
||||
fi
|
||||
|
||||
# invoke Haxe compoiler
|
||||
for target in *.hxml; do
|
||||
echo --------------------------
|
||||
echo Building ${target} ...
|
||||
echo --------------------------
|
||||
if [ ! -d bin/${target} ]; then
|
||||
mkdir bin/${target}
|
||||
fi
|
||||
haxe --cwd . ${target}
|
||||
done
|
||||
|
||||
|
||||
#eof
|
38
tutorial/haxe/neko.hxml
Normal file
38
tutorial/haxe/neko.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#neko target
|
||||
-neko bin/Tutorial.n
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
38
tutorial/haxe/php.hxml
Normal file
38
tutorial/haxe/php.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#PHP target
|
||||
-php bin/Tutorial.php
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
105
tutorial/haxe/project.hide
Normal file
105
tutorial/haxe/project.hide
Normal file
@ -0,0 +1,105 @@
|
||||
{
|
||||
"type" : 0
|
||||
,"target" : 4
|
||||
,"name" : "Apache Thrift Tutorial"
|
||||
,"main" : null
|
||||
,"projectPackage" : ""
|
||||
,"company" : "Apache Software Foundation (ASF)"
|
||||
,"license" : "Apache License, Version 2.0"
|
||||
,"url" : "http://www.apache.org/licenses/LICENSE-2.0"
|
||||
,"targetData" : [
|
||||
{
|
||||
"pathToHxml" : "flash.hxml"
|
||||
,"runActionType" : 1
|
||||
,"runActionText" : "bin/Tutorial.swf"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "javascript.hxml"
|
||||
,"runActionType" : 1
|
||||
,"runActionText" : "bin\\index.html"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "neko.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "neko bin/Tutorial.n"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "php.hxml"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "cpp.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "bin/Main-debug.exe"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "java.hxml"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "csharp.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "bin\\Tutorial.exe\\bin\\Main-Debug.exe"
|
||||
}
|
||||
,{
|
||||
"pathToHxml" : "python.hxml"
|
||||
,"runActionType" : 2
|
||||
,"runActionText" : "python bin/Tutorial.py"
|
||||
}
|
||||
]
|
||||
,"files" : [
|
||||
{
|
||||
"path" : "src\\org\\apache\\thrift\\server\\TServer.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 76
|
||||
}
|
||||
,{
|
||||
"path" : "src\\org\\apache\\thrift\\server\\TSimpleServer.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 100
|
||||
}
|
||||
,{
|
||||
"path" : "src\\shared\\SharedServiceProcessor.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 20
|
||||
}
|
||||
,{
|
||||
"path" : "src\\tutorial\\CalculatorProcessor.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 79
|
||||
}
|
||||
,{
|
||||
"path" : "src\\Main.hx"
|
||||
,"useTabs" : true
|
||||
,"indentSize" : 4
|
||||
,"foldedRegions" : [
|
||||
|
||||
]
|
||||
,"activeLine" : 276
|
||||
}
|
||||
]
|
||||
,"activeFile" : "src\\Main.hx"
|
||||
,"openFLTarget" : null
|
||||
,"openFLBuildMode" : "Debug"
|
||||
,"runActionType" : null
|
||||
,"runActionText" : null
|
||||
,"buildActionCommand" : null
|
||||
,"hiddenItems" : [
|
||||
|
||||
]
|
||||
,"showHiddenItems" : false
|
||||
}
|
38
tutorial/haxe/python.hxml
Normal file
38
tutorial/haxe/python.hxml
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#integrate files to classpath
|
||||
-cp src
|
||||
-cp gen-haxe
|
||||
-cp ../../lib/haxe/src
|
||||
|
||||
#this class wil be used as entry point for your app.
|
||||
-main Main
|
||||
|
||||
#Python target
|
||||
-python bin/Tutorial.py
|
||||
|
||||
#Add debug information
|
||||
-debug
|
||||
|
||||
#dead code elimination : remove unused code
|
||||
#"-dce no" : do not remove unused code
|
||||
#"-dce std" : remove unused code in the std lib (default)
|
||||
#"-dce full" : remove all unused code
|
||||
-dce full
|
101
tutorial/haxe/src/CalculatorHandler.hx
Normal file
101
tutorial/haxe/src/CalculatorHandler.hx
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import haxe.ds.IntMap;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
import tutorial.*;
|
||||
import shared.*;
|
||||
|
||||
|
||||
class CalculatorHandler implements Calculator {
|
||||
|
||||
private var log = new IntMap<SharedStruct>();
|
||||
|
||||
public function new() {
|
||||
}
|
||||
|
||||
public function ping() : Void {
|
||||
trace("ping()");
|
||||
}
|
||||
|
||||
|
||||
public function add( num1 : haxe.Int32, num2 : haxe.Int32) : haxe.Int32 {
|
||||
trace('add( $num1, $num2)');
|
||||
return num1 + num2;
|
||||
}
|
||||
|
||||
public function calculate( logid : haxe.Int32, work : Work) : haxe.Int32 {
|
||||
trace('calculate( $logid, '+work.op+","+work.num1+","+work.num2+")");
|
||||
|
||||
var val : haxe.Int32 = 0;
|
||||
switch (work.op)
|
||||
{
|
||||
case Operation.ADD:
|
||||
val = work.num1 + work.num2;
|
||||
|
||||
case Operation.SUBTRACT:
|
||||
val = work.num1 - work.num2;
|
||||
|
||||
case Operation.MULTIPLY:
|
||||
val = work.num1 * work.num2;
|
||||
|
||||
case Operation.DIVIDE:
|
||||
if (work.num2 == 0)
|
||||
{
|
||||
var io = new InvalidOperation();
|
||||
io.what = work.op;
|
||||
io.why = "Cannot divide by 0";
|
||||
throw io;
|
||||
}
|
||||
val = Std.int( work.num1 / work.num2);
|
||||
|
||||
default:
|
||||
var io = new InvalidOperation();
|
||||
io.what = work.op;
|
||||
io.why = "Unknown operation";
|
||||
throw io;
|
||||
}
|
||||
|
||||
var entry = new SharedStruct();
|
||||
entry.key = logid;
|
||||
entry.value = '$val';
|
||||
log.set(logid, entry);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public function getStruct( key : haxe.Int32) : SharedStruct {
|
||||
trace('getStruct($key)');
|
||||
return log.get(key);
|
||||
}
|
||||
|
||||
// oneway method, no args
|
||||
public function zip() : Void {
|
||||
trace("zip()");
|
||||
}
|
||||
|
||||
}
|
329
tutorial/haxe/src/Main.hx
Normal file
329
tutorial/haxe/src/Main.hx
Normal file
@ -0,0 +1,329 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.thrift.*;
|
||||
import org.apache.thrift.protocol.*;
|
||||
import org.apache.thrift.transport.*;
|
||||
import org.apache.thrift.server.*;
|
||||
import org.apache.thrift.meta_data.*;
|
||||
|
||||
import tutorial.*;
|
||||
import shared.*;
|
||||
|
||||
|
||||
enum Prot {
|
||||
binary;
|
||||
json;
|
||||
}
|
||||
|
||||
enum Trns {
|
||||
socket;
|
||||
http;
|
||||
}
|
||||
|
||||
class Main {
|
||||
|
||||
private static var server : Bool = false;
|
||||
private static var framed : Bool = false;
|
||||
private static var buffered : Bool = false;
|
||||
private static var prot : Prot = binary;
|
||||
private static var trns : Trns = socket;
|
||||
|
||||
private static var targetHost : String = "localhost";
|
||||
private static var targetPort : Int = 9090;
|
||||
|
||||
static function main() {
|
||||
#if ! (flash || js)
|
||||
try {
|
||||
ParseArgs();
|
||||
} catch (e : String) {
|
||||
trace(e);
|
||||
trace(GetHelp());
|
||||
return;
|
||||
}
|
||||
#end
|
||||
|
||||
try {
|
||||
if (server)
|
||||
RunServer();
|
||||
else
|
||||
RunClient();
|
||||
} catch (e : String) {
|
||||
trace(e);
|
||||
}
|
||||
|
||||
trace("Completed.");
|
||||
}
|
||||
|
||||
|
||||
#if ! (flash || js)
|
||||
|
||||
private static function GetHelp() : String {
|
||||
return Sys.executablePath()+" modus trnsOption transport protocol\n"
|
||||
+"Options:\n"
|
||||
+" modus: client, server (default: client)\n"
|
||||
+" trnsOption: framed, buffered (default: none)\n"
|
||||
+" transport: socket, http (default: socket)\n"
|
||||
+" protocol: binary, json (default: binary)\n"
|
||||
+"\n"
|
||||
+"All arguments are optional.\n";
|
||||
}
|
||||
|
||||
|
||||
private static function ParseArgs() : Void {
|
||||
var step = 0;
|
||||
for (arg in Sys.args()) {
|
||||
|
||||
// server|client
|
||||
switch(step) {
|
||||
case 0:
|
||||
++step;
|
||||
if ( arg == "client")
|
||||
server = false;
|
||||
else if ( arg == "server")
|
||||
server = true;
|
||||
else
|
||||
throw "First argument must be 'server' or 'client'";
|
||||
|
||||
case 1:
|
||||
if ( arg == "framed") {
|
||||
framed = true;
|
||||
} else if ( arg == "buffered") {
|
||||
buffered = true;
|
||||
} else if ( arg == "socket") {
|
||||
trns = socket;
|
||||
++step;
|
||||
} else if ( arg == "http") {
|
||||
trns = http;
|
||||
++step;
|
||||
} else {
|
||||
throw "Unknown transport "+arg;
|
||||
}
|
||||
|
||||
case 2:
|
||||
if ( arg == "binary") {
|
||||
prot = binary;
|
||||
++step;
|
||||
} else if ( arg == "json") {
|
||||
prot = json;
|
||||
++step;
|
||||
} else {
|
||||
throw "Unknown protocol "+arg;
|
||||
}
|
||||
|
||||
default:
|
||||
throw "Unexpected argument "+arg;
|
||||
}
|
||||
|
||||
if ( framed && buffered)
|
||||
{
|
||||
trace("WN: framed supersedes buffered");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
private static function ClientSetup() : Calculator {
|
||||
trace("Client configuration:");
|
||||
|
||||
// endpoint transport
|
||||
var transport : TTransport;
|
||||
switch(trns)
|
||||
{
|
||||
case socket:
|
||||
trace('- socket transport $targetHost:$targetPort');
|
||||
transport = new TSocket( targetHost, targetPort);
|
||||
case http:
|
||||
trace("- http transport $targetHost");
|
||||
#if flash
|
||||
transport = new THttpClient( new flash.net.URLRequest(targetHost));
|
||||
#else
|
||||
transport = new THttpClient( targetHost);
|
||||
#end
|
||||
default:
|
||||
throw "Unhandled transport";
|
||||
}
|
||||
|
||||
|
||||
// optinal layered transport
|
||||
if ( framed) {
|
||||
trace("- framed transport");
|
||||
transport = new TFramedTransport(transport);
|
||||
} else if ( buffered) {
|
||||
trace("- buffered transport");
|
||||
throw "TBufferedTransport not implemented yet";
|
||||
//transport = new TBufferedTransport(transport);
|
||||
}
|
||||
|
||||
|
||||
// protocol
|
||||
var protocol : TProtocol;
|
||||
switch(prot)
|
||||
{
|
||||
case binary:
|
||||
trace("- binary protocol");
|
||||
protocol = new TBinaryProtocol( transport);
|
||||
case json:
|
||||
trace("- JSON protocol");
|
||||
protocol = new TJSONProtocol( transport);
|
||||
default:
|
||||
throw "Unhandled protocol";
|
||||
}
|
||||
|
||||
|
||||
// put everything together
|
||||
transport.open();
|
||||
return new CalculatorImpl(protocol,protocol);
|
||||
}
|
||||
|
||||
|
||||
private static function RunClient() : Void {
|
||||
var client = ClientSetup();
|
||||
|
||||
try {
|
||||
client.ping();
|
||||
trace("ping() successful");
|
||||
} catch(error : TException) {
|
||||
trace('ping() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('ping() failed: $error');
|
||||
}
|
||||
|
||||
try {
|
||||
var sum = client.add( 1, 1);
|
||||
trace('1+1=$sum');
|
||||
} catch(error : TException) {
|
||||
trace('add() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('add() failed: $error');
|
||||
}
|
||||
|
||||
|
||||
var work = new tutorial.Work();
|
||||
work.op = tutorial.Operation.DIVIDE;
|
||||
work.num1 = 1;
|
||||
work.num2 = 0;
|
||||
try {
|
||||
var quotient = client.calculate( 1, work);
|
||||
trace('Whoa we can divide by 0! Result = $quotient');
|
||||
} catch(error : TException) {
|
||||
trace('calculate() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('calculate() failed: $error');
|
||||
}
|
||||
|
||||
work.op = tutorial.Operation.SUBTRACT;
|
||||
work.num1 = 15;
|
||||
work.num2 = 10;
|
||||
try {
|
||||
var diff = client.calculate( 1, work);
|
||||
trace('15-10=$diff');
|
||||
} catch(error : TException) {
|
||||
trace('calculate() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('calculate() failed: $error');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
var log : SharedStruct = client.getStruct( 1);
|
||||
var logval = log.value;
|
||||
trace('Check log: $logval');
|
||||
} catch(error : TException) {
|
||||
trace('getStruct() failed: $error');
|
||||
} catch(error : Dynamic) {
|
||||
trace('getStruct() failed: $error');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function ServerSetup() : TServer {
|
||||
trace("Server configuration:");
|
||||
|
||||
// endpoint transport
|
||||
var transport : TServerTransport = null;
|
||||
switch(trns)
|
||||
{
|
||||
case socket:
|
||||
#if (flash || js)
|
||||
throw 'current platform does not support socket servers';
|
||||
#else
|
||||
trace('- socket transport port $targetPort');
|
||||
transport = new TServerSocket( targetPort);
|
||||
#end
|
||||
case http:
|
||||
throw "HTTP server not implemented yet";
|
||||
//trace("- http transport");
|
||||
//transport = new THttpClient( targetHost);
|
||||
default:
|
||||
throw "Unhandled transport";
|
||||
}
|
||||
|
||||
// optional: layered transport
|
||||
var transfactory : TTransportFactory = null;
|
||||
if ( framed) {
|
||||
trace("- framed transport");
|
||||
transfactory = new TFramedTransportFactory();
|
||||
} else if ( buffered) {
|
||||
trace("- buffered transport");
|
||||
throw "TBufferedTransport not implemented yet";
|
||||
//transfactory = new TBufferedTransportFactory();
|
||||
}
|
||||
|
||||
// protocol
|
||||
var protfactory : TProtocolFactory = null;
|
||||
switch(prot)
|
||||
{
|
||||
case binary:
|
||||
trace("- binary protocol");
|
||||
protfactory = new TBinaryProtocolFactory();
|
||||
case json:
|
||||
trace("- JSON protocol");
|
||||
protfactory = new TJSONProtocolFactory();
|
||||
default:
|
||||
throw "Unhandled protocol";
|
||||
}
|
||||
|
||||
var handler = new CalculatorHandler();
|
||||
var processor = new CalculatorProcessor(handler);
|
||||
var server = new TSimpleServer( processor, transport, transfactory, protfactory);
|
||||
return server;
|
||||
}
|
||||
|
||||
|
||||
private static function RunServer() : Void {
|
||||
try
|
||||
{
|
||||
var server = ServerSetup();
|
||||
|
||||
trace("\nStarting the server...");
|
||||
server.Serve();
|
||||
}
|
||||
catch( e : Dynamic)
|
||||
{
|
||||
trace('RunServer() failed: $e');
|
||||
}
|
||||
trace("done.");
|
||||
}
|
||||
|
||||
}
|
@ -27,6 +27,7 @@ namespace d share // "shared" would collide with the eponymous D keyword.
|
||||
namespace java shared
|
||||
namespace perl shared
|
||||
namespace php shared
|
||||
namespace haxe shared
|
||||
|
||||
struct SharedStruct {
|
||||
1: i32 key
|
||||
|
@ -67,6 +67,7 @@ namespace d tutorial
|
||||
namespace java tutorial
|
||||
namespace php tutorial
|
||||
namespace perl tutorial
|
||||
namespace haxe tutorial
|
||||
|
||||
/**
|
||||
* Thrift lets you do typedefs to get pretty names for your types. Standard
|
||||
|
Loading…
Reference in New Issue
Block a user