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/cpp/src/protocol/TBinaryProtocol.cc b/lib/cpp/src/protocol/TBinaryProtocol.cc
index 51c9306..9fb2ec3 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.cc
+++ b/lib/cpp/src/protocol/TBinaryProtocol.cc
@@ -116,7 +116,24 @@
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());
@@ -276,6 +293,23 @@
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;