Thrift: Added support for double type across all languages
Summary: Just for completeness cause I'm crazy. Let's never use these!
Notes: Also made thrift grammar support # style comments, so you can do this at the top of your files
#!/usr/local/bin/thrift --cpp
/**
* This is a thrift def file youc an invoke directly and gen code!
*/
blah
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664789 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/php/src/protocol/TBinaryProtocol.php b/lib/php/src/protocol/TBinaryProtocol.php
index 4bb0297..2b1384f 100644
--- a/lib/php/src/protocol/TBinaryProtocol.php
+++ b/lib/php/src/protocol/TBinaryProtocol.php
@@ -136,6 +136,12 @@
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);
@@ -302,6 +308,13 @@
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);
diff --git a/lib/php/src/protocol/TProtocol.php b/lib/php/src/protocol/TProtocol.php
index 855d588..6101f57 100644
--- a/lib/php/src/protocol/TProtocol.php
+++ b/lib/php/src/protocol/TProtocol.php
@@ -89,6 +89,8 @@
public abstract function writeI64($out, $i64);
+ public abstract function writeDouble($out, $dub);
+
public abstract function writeString($out, $str);
@@ -139,6 +141,8 @@
public abstract function readI64($in, &$i64);
+ public abstract function readDouble($in, &$dub);
+
public abstract function readString($in, &$str);
/**
@@ -160,6 +164,8 @@
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:
diff --git a/lib/php/src/protocol/TType.php b/lib/php/src/protocol/TType.php
index 6ef0935..aa930ce 100644
--- a/lib/php/src/protocol/TType.php
+++ b/lib/php/src/protocol/TType.php
@@ -15,7 +15,8 @@
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;