mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-06 18:35:19 +00:00
THRIFT-518. as3: Add the AS3 generator and library
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@937067 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
15e2930ccf
commit
321eb7a2bd
@ -64,6 +64,9 @@ endif
|
||||
if THRIFT_GEN_java
|
||||
thrift_SOURCES += src/generate/t_java_generator.cc
|
||||
endif
|
||||
if THRIFT_GEN_as3
|
||||
thrift_SOURCES += src/generate/t_as3_generator.cc
|
||||
endif
|
||||
if THRIFT_GEN_csharp
|
||||
thrift_SOURCES += src/generate/t_csharp_generator.cc
|
||||
endif
|
||||
|
2606
compiler/cpp/src/generate/t_as3_generator.cc
Normal file
2606
compiler/cpp/src/generate/t_as3_generator.cc
Normal file
File diff suppressed because it is too large
Load Diff
@ -207,6 +207,8 @@ AX_THRIFT_GEN(cpp, [C++], yes)
|
||||
AM_CONDITIONAL([THRIFT_GEN_cpp], [test "$ax_thrift_gen_cpp" = "yes"])
|
||||
AX_THRIFT_GEN(java, [Java], yes)
|
||||
AM_CONDITIONAL([THRIFT_GEN_java], [test "$ax_thrift_gen_java" = "yes"])
|
||||
AX_THRIFT_GEN(as3, [AS3], yes)
|
||||
AM_CONDITIONAL([THRIFT_GEN_as3], [test "$ax_thrift_gen_as3" = "yes"])
|
||||
AX_THRIFT_GEN(csharp, [C#], yes)
|
||||
AM_CONDITIONAL([THRIFT_GEN_csharp], [test "$ax_thrift_gen_csharp" = "yes"])
|
||||
AX_THRIFT_GEN(py, [Python], yes)
|
||||
|
66
lib/as3/build.xml
Normal file
66
lib/as3/build.xml
Normal file
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<project name="libthrift" default="compile" basedir=".">
|
||||
|
||||
<description>Thrift Build File</description>
|
||||
|
||||
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
|
||||
|
||||
<property name="src" value="${basedir}/src" />
|
||||
<property name="build" value="${basedir}/build" />
|
||||
|
||||
<target name="checkFlexHome" unless="FLEX_HOME">
|
||||
<fail message='You must set the property FLEX_HOME with the path to your flex SDK, eg. ant -DFLEX_HOME="/Applications/Adobe Flex Builder 3/sdks/3.2.0"'/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="checkFlexHome">
|
||||
|
||||
<mkdir dir="${build}"/>
|
||||
|
||||
<!-- compc takes a list of classes separated by spaces, eg. "pkg.Class pkg.Class2"
|
||||
To generate this, we have to create an ant path, then convert it using
|
||||
pathconvert, removing the prefix with a map and removing the .as suffix using
|
||||
a mapper. From http://snippets.dzone.com/posts/show/3627.
|
||||
-->
|
||||
<path id="classesRaw">
|
||||
<fileset dir="${src}/">
|
||||
<include name="**/*.as"/>
|
||||
</fileset>
|
||||
</path>
|
||||
<pathconvert
|
||||
property="classesClean"
|
||||
pathsep=" "
|
||||
dirsep="."
|
||||
refid="classesRaw">
|
||||
<map from="${src}/" to=""/>
|
||||
<mapper type="glob" from="*.as" to="*"/>
|
||||
</pathconvert>
|
||||
|
||||
<compc output="${build}/libthrift.swc" include-classes="${classesClean}">
|
||||
<source-path path-element="${src}"/>
|
||||
</compc>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build}" />
|
||||
</target>
|
||||
|
||||
</project>
|
31
lib/as3/src/org/apache/thrift/AbstractMethodError.as
Normal file
31
lib/as3/src/org/apache/thrift/AbstractMethodError.as
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 {
|
||||
|
||||
import flash.errors.IllegalOperationError;
|
||||
|
||||
public class AbstractMethodError extends IllegalOperationError {
|
||||
|
||||
public function AbstractMethodError(message:String="") {
|
||||
super("Attempt to call an abstract method");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
63
lib/as3/src/org/apache/thrift/Set.as
Normal file
63
lib/as3/src/org/apache/thrift/Set.as
Normal file
@ -0,0 +1,63 @@
|
||||
package org.apache.thrift {
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
|
||||
public class Set {
|
||||
|
||||
private var _elements:Dictionary = new Dictionary();
|
||||
private var _size:int = 0;
|
||||
|
||||
public function Set(... values) {
|
||||
for each (var value:* in values) {
|
||||
add(value);
|
||||
}
|
||||
}
|
||||
|
||||
public function add(o:*):Boolean {
|
||||
var alreadyPresent:Boolean = _elements.hasOwnProperty(o);
|
||||
if (! alreadyPresent) {
|
||||
_size++;
|
||||
_elements[o] = true;
|
||||
}
|
||||
|
||||
return ! alreadyPresent;
|
||||
}
|
||||
|
||||
public function clear():void {
|
||||
for (var value:* in _elements) {
|
||||
remove(value);
|
||||
}
|
||||
}
|
||||
|
||||
public function contains(o:Object):Boolean {
|
||||
return _elements.hasOwnProperty(o);
|
||||
}
|
||||
|
||||
public function isEmpty():Boolean {
|
||||
return _size == 0;
|
||||
}
|
||||
|
||||
public function remove(o:*):Boolean {
|
||||
if (contains(o)) {
|
||||
delete _elements[o];
|
||||
_size--;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray():Array {
|
||||
var ret:Array = new Array();
|
||||
for (var key:* in _elements) {
|
||||
ret.push(key);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public function get size():int {
|
||||
return _size;
|
||||
}
|
||||
}
|
||||
}
|
101
lib/as3/src/org/apache/thrift/TApplicationError.as
Normal file
101
lib/as3/src/org/apache/thrift/TApplicationError.as
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 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
|
||||
*/
|
||||
public class TApplicationError extends TError {
|
||||
|
||||
private static const TAPPLICATION_EXCEPTION_STRUCT:TStruct = new TStruct("TApplicationException");
|
||||
private static const MESSAGE_FIELD:TField = new TField("message", TType.STRING, 1);
|
||||
private static const TYPE_FIELD:TField = new TField("type", TType.I32, 2);
|
||||
|
||||
public static const UNKNOWN:int = 0;
|
||||
public static const UNKNOWN_METHOD:int = 1;
|
||||
public static const INVALID_MESSAGE_TYPE:int = 2;
|
||||
public static const WRONG_METHOD_NAME:int = 3;
|
||||
public static const BAD_SEQUENCE_ID:int = 4;
|
||||
public static const MISSING_RESULT:int = 5;
|
||||
|
||||
public function TApplicationError(type:int = UNKNOWN, message:String = "") {
|
||||
super(message, type);
|
||||
}
|
||||
|
||||
public static function read(iprot:TProtocol):TApplicationError {
|
||||
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);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (field.type == TType.I32) {
|
||||
type = iprot.readI32();
|
||||
}
|
||||
else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
break;
|
||||
}
|
||||
iprot.readFieldEnd();
|
||||
}
|
||||
iprot.readStructEnd();
|
||||
return new TApplicationError(type, message);
|
||||
}
|
||||
|
||||
public function write(oprot:TProtocol):void {
|
||||
oprot.writeStructBegin(TAPPLICATION_EXCEPTION_STRUCT);
|
||||
if (message != null) {
|
||||
oprot.writeFieldBegin(MESSAGE_FIELD);
|
||||
oprot.writeString(message);
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
oprot.writeFieldBegin(TYPE_FIELD);
|
||||
oprot.writeI32(errorID);
|
||||
oprot.writeFieldEnd();
|
||||
oprot.writeFieldStop();
|
||||
oprot.writeStructEnd();
|
||||
}
|
||||
}
|
||||
}
|
67
lib/as3/src/org/apache/thrift/TBase.as
Normal file
67
lib/as3/src/org/apache/thrift/TBase.as
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
public 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):Boolean;
|
||||
|
||||
/**
|
||||
* 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):*;
|
||||
|
||||
/**
|
||||
* 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:*):void;
|
||||
}
|
||||
}
|
29
lib/as3/src/org/apache/thrift/TError.as
Normal file
29
lib/as3/src/org/apache/thrift/TError.as
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 {
|
||||
|
||||
public class TError extends Error {
|
||||
|
||||
public function TError(message:String = "", errorCode:int = 0) {
|
||||
super(message, errorCode);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
32
lib/as3/src/org/apache/thrift/TFieldRequirementType.as
Normal file
32
lib/as3/src/org/apache/thrift/TFieldRequirementType.as
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 {
|
||||
|
||||
/**
|
||||
* Requirement type constants.
|
||||
*
|
||||
*/
|
||||
public class TFieldRequirementType {
|
||||
public static const REQUIRED:int = 1;
|
||||
public static const OPTIONAL:int = 2;
|
||||
public static const DEFAULT:int = 3;
|
||||
}
|
||||
|
||||
}
|
32
lib/as3/src/org/apache/thrift/TProcessor.as
Normal file
32
lib/as3/src/org/apache/thrift/TProcessor.as
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 {
|
||||
|
||||
import org.apache.thrift.protocol.TProtocol;
|
||||
|
||||
/**
|
||||
* A processor is a generic object which operates upon an input stream and
|
||||
* writes to some output stream.
|
||||
*
|
||||
*/
|
||||
public interface TProcessor {
|
||||
function process(input:TProtocol, output:TProtocol):Boolean;
|
||||
}
|
||||
}
|
57
lib/as3/src/org/apache/thrift/meta_data/FieldMetaData.as
Normal file
57
lib/as3/src/org/apache/thrift/meta_data/FieldMetaData.as
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
public 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,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.meta_data {
|
||||
|
||||
import org.apache.thrift.protocol.TType;
|
||||
|
||||
/**
|
||||
* FieldValueMetaData and collection of subclasses to store metadata about
|
||||
* the value(s) of a field
|
||||
*/
|
||||
public class FieldValueMetaData {
|
||||
|
||||
public var type:int;
|
||||
|
||||
public function FieldValueMetaData(type:int) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public function isStruct():Boolean {
|
||||
return type == TType.STRUCT;
|
||||
}
|
||||
|
||||
public function isContainer():Boolean {
|
||||
return type == TType.LIST || type == TType.MAP || type == TType.SET;
|
||||
}
|
||||
}
|
||||
}
|
31
lib/as3/src/org/apache/thrift/meta_data/ListMetaData.as
Normal file
31
lib/as3/src/org/apache/thrift/meta_data/ListMetaData.as
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.meta_data {
|
||||
|
||||
public class ListMetaData extends FieldValueMetaData {
|
||||
|
||||
public var elemMetaData:FieldValueMetaData;
|
||||
|
||||
public function ListMetaData(type:int, eMetaData:FieldValueMetaData) {
|
||||
super(type);
|
||||
this.elemMetaData = eMetaData;
|
||||
}
|
||||
}
|
||||
}
|
33
lib/as3/src/org/apache/thrift/meta_data/MapMetaData.as
Normal file
33
lib/as3/src/org/apache/thrift/meta_data/MapMetaData.as
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
31
lib/as3/src/org/apache/thrift/meta_data/SetMetaData.as
Normal file
31
lib/as3/src/org/apache/thrift/meta_data/SetMetaData.as
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.meta_data {
|
||||
|
||||
public class SetMetaData extends FieldValueMetaData {
|
||||
|
||||
public var elemMetaData:FieldValueMetaData;
|
||||
|
||||
public function SetMetaData(type:int, eMetaData:FieldValueMetaData) {
|
||||
super(type);
|
||||
this.elemMetaData = eMetaData;
|
||||
}
|
||||
}
|
||||
}
|
31
lib/as3/src/org/apache/thrift/meta_data/StructMetaData.as
Normal file
31
lib/as3/src/org/apache/thrift/meta_data/StructMetaData.as
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.meta_data {
|
||||
|
||||
public class StructMetaData extends FieldValueMetaData {
|
||||
|
||||
public var structClass:Class;
|
||||
|
||||
public function StructMetaData(type:int, sClass:Class) {
|
||||
super(type);
|
||||
this.structClass = sClass;
|
||||
}
|
||||
}
|
||||
}
|
335
lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
Normal file
335
lib/as3/src/org/apache/thrift/protocol/TBinaryProtocol.as
Normal file
@ -0,0 +1,335 @@
|
||||
/*
|
||||
* 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 flash.utils.ByteArray;
|
||||
|
||||
import org.apache.thrift.TError;
|
||||
import org.apache.thrift.transport.THttpClient;
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
|
||||
/**
|
||||
* Binary protocol implementation for thrift.
|
||||
*/
|
||||
public class TBinaryProtocol implements TProtocol {
|
||||
|
||||
private static var ANONYMOUS_STRUCT:TStruct = new TStruct();
|
||||
|
||||
protected static const VERSION_MASK:int = int(0xffff0000);
|
||||
protected static const VERSION_1:int = int(0x80010000);
|
||||
|
||||
protected var strictRead_:Boolean = false;
|
||||
protected var strictWrite_:Boolean = true;
|
||||
|
||||
protected var readLength_:int;
|
||||
protected var checkReadLength_:Boolean = false;
|
||||
|
||||
/**
|
||||
* Factory
|
||||
*/
|
||||
/*
|
||||
public static class Factory implements TProtocolFactory {
|
||||
protected boolean strictRead_ = false;
|
||||
protected boolean strictWrite_ = true;
|
||||
|
||||
public Factory() {
|
||||
this(false, true);
|
||||
}
|
||||
|
||||
public Factory(boolean strictRead, boolean strictWrite) {
|
||||
strictRead_ = strictRead;
|
||||
strictWrite_ = strictWrite;
|
||||
}
|
||||
|
||||
public TProtocol getProtocol(TTransport trans) {
|
||||
return new TBinaryProtocol(trans, strictRead_, strictWrite_);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private var trans_:TTransport;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function TBinaryProtocol(trans:TTransport, strictRead:Boolean=false, strictWrite:Boolean=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:Boolean):void {
|
||||
writeByte(b ? 1 : 0);
|
||||
}
|
||||
|
||||
private var out:ByteArray = new ByteArray();
|
||||
public function writeByte(b:int):void {
|
||||
reset(out);
|
||||
out.writeByte(b);
|
||||
trans_.write(out, 0, 1);
|
||||
}
|
||||
|
||||
public function writeI16(i16:int):void {
|
||||
reset(out);
|
||||
out.writeShort(i16);
|
||||
trans_.write(out, 0, 2);
|
||||
}
|
||||
|
||||
public function writeI32(i32:int):void {
|
||||
reset(out);
|
||||
out.writeInt(i32);
|
||||
trans_.write(out, 0, 4);
|
||||
}
|
||||
|
||||
//private byte[] i64out = new byte[8];
|
||||
//public function writeI64(i64:Number):void {
|
||||
//i64out[0] = (byte)(0xff & (i64 >> 56));
|
||||
//i64out[1] = (byte)(0xff & (i64 >> 48));
|
||||
//i64out[2] = (byte)(0xff & (i64 >> 40));
|
||||
//i64out[3] = (byte)(0xff & (i64 >> 32));
|
||||
//i64out[4] = (byte)(0xff & (i64 >> 24));
|
||||
//i64out[5] = (byte)(0xff & (i64 >> 16));
|
||||
//i64out[6] = (byte)(0xff & (i64 >> 8));
|
||||
//i64out[7] = (byte)(0xff & (i64));
|
||||
//trans_.write(i64out, 0, 8);
|
||||
//}
|
||||
|
||||
public function writeDouble(dub:Number):void {
|
||||
reset(out);
|
||||
out.writeDouble(dub);
|
||||
trans_.write(out, 0, 8);
|
||||
}
|
||||
|
||||
private var stringOut:ByteArray = new ByteArray();
|
||||
|
||||
public function writeString(str:String):void {
|
||||
reset(stringOut);
|
||||
stringOut.writeUTFBytes(str);
|
||||
|
||||
writeI32(stringOut.length);
|
||||
trans_.write(stringOut, 0, stringOut.length);
|
||||
}
|
||||
|
||||
public function writeBinary(bin:ByteArray):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 TProtocolError(TProtocolError.BAD_VERSION, "Bad version in readMessageBegin");
|
||||
}
|
||||
return new TMessage(readString(), size & 0x000000ff, readI32());
|
||||
}
|
||||
else {
|
||||
if (strictRead_) {
|
||||
throw new TProtocolError(TProtocolError.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 = type == TType.STOP ? 0 : 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():Boolean {
|
||||
return (readByte() == 1);
|
||||
}
|
||||
|
||||
private var bytes:ByteArray = new ByteArray();
|
||||
|
||||
public function readByte():int {
|
||||
readAll(1);
|
||||
return bytes.readByte();
|
||||
}
|
||||
|
||||
public function readI16():int {
|
||||
readAll(2);
|
||||
return bytes.readShort();
|
||||
}
|
||||
|
||||
public function readI32():int {
|
||||
readAll(4);
|
||||
return bytes.readInt();
|
||||
}
|
||||
|
||||
//private byte[] i64rd = new byte[8];
|
||||
/*
|
||||
public function readI64() throws TException {
|
||||
readAll(i64rd, 0, 8);
|
||||
return
|
||||
((long)(i64rd[0] & 0xff) << 56) |
|
||||
((long)(i64rd[1] & 0xff) << 48) |
|
||||
((long)(i64rd[2] & 0xff) << 40) |
|
||||
((long)(i64rd[3] & 0xff) << 32) |
|
||||
((long)(i64rd[4] & 0xff) << 24) |
|
||||
((long)(i64rd[5] & 0xff) << 16) |
|
||||
((long)(i64rd[6] & 0xff) << 8) |
|
||||
((long)(i64rd[7] & 0xff));
|
||||
}
|
||||
*/
|
||||
|
||||
public function readDouble():Number {
|
||||
readAll(8);
|
||||
return bytes.readDouble();
|
||||
}
|
||||
|
||||
public function readString():String {
|
||||
var size:int = readI32();
|
||||
readAll(size);
|
||||
return bytes.readUTFBytes(size);
|
||||
}
|
||||
|
||||
public function readStringBody(size:int):String {
|
||||
readAll(size);
|
||||
return bytes.readUTFBytes(size);
|
||||
}
|
||||
|
||||
public function readBinary():ByteArray {
|
||||
var size:int = readI32();
|
||||
checkReadLength(size);
|
||||
var buf:ByteArray = new ByteArray();
|
||||
trans_.readAll(buf, 0, size);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private function readAll(len:int):void {
|
||||
reset(bytes);
|
||||
|
||||
checkReadLength(len);
|
||||
trans_.readAll(bytes, 0, len);
|
||||
|
||||
bytes.position = 0;
|
||||
}
|
||||
|
||||
public function setReadLength(readLength:int):void {
|
||||
readLength_ = readLength;
|
||||
checkReadLength_ = true;
|
||||
}
|
||||
|
||||
protected function checkReadLength(length:int):void {
|
||||
if (checkReadLength_) {
|
||||
readLength_ -= length;
|
||||
if (readLength_ < 0) {
|
||||
throw new TError("Message length exceeded: " + length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function reset(arr:ByteArray):void {
|
||||
arr.length = 0;
|
||||
arr.position = 0;
|
||||
}
|
||||
}
|
||||
}
|
43
lib/as3/src/org/apache/thrift/protocol/TField.as
Normal file
43
lib/as3/src/org/apache/thrift/protocol/TField.as
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 {
|
||||
|
||||
public class TField {
|
||||
|
||||
public var name:String;
|
||||
public var type:int;
|
||||
public var id:int;
|
||||
|
||||
public function TField(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):Boolean {
|
||||
return type == otherField.type && id == otherField.id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
33
lib/as3/src/org/apache/thrift/protocol/TList.as
Normal file
33
lib/as3/src/org/apache/thrift/protocol/TList.as
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
public class TList {
|
||||
|
||||
public var elemType:int;
|
||||
public var size:int;
|
||||
|
||||
public function TList(t:int = 0, s:int = 0) {
|
||||
elemType = t;
|
||||
size = s;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
33
lib/as3/src/org/apache/thrift/protocol/TMap.as
Normal file
33
lib/as3/src/org/apache/thrift/protocol/TMap.as
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 {
|
||||
public class TMap {
|
||||
|
||||
public var keyType:int;
|
||||
public var valueType:int;
|
||||
public var size:int;
|
||||
|
||||
public function TMap(k:int = 0, v:int = 0, s:int = 0) {
|
||||
keyType = k;
|
||||
valueType = v;
|
||||
size = s;
|
||||
}
|
||||
}
|
||||
}
|
42
lib/as3/src/org/apache/thrift/protocol/TMessage.as
Normal file
42
lib/as3/src/org/apache/thrift/protocol/TMessage.as
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
public class TMessage {
|
||||
|
||||
public var name:String;
|
||||
public var type:int;
|
||||
public var seqid:int;
|
||||
|
||||
public function TMessage(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):Boolean {
|
||||
return name == other.name && type == other.type && seqid == other.seqid;
|
||||
}
|
||||
}
|
||||
}
|
28
lib/as3/src/org/apache/thrift/protocol/TMessageType.as
Normal file
28
lib/as3/src/org/apache/thrift/protocol/TMessageType.as
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
public class TMessageType {
|
||||
public static const CALL:int = 1;
|
||||
public static const REPLY:int = 2;
|
||||
public static const EXCEPTION:int = 3;
|
||||
public static const ONEWAY:int = 4;
|
||||
}
|
||||
}
|
124
lib/as3/src/org/apache/thrift/protocol/TProtocol.as
Normal file
124
lib/as3/src/org/apache/thrift/protocol/TProtocol.as
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.TError;
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
/**
|
||||
* Protocol interface definition
|
||||
*/
|
||||
public interface TProtocol {
|
||||
|
||||
function TProtocol(trans:TTransport);
|
||||
|
||||
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:Boolean):void;
|
||||
|
||||
function writeByte(b:int):void;
|
||||
|
||||
function writeI16(i16:int):void;
|
||||
|
||||
function writeI32(i32:int):void;
|
||||
|
||||
//function writeI64(i64:Number):void;
|
||||
|
||||
function writeDouble(dub:Number):void;
|
||||
|
||||
function writeString(str:String):void;
|
||||
|
||||
function writeBinary(bin:ByteArray):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():Boolean;
|
||||
|
||||
function readByte():int;
|
||||
|
||||
function readI16():int;
|
||||
|
||||
function readI32():int;
|
||||
|
||||
//function readI64():Number;
|
||||
|
||||
function readDouble():Number;
|
||||
|
||||
function readString():String;
|
||||
|
||||
function readBinary():ByteArray;
|
||||
}
|
||||
}
|
38
lib/as3/src/org/apache/thrift/protocol/TProtocolError.as
Normal file
38
lib/as3/src/org/apache/thrift/protocol/TProtocolError.as
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 {
|
||||
|
||||
import org.apache.thrift.TError;
|
||||
|
||||
public class TProtocolError extends TError {
|
||||
|
||||
public static const UNKNOWN:int = 0;
|
||||
public static const INVALID_DATA:int = 1;
|
||||
public static const NEGATIVE_SIZE:int = 2;
|
||||
public static const SIZE_LIMIT:int = 3;
|
||||
public static const BAD_VERSION:int = 4;
|
||||
public static const NOT_IMPLEMENTED:int = 5;
|
||||
|
||||
public function TProtocolError(error:int = UNKNOWN, message:String = "") {
|
||||
super(message, error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
27
lib/as3/src/org/apache/thrift/protocol/TProtocolFactory.as
Normal file
27
lib/as3/src/org/apache/thrift/protocol/TProtocolFactory.as
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 {
|
||||
|
||||
import org.apache.thrift.transport.TTransport;
|
||||
|
||||
public interface TProtocolFactory {
|
||||
function getProtocol(trans:TTransport):TProtocol;
|
||||
}
|
||||
}
|
148
lib/as3/src/org/apache/thrift/protocol/TProtocolUtil.as
Normal file
148
lib/as3/src/org/apache/thrift/protocol/TProtocolUtil.as
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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.TError;
|
||||
|
||||
/**
|
||||
* Utility class with static methods for interacting with protocol data
|
||||
* streams.
|
||||
*
|
||||
*/
|
||||
public class TProtocolUtil {
|
||||
|
||||
/**
|
||||
* The maximum recursive depth the skip() function will traverse before
|
||||
* throwing a TException.
|
||||
*/
|
||||
private static var maxSkipDepth:int = int.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* 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 TError("Maximum skip depth exceeded");
|
||||
}
|
||||
switch (type) {
|
||||
case TType.BOOL: {
|
||||
prot.readBool();
|
||||
break;
|
||||
}
|
||||
case TType.BYTE: {
|
||||
prot.readByte();
|
||||
break;
|
||||
}
|
||||
case TType.I16: {
|
||||
prot.readI16();
|
||||
break;
|
||||
}
|
||||
case TType.I32: {
|
||||
prot.readI32();
|
||||
break;
|
||||
}
|
||||
/*
|
||||
case TType.I64: {
|
||||
prot.readI64();
|
||||
break;
|
||||
}
|
||||
*/
|
||||
case TType.DOUBLE: {
|
||||
prot.readDouble();
|
||||
break;
|
||||
}
|
||||
case TType.STRING: {
|
||||
prot.readBinary();
|
||||
break;
|
||||
}
|
||||
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();
|
||||
break;
|
||||
}
|
||||
case TType.MAP: {
|
||||
var map:TMap = prot.readMapBegin();
|
||||
for (var i:int = 0; i < map.size; i++) {
|
||||
skipMaxDepth(prot, map.keyType, maxDepth - 1);
|
||||
skipMaxDepth(prot, map.valueType, maxDepth - 1);
|
||||
}
|
||||
prot.readMapEnd();
|
||||
break;
|
||||
}
|
||||
case TType.SET: {
|
||||
var set:TSet = prot.readSetBegin();
|
||||
for (var j:int = 0; j < set.size; j++) {
|
||||
skipMaxDepth(prot, set.elemType, maxDepth - 1);
|
||||
}
|
||||
prot.readSetEnd();
|
||||
break;
|
||||
}
|
||||
case TType.LIST: {
|
||||
var list:TList = prot.readListBegin();
|
||||
for (var k:int = 0; k < list.size; k++) {
|
||||
skipMaxDepth(prot, list.elemType, maxDepth - 1);
|
||||
}
|
||||
prot.readListEnd();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
lib/as3/src/org/apache/thrift/protocol/TSet.as
Normal file
33
lib/as3/src/org/apache/thrift/protocol/TSet.as
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
public class TSet {
|
||||
|
||||
public var elemType:int;
|
||||
public var size:int;
|
||||
|
||||
public function TSet(t:int = 0, s:int = 0) {
|
||||
elemType = t;
|
||||
size = s;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
31
lib/as3/src/org/apache/thrift/protocol/TStruct.as
Normal file
31
lib/as3/src/org/apache/thrift/protocol/TStruct.as
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.protocol {
|
||||
|
||||
public class TStruct {
|
||||
|
||||
public var name:String;
|
||||
|
||||
public function TStruct(n:String = "") {
|
||||
name = n;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
39
lib/as3/src/org/apache/thrift/protocol/TType.as
Normal file
39
lib/as3/src/org/apache/thrift/protocol/TType.as
Normal file
@ -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 {
|
||||
|
||||
public class TType {
|
||||
|
||||
public static const STOP:int = 0;
|
||||
public static const VOID:int = 1;
|
||||
public static const BOOL:int = 2;
|
||||
public static const BYTE:int = 3;
|
||||
public static const DOUBLE:int = 4;
|
||||
public static const I16:int = 6;
|
||||
public static const I32:int = 8;
|
||||
public static const I64:int = 10;
|
||||
public static const STRING:int = 11;
|
||||
public static const STRUCT:int = 12;
|
||||
public static const MAP:int = 13;
|
||||
public static const SET:int = 14;
|
||||
public static const LIST:int = 15;
|
||||
|
||||
}
|
||||
}
|
251
lib/as3/src/org/apache/thrift/transport/TFullDuplexHttpClient.as
Normal file
251
lib/as3/src/org/apache/thrift/transport/TFullDuplexHttpClient.as
Normal file
@ -0,0 +1,251 @@
|
||||
/*
|
||||
* 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 flash.utils.ByteArray;
|
||||
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:Boolean = false;
|
||||
|
||||
private var obuffer:ByteArray = new ByteArray();
|
||||
|
||||
private var input:IDataInput;
|
||||
|
||||
private var output:IDataOutput;
|
||||
|
||||
private var bytesInChunk:int = 0;
|
||||
|
||||
private var CRLF:ByteArray = new ByteArray();
|
||||
|
||||
private var ioCallback:Function = null;
|
||||
|
||||
private var eventDispatcher:EventDispatcher = new EventDispatcher();
|
||||
|
||||
public function TFullDuplexHttpClient(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():Boolean
|
||||
{
|
||||
if(socket.connected)
|
||||
{
|
||||
trace("Bytes remained:" + socket.bytesAvailable);
|
||||
return socket.bytesAvailable>0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override function read(buf:ByteArray, off:int, len:int):int
|
||||
{
|
||||
var n1:int = 0, n2:int = 0, n3:int = 0, n4:int = 0, cidx:int = 2;
|
||||
var chunkSize:ByteArray = new ByteArray();
|
||||
|
||||
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 TTransportError(TTransportError.UNKNOWN, "No more data available.");
|
||||
}
|
||||
catch (e:Error)
|
||||
{
|
||||
trace(e);
|
||||
// WTF??
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "Bad IO error:" + e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function debugBuffer(buf:ByteArray):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:ByteArray, off:int, len:int):void
|
||||
{
|
||||
obuffer.writeBytes(buf, off, len);
|
||||
}
|
||||
|
||||
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = 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 TTransportError(TTransportError.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:Function = 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 ByteArray();
|
||||
}
|
||||
|
||||
public override function isOpen():Boolean
|
||||
{
|
||||
return (this.socket == null ? false : this.socket.connected);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
103
lib/as3/src/org/apache/thrift/transport/THttpClient.as
Normal file
103
lib/as3/src/org/apache/thrift/transport/THttpClient.as
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.SecurityErrorEvent;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestMethod;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
/**
|
||||
* HTTP implementation of the TTransport interface. Used for working with a
|
||||
* Thrift web services implementation.
|
||||
*/
|
||||
public class THttpClient extends TTransport {
|
||||
|
||||
private var request_:URLRequest = null;
|
||||
private var requestBuffer_:ByteArray = new ByteArray();
|
||||
private var responseBuffer_:ByteArray = null;
|
||||
|
||||
public function getBuffer():ByteArray {
|
||||
return requestBuffer_;
|
||||
}
|
||||
|
||||
public function THttpClient(request:URLRequest):void {
|
||||
request.contentType = "application/x-thrift";
|
||||
request_ = request;
|
||||
}
|
||||
|
||||
public override function open():void {
|
||||
}
|
||||
|
||||
public override function close():void {
|
||||
}
|
||||
|
||||
public override function isOpen():Boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override function read(buf:ByteArray, off:int, len:int):int {
|
||||
if (responseBuffer_ == null) {
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "Response buffer is empty, no request.");
|
||||
}
|
||||
try {
|
||||
responseBuffer_.readBytes(buf, off, len);
|
||||
return len;
|
||||
}
|
||||
catch (e:EOFError) {
|
||||
throw new TTransportError(TTransportError.UNKNOWN, "No more data available.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override function write(buf:ByteArray, off:int, len:int):void {
|
||||
requestBuffer_.writeBytes(buf, off, len);
|
||||
}
|
||||
|
||||
public override function flush(callback:Function=null):void {
|
||||
var loader:URLLoader = new URLLoader();
|
||||
if (callback != null) {
|
||||
loader.addEventListener(Event.COMPLETE, function(event:Event):void {
|
||||
responseBuffer_ = URLLoader(event.target).data;
|
||||
callback(null);
|
||||
responseBuffer_ = null;
|
||||
});
|
||||
loader.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void {
|
||||
callback(new TTransportError(TTransportError.UNKNOWN, "IOError: " + event.text));
|
||||
responseBuffer_ = null;
|
||||
});
|
||||
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(event:SecurityErrorEvent):void {
|
||||
callback(new TTransportError(TTransportError.UNKNOWN, "SecurityError: " + event.text));
|
||||
responseBuffer_ = null;
|
||||
});
|
||||
}
|
||||
request_.method = URLRequestMethod.POST;
|
||||
loader.dataFormat = URLLoaderDataFormat.BINARY;
|
||||
requestBuffer_.position = 0;
|
||||
request_.data = requestBuffer_;
|
||||
loader.load(request_);
|
||||
}
|
||||
}
|
||||
}
|
127
lib/as3/src/org/apache/thrift/transport/TTransport.as
Normal file
127
lib/as3/src/org/apache/thrift/transport/TTransport.as
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.thrift.transport {
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
import org.apache.thrift.AbstractMethodError;
|
||||
|
||||
public class TTransport {
|
||||
|
||||
/**
|
||||
* Queries whether the transport is open.
|
||||
*
|
||||
* @return True if the transport is open.
|
||||
*/
|
||||
public function isOpen():Boolean {
|
||||
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():Boolean {
|
||||
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 number of bytes actually read
|
||||
* @throws TTransportException if there was an error reading data
|
||||
*/
|
||||
public function read(buf:ByteArray, 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:ByteArray, 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 TTransportError(TTransportError.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:ByteArray):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:ByteArray, 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:Function=null):void {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
}
|
||||
}
|
37
lib/as3/src/org/apache/thrift/transport/TTransportError.as
Normal file
37
lib/as3/src/org/apache/thrift/transport/TTransportError.as
Normal file
@ -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.TError;
|
||||
|
||||
public class TTransportError extends TError {
|
||||
|
||||
public static const UNKNOWN:int = 0;
|
||||
public static const NOT_OPEN:int = 1;
|
||||
public static const ALREADY_OPEN:int = 2;
|
||||
public static const TIMED_OUT:int = 3;
|
||||
public static const END_OF_FILE:int = 4;
|
||||
|
||||
public function TTransportError(error:int = UNKNOWN, message:String = "") {
|
||||
super(message, error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user