case t_base_type::TYPE_I64:
out << "readI64(itrans, " << name << ");";
break;
+ case t_base_type::TYPE_DOUBLE:
+ out << "readDouble(itrans, " << name << ");";
+ break;
default:
throw "compiler error: no C++ reader for base type " + tbase + name;
}
case t_base_type::TYPE_I64:
out << "writeI64(otrans, " << name << ");";
break;
+ case t_base_type::TYPE_DOUBLE:
+ out << "writeDouble(otrans, " << name << ");";
+ break;
default:
throw "compiler error: no C++ writer for base type " + tbase + name;
}
return "int32_t";
case t_base_type::TYPE_I64:
return "int64_t";
+ case t_base_type::TYPE_DOUBLE:
+ return "double";
default:
throw "compiler error: no C++ base type name for base type " + tbase;
}
case t_base_type::TYPE_I64:
result += " = 0";
break;
+ case t_base_type::TYPE_DOUBLE:
+ result += " = (double)0";
+ break;
default:
throw "compiler error: no C++ initializer for base type " + tbase;
}
return "facebook::thrift::protocol::T_I32";
case t_base_type::TYPE_I64:
return "facebook::thrift::protocol::T_I64";
+ case t_base_type::TYPE_DOUBLE:
+ return "facebook::thrift::protocol::T_DOUBLE";
}
} else if (type->is_enum()) {
return "facebook::thrift::protocol::T_I32";
case t_base_type::TYPE_I64:
out << "readI64(_itrans);";
break;
+ case t_base_type::TYPE_DOUBLE:
+ out << "readDouble(_itrans);";
+ break;
default:
throw "compiler error: no Java name for base type " + tbase;
}
case t_base_type::TYPE_I64:
out << "writeI64(_otrans, " << name << ");";
break;
+ case t_base_type::TYPE_DOUBLE:
+ out << "writeDouble(_otrans, " << name << ");";
+ break;
default:
throw "compiler error: no Java name for base type " + tbase;
}
return (in_container ? "Integer" : "int");
case t_base_type::TYPE_I64:
return (in_container ? "Long" : "long");
+ case t_base_type::TYPE_DOUBLE:
+ return (in_container ? "Double" : "double");
default:
throw "compiler error: no C++ name for base type " + tbase;
}
case t_base_type::TYPE_I64:
result += " = 0";
break;
+ case t_base_type::TYPE_DOUBLE:
+ result += " = (double)0";
+ break;
}
} else if (ttype->is_enum()) {
return "TType.I32";
case t_base_type::TYPE_I64:
return "TType.I64";
+ case t_base_type::TYPE_DOUBLE:
+ return "TType.DOUBLE";
}
} else if (type->is_enum()) {
return "TType.I32";
"return;" << endl;
} else {
f_service_ <<
- indent() << "throw Exception(\"" << (*f_iter)->get_name() << " failed: unknown result\");" << endl;
+ indent() << "throw new Exception(\"" << (*f_iter)->get_name() << " failed: unknown result\");" << endl;
}
}
indent() << " $" << name << " = $_arr[1]*4294967296 + $_arr[2];" << endl <<
indent() << "}" << endl;
break;
+ case t_base_type::TYPE_DOUBLE:
+ out <<
+ indent() << "$_arr = unpack('d', strrev(" << itrans << "->readAll(8)));" << endl <<
+ indent() << "$" << name << " = $_arr[1];" << endl;
+ break;
default:
throw "compiler error: no PHP name for base type " + tbase + tfield->get_name();
}
case t_base_type::TYPE_I64:
out << "readI64($itrans, $" << name << ");";
break;
+ case t_base_type::TYPE_DOUBLE:
+ out << "readDouble($itrans, $" << name << ");";
+ break;
default:
throw "compiler error: no PHP name for base type " + tbase;
}
t_field fvtype(g_program->get_byte_type(), vtype);
t_field fetype(g_program->get_byte_type(), etype);
- indent(out) <<
- prefix << " = array();" << endl <<
- "$" << size << " = 0;" << endl;
+ out <<
+ indent() << "$" << prefix << " = array();" << endl <<
+ indent() << "$" << size << " = 0;" << endl;
// Declare variables, read header
if (ttype->is_map()) {
out <<
indent() << "$_output .= pack('N2', $" << name << " >> 32, $" << name << " & 0xFFFFFFFF);" << endl;
break;
+ case t_base_type::TYPE_DOUBLE:
+ out <<
+ indent() << "$_output .= strrev(pack('d', $" << name << "));" << endl;
+ break;
default:
throw "compiler error: no PHP name for base type " + tbase;
}
case t_base_type::TYPE_I64:
out << "writeI64($otrans, $" << name << ");";
break;
+ case t_base_type::TYPE_DOUBLE:
+ out << "writeDouble($otrans, $" << name << ");";
+ break;
default:
throw "compiler error: no PHP name for base type " + tbase;
}
return "Int32";
case t_base_type::TYPE_I64:
return "Int64";
+ case t_base_type::TYPE_DOUBLE:
+ return "Double";
default:
throw "compiler error: no PHP name for base type " + tbase;
}
case t_base_type::TYPE_I64:
result += " = 0";
break;
+ case t_base_type::TYPE_DOUBLE:
+ result += " = 0.0";
+ break;
default:
throw "compiler error: no PHP initializer for base type " + tbase;
}
return "TType::I32";
case t_base_type::TYPE_I64:
return "TType::I64";
+ case t_base_type::TYPE_DOUBLE:
+ return "TType::DOUBLE";
}
} else if (type->is_enum()) {
return "TType::I32";
case t_base_type::TYPE_I64:
out << "readI64(itrans);";
break;
+ case t_base_type::TYPE_DOUBLE:
+ out << "readDouble(itrans);";
+ break;
default:
throw "compiler error: no PHP name for base type " + tbase;
}
case t_base_type::TYPE_I64:
out << "writeI64(otrans, " << name << ")";
break;
+ case t_base_type::TYPE_DOUBLE:
+ out << "writeDouble(otrans, " << name << ")";
+ break;
default:
throw "compiler error: no PHP name for base type " + tbase;
}
return "Int32";
case t_base_type::TYPE_I64:
return "Int64";
+ case t_base_type::TYPE_DOUBLE:
+ return "Double";
default:
throw "compiler error: no PHP name for base type " + tbase;
}
case t_base_type::TYPE_I64:
result += " = 0";
break;
+ case t_base_type::TYPE_DOUBLE:
+ result += " = 0.0";
+ break;
default:
throw "compiler error: no PHP initializer for base type " + tbase;
}
return "TType.I32";
case t_base_type::TYPE_I64:
return "TType.I64";
+ case t_base_type::TYPE_DOUBLE:
+ return "TType.DOUBLE";
}
} else if (type->is_enum()) {
return "TType.I32";
*/
class t_base_type : public t_type {
public:
- /** Enumeration of thrift base types */
+ /**
+ * Enumeration of thrift base types
+ */
enum t_base {
TYPE_VOID,
TYPE_STRING,
TYPE_BYTE,
TYPE_I16,
TYPE_I32,
- TYPE_I64
+ TYPE_I64,
+ TYPE_DOUBLE
};
t_base_type(std::string name, t_base base) :
type_i16 = new t_base_type("i16", t_base_type::TYPE_I16);
type_i32 = new t_base_type("i32", t_base_type::TYPE_I32);
type_i64 = new t_base_type("i64", t_base_type::TYPE_I64);
+ type_double = new t_base_type("double", t_base_type::TYPE_DOUBLE);
}
~t_program() {
delete type_i16;
delete type_i32;
delete type_i64;
+ delete type_double;
}
// Name accessor
t_type* get_i16_type() const { return type_i16; }
t_type* get_i32_type() const { return type_i32; }
t_type* get_i64_type() const { return type_i64; }
+ t_type* get_double_type() const { return type_double; }
// Custom data type lookup
t_type* get_custom_type(std::string name) {
t_type* type_i16;
t_type* type_i32;
t_type* type_i64;
+ t_type* type_double;
};
#endif
whitespace ([ \t\r\n]*)
multicomm ("/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/")
comment ("//"[^\n]*)
+unixcomment ("#"[^\n]*)
symbol ([\,\{\}\(\)\=<>])
%%
{whitespace} { /* do nothing */ }
{multicomm} { /* do nothing */ }
{comment} { /* do nothing */ }
+{unixcomment} { /* do nothing */ }
{symbol} { return yytext[0]; }
pdebug("BaseType -> tok_i64");
$$ = g_program->get_i64_type();
}
+| tok_double
+ {
+ pdebug("BaseType -> tok_double");
+ $$ = g_program->get_double_type();
+ }
ContainerType:
MapType
out->write((uint8_t*)&net, 8);
return 8;
}
+
+uint32_t TBinaryProtocol::writeDouble(shared_ptr<TTransport> out,
+ const double dub) const {
+ uint8_t b[8];
+ uint8_t* d = (uint8_t*)&dub;
+ b[0] = d[7];
+ b[1] = d[6];
+ b[2] = d[5];
+ b[3] = d[4];
+ b[4] = d[3];
+ b[5] = d[2];
+ b[6] = d[1];
+ b[7] = d[0];
+ out->write((uint8_t*)b, 8);
+ return 8;
+}
+
uint32_t TBinaryProtocol::writeString(shared_ptr<TTransport> out,
const string& str) const {
uint32_t result = writeI32(out, str.size());
return 8;
}
+uint32_t TBinaryProtocol::readDouble(shared_ptr<TTransport> in,
+ double& dub) const {
+ uint8_t b[8];
+ uint8_t d[8];
+ in->readAll(b, 8);
+ d[0] = b[7];
+ d[1] = b[6];
+ d[2] = b[5];
+ d[3] = b[4];
+ d[4] = b[3];
+ d[5] = b[2];
+ d[6] = b[1];
+ d[7] = b[0];
+ dub = *(double*)d;
+ return 8;
+}
+
uint32_t TBinaryProtocol::readString(shared_ptr<TTransport> in,
string& str) const {
uint32_t result;
uint32_t writeI64(shared_ptr<TTransport> out,
const int64_t i64) const;
+ uint32_t writeDouble(shared_ptr<TTransport> out,
+ const double dub) const;
+
+
uint32_t writeString(shared_ptr<TTransport> out,
const std::string& str) const;
uint32_t readI64(shared_ptr<TTransport> in,
int64_t& i64) const;
+ uint32_t readDouble(shared_ptr<TTransport> in,
+ double& dub) const;
+
uint32_t readString(shared_ptr<TTransport> in,
std::string& str) const;
};
using namespace facebook::thrift::transport;
-#define ntohll(x) (((uint64_t)(ntohl((int)((x << 32) >> 32))) << 32) | (uint32_t)ntohl(((int)(x >> 32))))
+#define ntohll(x) (((uint64_t)(ntohl((int)((x & 0x00000000FFFFFFFF)))) << 32) | (uint32_t)ntohl(((int)(x >> 32 & 0x00000000FFFFFFFF))))
#define htonll(x) ntohll(x)
T_I32 = 8,
T_U64 = 9,
T_I64 = 10,
+ T_DOUBLE = 4,
T_STRING = 11,
T_UTF7 = 11,
T_STRUCT = 12,
virtual uint32_t writeI64(shared_ptr<TTransport> out,
const int64_t i64) const = 0;
+ virtual uint32_t writeDouble(shared_ptr<TTransport> out,
+ const double dub) const = 0;
+
virtual uint32_t writeString(shared_ptr<TTransport> out,
const std::string& str) const = 0;
virtual uint32_t readI64(shared_ptr<TTransport> in,
int64_t& i64) const = 0;
+ virtual uint32_t readDouble(shared_ptr<TTransport> in,
+ double& dub) const = 0;
+
virtual uint32_t readString(shared_ptr<TTransport> in,
std::string& str) const = 0;
int64_t i64;
return readI64(in, i64);
}
+ case T_DOUBLE:
+ {
+ double dub;
+ return readDouble(in, dub);
+ }
case T_STRING:
{
std::string str;
out.write(i64out, 0, 8);
}
+ public void writeDouble(TTransport out, double dub) throws TException {
+ writeI64(out, Double.doubleToLongBits(dub));
+ }
+
public void writeString(TTransport out, String str) throws TException {
byte[] dat = str.getBytes();
writeI32(out, dat.length);
((long)(i64rd[7] & 0xff));
}
+ public double readDouble(TTransport in) throws TException {
+ return Double.longBitsToDouble(readI64(in));
+ }
+
public String readString(TTransport in) throws TException {
int size = readI32(in);
byte[] buf = new byte[size];
public void writeI64 (TTransport out,
long i64) throws TException;
+ public void writeDouble (TTransport out,
+ double dub) throws TException;
+
+
public void writeString (TTransport out,
String str) throws TException;
public long readI64 (TTransport in) throws TException;
+ public double readDouble (TTransport in) throws TException;
+
public String readString (TTransport in) throws TException;
}
{
prot.readI64(in);
}
+ case TType.DOUBLE:
+ {
+ prot.readDouble(in);
+ }
case TType.STRING:
{
prot.readString(in);
public static final byte VOID = 1;
public static final byte BOOL = 2;
public static final byte BYTE = 3;
+ public static final byte DOUBLE = 4;
public static final byte I16 = 6;
public static final byte I32 = 8;
public static final byte I64 = 10;
return 8;
}
+ public function writeDouble($out, $value) {
+ $data = pack('d', $value);
+ $out->write(strrev($data), 8);
+ return 8;
+ }
+
public function writeString($out, $value) {
$len = strlen($value);
$result = $this->writeI32($out, $len);
return 8;
}
+ public function readDouble($in, &$value) {
+ $data = strrev($in->readAll(8));
+ $arr = unpack('d', $data);
+ $value = $arr[1];
+ return 8;
+ }
+
public function readString($in, &$value) {
$result = $this->readI32($in, $len);
$value = $in->readAll($len);
public abstract function writeI64($out, $i64);
+ public abstract function writeDouble($out, $dub);
+
public abstract function writeString($out, $str);
public abstract function readI64($in, &$i64);
+ public abstract function readDouble($in, &$dub);
+
public abstract function readString($in, &$str);
/**
return $this->readI32($in, $i32);
case TType::I64:
return $this->readI64($in, $i64);
+ case TType::DOUBLE:
+ return $this->readDouble($in, $dub);
case TType::STRING:
return $this->readString($in, $str);
case TType::STRUCT:
const VOID = 1;
const BOOL = 2;
const BYTE = 3;
- const I08 = 4;
+ const I08 = 3;
+ const DOUBLE = 4;
const I16 = 6;
const I32 = 8;
const I64 = 10;
buff = pack("!q", i64)
otrans.write(buff)
+ def writeDouble(self, otrans, dub):
+ buff = pack("!d", dub)
+ otrans.write(buff)
+
def writeString(self, otrans, str):
self.writeI32(otrans, len(str))
otrans.write(str)
val, = unpack('!q', buff)
return val
+ def readDouble(self, itrans):
+ buff = itrans.readAll(8)
+ val, = unpack('!d', buff)
+ return val
+
def readString(self, itrans):
len = self.readI32(itrans)
str = itrans.readAll(len)
VOID = 1
BOOL = 2
BYTE = 3
- I08 = 4
+ I08 = 3
+ DOUBLE = 4
I16 = 6
I32 = 8
I64 = 10
def writeI64(self, otrans, i64):
pass
+ def writeDouble(self, otrans, dub):
+ pass
+
def writeString(self, otrans, str):
pass
def readI64(self, itrans):
pass
+ def readDouble(self, itrans):
+ pass
+
def readString(self, itrans):
pass
self.readI32(itrans)
elif type == TType.I64:
self.readI64(itrans)
+ elif type == TType.DOUBLE:
+ self.readDouble(itrans)
elif type == TType.STRING:
self.readString(itrans)
elif type == TType.STRUCT:
+import sys
+import traceback
+
from thrift.Thrift import TProcessor
from thrift.transport import TTransport
while True:
self.processor.process(client, client)
except Exception, x:
- print x
+ print '%s, %s, %s' % (type(x), x, traceback.format_exc())
print 'Client died.'
client.close()
def read(self, sz):
buff = self.handle.recv(sz)
if len(buff) == 0:
- raise Exception('TScket read 0 bytes')
+ raise Exception('TSocket read 0 bytes')
return buff
def write(self, buff):
byte testByte(byte thing = 1),
i32 testI32(i32 thing = 1),
i64 testI64(i64 thing = 1),
+ double testDouble(double thing = 1),
Xtruct testStruct(Xtruct thing = 1),
Xtruct2 testNest(Xtruct2 thing = 1),
map<i32,i32> testMap(map<i32,i32> thing = 1),
printf("testI64(-34359738368)");
int64_t i64 = testClient.testI64(-34359738368LL);
printf(" = %ld\n", i64);
+
+ /**
+ * DOUBLE TEST
+ */
+ printf("testDouble(-5.2098523)");
+ double dub = testClient.testDouble(-5.2098523);
+ printf(" = %lf\n", dub);
/**
* STRUCT TEST
return thing;
}
+ double testDouble(double thing) {
+ printf("testDouble(%lf)\n", thing);
+ return thing;
+ }
+
Xtruct testStruct(Xtruct thing) {
printf("testStruct({\"%s\", %d, %d, %ld})\n",
thing.string_thing.c_str(),
long i64 = testClient.testI64(-34359738368L);
System.out.print(" = " + i64 + "\n");
+ /**
+ * DOUBLE TEST
+ */
+ System.out.print("testDouble(5.325098235)");
+ double dub = testClient.testDouble(5.325098235);
+ System.out.print(" = " + dub + "\n");
+
/**
* STRUCT TEST
*/
System.out.print("testI64(" + thing + ")\n");
return thing;
}
+
+ public double testDouble(double thing) {
+ System.out.print("testDouble(" + thing + ")\n");
+ return thing;
+ }
public Xtruct testStruct(Xtruct thing) {
System.out.print("testStruct({" +
$i64 = $testClient->testI64(-34359738368);
print_r(" = $i64\n");
+/**
+ * DOUBLE TEST
+ */
+print_r("testDouble(-852.234234234)");
+$dub = $testClient->testDouble(-852.234234234);
+print_r(" = $dub\n");
+
/**
* STRUCT TEST
*/
print "testI32(-1)"
print client.testI32(-1)
+print "testI32(0)"
+print client.testI32(0)
+
print "testI64(-34359738368)"
print client.testI64(-34359738368)
+print "testDouble(-5.235098235)"
+print client.testDouble(-5.235098235)
+
print "testStruct({Zero, 1, -3, -5})"
x = Xtruct()
x.string_thing = "Zero"
print 'testByte(%d)' % byte
return byte
+ def testI16(self, i16):
+ print 'testI16(%d)' % i16
+ return i16
+
+ def testI32(self, i32):
+ print 'testI32(%d)' % i32
+ return i32
+
+ def testI64(self, i64):
+ print 'testI64(%d)' % i64
+ return i64
+
+ def testDouble(self, dub):
+ print 'testDouble(%f)' % dub
+ return dub
+
+ def testStruct(self, thing):
+ print 'testStruct({%s, %d, %d, %d})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing)
+ return thing
+
def testException(self, str):
print 'testException(%s)' % str
- x = Xception()
- x.errorCode = 1001
- x.message = str
- raise x
+ if str == 'Xception':
+ x = Xception()
+ x.errorCode = 1001
+ x.message = str
+ raise x
transport = TSocket.TServerSocket(9090)
protocol = TBinaryProtocol.TBinaryProtocol()