Index: build-common.xml
===================================================================
--- build-common.xml (revision 720079)
+++ build-common.xml (working copy)
@@ -86,6 +86,9 @@
+
+
+
@@ -215,7 +218,7 @@
-
+
Index: build.xml
===================================================================
--- build.xml (revision 720079)
+++ build.xml (working copy)
@@ -67,6 +67,9 @@
+
+
+
@@ -89,6 +92,9 @@
+
+
+
Index: service/include/thrift/processor/StatsProcessor.h
===================================================================
--- service/include/thrift/processor/StatsProcessor.h (revision 0)
+++ service/include/thrift/processor/StatsProcessor.h (revision 0)
@@ -0,0 +1,504 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef STATSPROCESSOR_H
+#define STATSPROCESSOR_H
+
+#include
+#include
+#include
+#include
+
+namespace facebook { namespace thrift { namespace processor {
+
+/*
+ * Class for keeping track of function call statistics and printing them if desired
+ *
+ * @author James Wang
+ */
+class StatsProcessor : public facebook::thrift::TProcessor {
+public:
+ StatsProcessor(bool print, bool frequency)
+ : print_(print),
+ frequency_(frequency)
+ {}
+ virtual ~StatsProcessor() {};
+
+ virtual bool process(boost::shared_ptr piprot, boost::shared_ptr poprot) {
+
+ piprot_ = piprot;
+
+ std::string fname;
+ facebook::thrift::protocol::TMessageType mtype;
+ int32_t seqid;
+
+ piprot_->readMessageBegin(fname, mtype, seqid);
+ if (mtype != facebook::thrift::protocol::T_CALL) {
+ if (print_) {
+ printf("Unknown message type\n");
+ }
+ throw facebook::thrift::TException("Unexpected message type");
+ }
+ if (print_) {
+ printf("%s (", fname.c_str());
+ }
+ if (frequency_) {
+ if (frequency_map_.find(fname) != frequency_map_.end()) {
+ frequency_map_[fname]++;
+ } else {
+ frequency_map_[fname] = 1;
+ }
+ }
+
+ facebook::thrift::protocol::TType ftype;
+ int16_t fid;
+
+ while (true) {
+ piprot_->readFieldBegin(fname, ftype, fid);
+ if (ftype == facebook::thrift::protocol::T_STOP) {
+ break;
+ }
+
+ printAndPassToBuffer(ftype);
+ if (print_) {
+ printf(", ");
+ }
+ }
+
+ if (print_) {
+ printf("\b\b)\n");
+ }
+ return true;
+ }
+
+ const std::map& get_frequency_map() {
+ return frequency_map_;
+ }
+
+protected:
+ void printAndPassToBuffer(facebook::thrift::protocol::TType ftype) {
+ switch (ftype) {
+ case facebook::thrift::protocol::T_BOOL:
+ {
+ bool boolv;
+ piprot_->readBool(boolv);
+ if (print_) {
+ printf("%d", boolv);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_BYTE:
+ {
+ int8_t bytev;
+ piprot_->readByte(bytev);
+ if (print_) {
+ printf("%d", bytev);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_I16:
+ {
+ int16_t i16;
+ piprot_->readI16(i16);
+ if (print_) {
+ printf("%d", i16);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_I32:
+ {
+ int32_t i32;
+ piprot_->readI32(i32);
+ if (print_) {
+ printf("%d", i32);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_I64:
+ {
+ int64_t i64;
+ piprot_->readI64(i64);
+ if (print_) {
+ printf("%ld", i64);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_DOUBLE:
+ {
+ double dub;
+ piprot_->readDouble(dub);
+ if (print_) {
+ printf("%f", dub);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_STRING:
+ {
+ std::string str;
+ piprot_->readString(str);
+ if (print_) {
+ printf("%s", str.c_str());
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_STRUCT:
+ {
+ std::string name;
+ int16_t fid;
+ facebook::thrift::protocol::TType ftype;
+ piprot_->readStructBegin(name);
+ if (print_) {
+ printf("<");
+ }
+ while (true) {
+ piprot_->readFieldBegin(name, ftype, fid);
+ if (ftype == facebook::thrift::protocol::T_STOP) {
+ break;
+ }
+ printAndPassToBuffer(ftype);
+ if (print_) {
+ printf(",");
+ }
+ piprot_->readFieldEnd();
+ }
+ piprot_->readStructEnd();
+ if (print_) {
+ printf("\b>");
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_MAP:
+ {
+ facebook::thrift::protocol::TType keyType;
+ facebook::thrift::protocol::TType valType;
+ uint32_t i, size;
+ piprot_->readMapBegin(keyType, valType, size);
+ if (print_) {
+ printf("{");
+ }
+ for (i = 0; i < size; i++) {
+ printAndPassToBuffer(keyType);
+ if (print_) {
+ printf("=>");
+ }
+ printAndPassToBuffer(valType);
+ if (print_) {
+ printf(",");
+ }
+ }
+ piprot_->readMapEnd();
+ if (print_) {
+ printf("\b}");
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_SET:
+ {
+ facebook::thrift::protocol::TType elemType;
+ uint32_t i, size;
+ piprot_->readSetBegin(elemType, size);
+ if (print_) {
+ printf("{");
+ }
+ for (i = 0; i < size; i++) {
+ printAndPassToBuffer(elemType);
+ if (print_) {
+ printf(",");
+ }
+ }
+ piprot_->readSetEnd();
+ if (print_) {
+ printf("\b}");
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_LIST:
+ {
+ facebook::thrift::protocol::TType elemType;
+ uint32_t i, size;
+ piprot_->readListBegin(elemType, size);
+ if (print_) {
+ printf("[");
+ }
+ for (i = 0; i < size; i++) {
+ printAndPassToBuffer(elemType);
+ if (print_) {
+ printf(",");
+ }
+ }
+ piprot_->readListEnd();
+ if (print_) {
+ printf("\b]");
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ boost::shared_ptr piprot_;
+ std::map frequency_map_;
+
+ bool print_;
+ bool frequency_;
+};
+
+}}} // facebook::thrift::processor
+
+#endif
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef STATSPROCESSOR_H
+#define STATSPROCESSOR_H
+
+#include
+#include
+#include
+#include
+
+namespace facebook { namespace thrift { namespace processor {
+
+/*
+ * Class for keeping track of function call statistics and printing them if desired
+ *
+ * @author James Wang
+ */
+class StatsProcessor : public facebook::thrift::TProcessor {
+public:
+ StatsProcessor(bool print, bool frequency)
+ : print_(print),
+ frequency_(frequency)
+ {}
+ virtual ~StatsProcessor() {};
+
+ virtual bool process(boost::shared_ptr piprot, boost::shared_ptr poprot) {
+
+ piprot_ = piprot;
+
+ std::string fname;
+ facebook::thrift::protocol::TMessageType mtype;
+ int32_t seqid;
+
+ piprot_->readMessageBegin(fname, mtype, seqid);
+ if (mtype != facebook::thrift::protocol::T_CALL) {
+ if (print_) {
+ printf("Unknown message type\n");
+ }
+ throw facebook::thrift::TException("Unexpected message type");
+ }
+ if (print_) {
+ printf("%s (", fname.c_str());
+ }
+ if (frequency_) {
+ if (frequency_map_.find(fname) != frequency_map_.end()) {
+ frequency_map_[fname]++;
+ } else {
+ frequency_map_[fname] = 1;
+ }
+ }
+
+ facebook::thrift::protocol::TType ftype;
+ int16_t fid;
+
+ while (true) {
+ piprot_->readFieldBegin(fname, ftype, fid);
+ if (ftype == facebook::thrift::protocol::T_STOP) {
+ break;
+ }
+
+ printAndPassToBuffer(ftype);
+ if (print_) {
+ printf(", ");
+ }
+ }
+
+ if (print_) {
+ printf("\b\b)\n");
+ }
+ return true;
+ }
+
+ const std::map& get_frequency_map() {
+ return frequency_map_;
+ }
+
+protected:
+ void printAndPassToBuffer(facebook::thrift::protocol::TType ftype) {
+ switch (ftype) {
+ case facebook::thrift::protocol::T_BOOL:
+ {
+ bool boolv;
+ piprot_->readBool(boolv);
+ if (print_) {
+ printf("%d", boolv);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_BYTE:
+ {
+ int8_t bytev;
+ piprot_->readByte(bytev);
+ if (print_) {
+ printf("%d", bytev);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_I16:
+ {
+ int16_t i16;
+ piprot_->readI16(i16);
+ if (print_) {
+ printf("%d", i16);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_I32:
+ {
+ int32_t i32;
+ piprot_->readI32(i32);
+ if (print_) {
+ printf("%d", i32);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_I64:
+ {
+ int64_t i64;
+ piprot_->readI64(i64);
+ if (print_) {
+ printf("%ld", i64);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_DOUBLE:
+ {
+ double dub;
+ piprot_->readDouble(dub);
+ if (print_) {
+ printf("%f", dub);
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_STRING:
+ {
+ std::string str;
+ piprot_->readString(str);
+ if (print_) {
+ printf("%s", str.c_str());
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_STRUCT:
+ {
+ std::string name;
+ int16_t fid;
+ facebook::thrift::protocol::TType ftype;
+ piprot_->readStructBegin(name);
+ if (print_) {
+ printf("<");
+ }
+ while (true) {
+ piprot_->readFieldBegin(name, ftype, fid);
+ if (ftype == facebook::thrift::protocol::T_STOP) {
+ break;
+ }
+ printAndPassToBuffer(ftype);
+ if (print_) {
+ printf(",");
+ }
+ piprot_->readFieldEnd();
+ }
+ piprot_->readStructEnd();
+ if (print_) {
+ printf("\b>");
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_MAP:
+ {
+ facebook::thrift::protocol::TType keyType;
+ facebook::thrift::protocol::TType valType;
+ uint32_t i, size;
+ piprot_->readMapBegin(keyType, valType, size);
+ if (print_) {
+ printf("{");
+ }
+ for (i = 0; i < size; i++) {
+ printAndPassToBuffer(keyType);
+ if (print_) {
+ printf("=>");
+ }
+ printAndPassToBuffer(valType);
+ if (print_) {
+ printf(",");
+ }
+ }
+ piprot_->readMapEnd();
+ if (print_) {
+ printf("\b}");
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_SET:
+ {
+ facebook::thrift::protocol::TType elemType;
+ uint32_t i, size;
+ piprot_->readSetBegin(elemType, size);
+ if (print_) {
+ printf("{");
+ }
+ for (i = 0; i < size; i++) {
+ printAndPassToBuffer(elemType);
+ if (print_) {
+ printf(",");
+ }
+ }
+ piprot_->readSetEnd();
+ if (print_) {
+ printf("\b}");
+ }
+ }
+ break;
+ case facebook::thrift::protocol::T_LIST:
+ {
+ facebook::thrift::protocol::TType elemType;
+ uint32_t i, size;
+ piprot_->readListBegin(elemType, size);
+ if (print_) {
+ printf("[");
+ }
+ for (i = 0; i < size; i++) {
+ printAndPassToBuffer(elemType);
+ if (print_) {
+ printf(",");
+ }
+ }
+ piprot_->readListEnd();
+ if (print_) {
+ printf("\b]");
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ boost::shared_ptr piprot_;
+ std::map frequency_map_;
+
+ bool print_;
+ bool frequency_;
+};
+
+}}} // facebook::thrift::processor
+
+#endif
Index: service/include/thrift/processor/PeekProcessor.h
===================================================================
--- service/include/thrift/processor/PeekProcessor.h (revision 0)
+++ service/include/thrift/processor/PeekProcessor.h (revision 0)
@@ -0,0 +1,128 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef PEEKPROCESSOR_H
+#define PEEKPROCESSOR_H
+
+#include
+#include
+#include
+#include
+#include
+
+namespace facebook { namespace thrift { namespace processor {
+
+/*
+ * Class for peeking at the raw data that is being processed by another processor
+ * and gives the derived class a chance to change behavior accordingly
+ *
+ * @author James Wang
+ */
+class PeekProcessor : public facebook::thrift::TProcessor {
+
+ public:
+ PeekProcessor();
+ virtual ~PeekProcessor();
+
+ // Input here: actualProcessor - the underlying processor
+ // protocolFactory - the protocol factory used to wrap the memory buffer
+ // transportFactory - this TPipedTransportFactory is used to wrap the source transport
+ // via a call to getPipedTransport
+ void initialize(boost::shared_ptr actualProcessor,
+ boost::shared_ptr protocolFactory,
+ boost::shared_ptr transportFactory);
+
+ boost::shared_ptr getPipedTransport(boost::shared_ptr in);
+
+ void setTargetTransport(boost::shared_ptr targetTransport);
+
+ virtual bool process(boost::shared_ptr in,
+ boost::shared_ptr out);
+
+ // The following three functions can be overloaded by child classes to
+ // achieve desired peeking behavior
+ virtual void peekName(const std::string& fname);
+ virtual void peekBuffer(uint8_t* buffer, uint32_t size);
+ virtual void peek(boost::shared_ptr in,
+ facebook::thrift::protocol::TType ftype,
+ int16_t fid);
+ virtual void peekEnd();
+
+ private:
+ boost::shared_ptr actualProcessor_;
+ boost::shared_ptr pipedProtocol_;
+ boost::shared_ptr transportFactory_;
+ boost::shared_ptr memoryBuffer_;
+ boost::shared_ptr targetTransport_;
+};
+
+}}} // facebook::thrift::processor
+
+#endif
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef PEEKPROCESSOR_H
+#define PEEKPROCESSOR_H
+
+#include
+#include
+#include
+#include
+#include
+
+namespace facebook { namespace thrift { namespace processor {
+
+/*
+ * Class for peeking at the raw data that is being processed by another processor
+ * and gives the derived class a chance to change behavior accordingly
+ *
+ * @author James Wang
+ */
+class PeekProcessor : public facebook::thrift::TProcessor {
+
+ public:
+ PeekProcessor();
+ virtual ~PeekProcessor();
+
+ // Input here: actualProcessor - the underlying processor
+ // protocolFactory - the protocol factory used to wrap the memory buffer
+ // transportFactory - this TPipedTransportFactory is used to wrap the source transport
+ // via a call to getPipedTransport
+ void initialize(boost::shared_ptr actualProcessor,
+ boost::shared_ptr protocolFactory,
+ boost::shared_ptr transportFactory);
+
+ boost::shared_ptr getPipedTransport(boost::shared_ptr in);
+
+ void setTargetTransport(boost::shared_ptr targetTransport);
+
+ virtual bool process(boost::shared_ptr in,
+ boost::shared_ptr out);
+
+ // The following three functions can be overloaded by child classes to
+ // achieve desired peeking behavior
+ virtual void peekName(const std::string& fname);
+ virtual void peekBuffer(uint8_t* buffer, uint32_t size);
+ virtual void peek(boost::shared_ptr in,
+ facebook::thrift::protocol::TType ftype,
+ int16_t fid);
+ virtual void peekEnd();
+
+ private:
+ boost::shared_ptr actualProcessor_;
+ boost::shared_ptr pipedProtocol_;
+ boost::shared_ptr transportFactory_;
+ boost::shared_ptr memoryBuffer_;
+ boost::shared_ptr targetTransport_;
+};
+
+}}} // facebook::thrift::processor
+
+#endif
Index: service/include/thrift/TReflectionLocal.h
===================================================================
--- service/include/thrift/TReflectionLocal.h (revision 0)
+++ service/include/thrift/TReflectionLocal.h (revision 0)
@@ -0,0 +1,168 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_TREFLECTIONLOCAL_H_
+#define _THRIFT_TREFLECTIONLOCAL_H_ 1
+
+#include
+#include
+#include
+
+/**
+ * Local Reflection is a blanket term referring to the the structure
+ * and generation of this particular representation of Thrift types.
+ * (It is called local because it cannot be serialized by Thrift).
+ *
+ * @author David Reiss
+ */
+
+namespace facebook { namespace thrift { namespace reflection { namespace local {
+
+using facebook::thrift::protocol::TType;
+
+// We include this many bytes of the structure's fingerprint when serializing
+// a top-level structure. Long enough to make collisions unlikely, short
+// enough to not significantly affect the amount of memory used.
+const int FP_PREFIX_LEN = 4;
+
+struct FieldMeta {
+ int16_t tag;
+ bool is_optional;
+};
+
+struct TypeSpec {
+ TType ttype;
+ uint8_t fp_prefix[FP_PREFIX_LEN];
+
+ // Use an anonymous union here so we can fit two TypeSpecs in one cache line.
+ union {
+ struct {
+ // Use parallel arrays here for denser packing (of the arrays).
+ FieldMeta* metas;
+ TypeSpec** specs;
+ } tstruct;
+ struct {
+ TypeSpec *subtype1;
+ TypeSpec *subtype2;
+ } tcontainer;
+ };
+
+ // Static initialization of unions isn't really possible,
+ // so take the plunge and use constructors.
+ // Hopefully they'll be evaluated at compile time.
+
+ TypeSpec(TType ttype) : ttype(ttype) {
+ std::memset(fp_prefix, 0, FP_PREFIX_LEN);
+ }
+
+ TypeSpec(TType ttype,
+ const uint8_t* fingerprint,
+ FieldMeta* metas,
+ TypeSpec** specs) :
+ ttype(ttype)
+ {
+ std::memcpy(fp_prefix, fingerprint, FP_PREFIX_LEN);
+ tstruct.metas = metas;
+ tstruct.specs = specs;
+ }
+
+ TypeSpec(TType ttype, TypeSpec* subtype1, TypeSpec* subtype2) :
+ ttype(ttype)
+ {
+ std::memset(fp_prefix, 0, FP_PREFIX_LEN);
+ tcontainer.subtype1 = subtype1;
+ tcontainer.subtype2 = subtype2;
+ }
+
+};
+
+}}}} // facebook::thrift::reflection::local
+
+#endif // #ifndef _THRIFT_TREFLECTIONLOCAL_H_
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_TREFLECTIONLOCAL_H_
+#define _THRIFT_TREFLECTIONLOCAL_H_ 1
+
+#include
+#include
+#include
+
+/**
+ * Local Reflection is a blanket term referring to the the structure
+ * and generation of this particular representation of Thrift types.
+ * (It is called local because it cannot be serialized by Thrift).
+ *
+ * @author David Reiss
+ */
+
+namespace facebook { namespace thrift { namespace reflection { namespace local {
+
+using facebook::thrift::protocol::TType;
+
+// We include this many bytes of the structure's fingerprint when serializing
+// a top-level structure. Long enough to make collisions unlikely, short
+// enough to not significantly affect the amount of memory used.
+const int FP_PREFIX_LEN = 4;
+
+struct FieldMeta {
+ int16_t tag;
+ bool is_optional;
+};
+
+struct TypeSpec {
+ TType ttype;
+ uint8_t fp_prefix[FP_PREFIX_LEN];
+
+ // Use an anonymous union here so we can fit two TypeSpecs in one cache line.
+ union {
+ struct {
+ // Use parallel arrays here for denser packing (of the arrays).
+ FieldMeta* metas;
+ TypeSpec** specs;
+ } tstruct;
+ struct {
+ TypeSpec *subtype1;
+ TypeSpec *subtype2;
+ } tcontainer;
+ };
+
+ // Static initialization of unions isn't really possible,
+ // so take the plunge and use constructors.
+ // Hopefully they'll be evaluated at compile time.
+
+ TypeSpec(TType ttype) : ttype(ttype) {
+ std::memset(fp_prefix, 0, FP_PREFIX_LEN);
+ }
+
+ TypeSpec(TType ttype,
+ const uint8_t* fingerprint,
+ FieldMeta* metas,
+ TypeSpec** specs) :
+ ttype(ttype)
+ {
+ std::memcpy(fp_prefix, fingerprint, FP_PREFIX_LEN);
+ tstruct.metas = metas;
+ tstruct.specs = specs;
+ }
+
+ TypeSpec(TType ttype, TypeSpec* subtype1, TypeSpec* subtype2) :
+ ttype(ttype)
+ {
+ std::memset(fp_prefix, 0, FP_PREFIX_LEN);
+ tcontainer.subtype1 = subtype1;
+ tcontainer.subtype2 = subtype2;
+ }
+
+};
+
+}}}} // facebook::thrift::reflection::local
+
+#endif // #ifndef _THRIFT_TREFLECTIONLOCAL_H_
Index: service/include/thrift/TLogging.h
===================================================================
--- service/include/thrift/TLogging.h (revision 0)
+++ service/include/thrift/TLogging.h (revision 0)
@@ -0,0 +1,302 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_TLOGGING_H_
+#define _THRIFT_TLOGGING_H_ 1
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/**
+ * Contains utility macros for debugging and logging.
+ *
+ * @author Aditya Agarwal
+ */
+
+#ifndef HAVE_CLOCK_GETTIME
+#include
+#else
+#include
+#endif
+
+#ifdef HAVE_STDINT_H
+#include
+#endif
+
+/**
+ * T_GLOBAL_DEBUGGING_LEVEL = 0: all debugging turned off, debug macros undefined
+ * T_GLOBAL_DEBUGGING_LEVEL = 1: all debugging turned on
+ */
+#define T_GLOBAL_DEBUGGING_LEVEL 0
+
+
+/**
+ * T_GLOBAL_LOGGING_LEVEL = 0: all logging turned off, logging macros undefined
+ * T_GLOBAL_LOGGING_LEVEL = 1: all logging turned on
+ */
+#define T_GLOBAL_LOGGING_LEVEL 1
+
+
+/**
+ * Standard wrapper around fprintf what will prefix the file name and line
+ * number to the line. Uses T_GLOBAL_DEBUGGING_LEVEL to control whether it is
+ * turned on or off.
+ *
+ * @param format_string
+ */
+#if T_GLOBAL_DEBUGGING_LEVEL > 0
+ #define T_DEBUG(format_string,...) \
+ if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \
+ fprintf(stderr,"[%s,%d] " #format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \
+ }
+#else
+ #define T_DEBUG(format_string,...)
+#endif
+
+
+/**
+ * analagous to T_DEBUG but also prints the time
+ *
+ * @param string format_string input: printf style format string
+ */
+#if T_GLOBAL_DEBUGGING_LEVEL > 0
+ #define T_DEBUG_T(format_string,...) \
+ { \
+ if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \
+ time_t now; \
+ char dbgtime[26] ; \
+ time(&now); \
+ ctime_r(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr,"[%s,%d] [%s] " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \
+ } \
+ }
+#else
+ #define T_DEBUG_T(format_string,...)
+#endif
+
+
+/**
+ * analagous to T_DEBUG but uses input level to determine whether or not the string
+ * should be logged.
+ *
+ * @param int level: specified debug level
+ * @param string format_string input: format string
+ */
+#define T_DEBUG_L(level, format_string,...) \
+ if ((level) > 0) { \
+ fprintf(stderr,"[%s,%d] " #format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \
+ }
+
+
+/**
+ * Explicit error logging. Prints time, file name and line number
+ *
+ * @param string format_string input: printf style format string
+ */
+#define T_ERROR(format_string,...) \
+ { \
+ time_t now; \
+ char dbgtime[26] ; \
+ time(&now); \
+ ctime_r(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr,"[%s,%d] [%s] ERROR: " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \
+ }
+
+
+/**
+ * Analagous to T_ERROR, additionally aborting the process.
+ * WARNING: macro calls abort(), ending program execution
+ *
+ * @param string format_string input: printf style format string
+ */
+#define T_ERROR_ABORT(format_string,...) \
+ { \
+ time_t now; \
+ char dbgtime[26] ; \
+ time(&now); \
+ ctime_r(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr,"[%s,%d] [%s] ERROR: Going to abort " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \
+ exit(1); \
+ }
+
+
+/**
+ * Log input message
+ *
+ * @param string format_string input: printf style format string
+ */
+#if T_GLOBAL_LOGGING_LEVEL > 0
+ #define T_LOG_OPER(format_string,...) \
+ { \
+ if (T_GLOBAL_LOGGING_LEVEL > 0) { \
+ time_t now; \
+ char dbgtime[26] ; \
+ time(&now); \
+ ctime_r(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr,"[%s] " #format_string " \n", dbgtime,##__VA_ARGS__); \
+ } \
+ }
+#else
+ #define T_LOG_OPER(format_string,...)
+#endif
+
+#endif // #ifndef _THRIFT_TLOGGING_H_
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_TLOGGING_H_
+#define _THRIFT_TLOGGING_H_ 1
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/**
+ * Contains utility macros for debugging and logging.
+ *
+ * @author Aditya Agarwal
+ */
+
+#ifndef HAVE_CLOCK_GETTIME
+#include
+#else
+#include
+#endif
+
+#ifdef HAVE_STDINT_H
+#include
+#endif
+
+/**
+ * T_GLOBAL_DEBUGGING_LEVEL = 0: all debugging turned off, debug macros undefined
+ * T_GLOBAL_DEBUGGING_LEVEL = 1: all debugging turned on
+ */
+#define T_GLOBAL_DEBUGGING_LEVEL 0
+
+
+/**
+ * T_GLOBAL_LOGGING_LEVEL = 0: all logging turned off, logging macros undefined
+ * T_GLOBAL_LOGGING_LEVEL = 1: all logging turned on
+ */
+#define T_GLOBAL_LOGGING_LEVEL 1
+
+
+/**
+ * Standard wrapper around fprintf what will prefix the file name and line
+ * number to the line. Uses T_GLOBAL_DEBUGGING_LEVEL to control whether it is
+ * turned on or off.
+ *
+ * @param format_string
+ */
+#if T_GLOBAL_DEBUGGING_LEVEL > 0
+ #define T_DEBUG(format_string,...) \
+ if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \
+ fprintf(stderr,"[%s,%d] " #format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \
+ }
+#else
+ #define T_DEBUG(format_string,...)
+#endif
+
+
+/**
+ * analagous to T_DEBUG but also prints the time
+ *
+ * @param string format_string input: printf style format string
+ */
+#if T_GLOBAL_DEBUGGING_LEVEL > 0
+ #define T_DEBUG_T(format_string,...) \
+ { \
+ if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \
+ time_t now; \
+ char dbgtime[26] ; \
+ time(&now); \
+ ctime_r(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr,"[%s,%d] [%s] " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \
+ } \
+ }
+#else
+ #define T_DEBUG_T(format_string,...)
+#endif
+
+
+/**
+ * analagous to T_DEBUG but uses input level to determine whether or not the string
+ * should be logged.
+ *
+ * @param int level: specified debug level
+ * @param string format_string input: format string
+ */
+#define T_DEBUG_L(level, format_string,...) \
+ if ((level) > 0) { \
+ fprintf(stderr,"[%s,%d] " #format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \
+ }
+
+
+/**
+ * Explicit error logging. Prints time, file name and line number
+ *
+ * @param string format_string input: printf style format string
+ */
+#define T_ERROR(format_string,...) \
+ { \
+ time_t now; \
+ char dbgtime[26] ; \
+ time(&now); \
+ ctime_r(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr,"[%s,%d] [%s] ERROR: " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \
+ }
+
+
+/**
+ * Analagous to T_ERROR, additionally aborting the process.
+ * WARNING: macro calls abort(), ending program execution
+ *
+ * @param string format_string input: printf style format string
+ */
+#define T_ERROR_ABORT(format_string,...) \
+ { \
+ time_t now; \
+ char dbgtime[26] ; \
+ time(&now); \
+ ctime_r(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr,"[%s,%d] [%s] ERROR: Going to abort " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \
+ exit(1); \
+ }
+
+
+/**
+ * Log input message
+ *
+ * @param string format_string input: printf style format string
+ */
+#if T_GLOBAL_LOGGING_LEVEL > 0
+ #define T_LOG_OPER(format_string,...) \
+ { \
+ if (T_GLOBAL_LOGGING_LEVEL > 0) { \
+ time_t now; \
+ char dbgtime[26] ; \
+ time(&now); \
+ ctime_r(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr,"[%s] " #format_string " \n", dbgtime,##__VA_ARGS__); \
+ } \
+ }
+#else
+ #define T_LOG_OPER(format_string,...)
+#endif
+
+#endif // #ifndef _THRIFT_TLOGGING_H_
Index: service/include/thrift/protocol/TBinaryProtocol.h
===================================================================
--- service/include/thrift/protocol/TBinaryProtocol.h (revision 0)
+++ service/include/thrift/protocol/TBinaryProtocol.h (revision 0)
@@ -0,0 +1,478 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_
+#define _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ 1
+
+#include "TProtocol.h"
+
+#include
+
+namespace facebook { namespace thrift { namespace protocol {
+
+/**
+ * The default binary protocol for thrift. Writes all data in a very basic
+ * binary format, essentially just spitting out the raw bytes.
+ *
+ * @author Mark Slee
+ */
+class TBinaryProtocol : public TProtocol {
+ protected:
+ static const int32_t VERSION_MASK = 0xffff0000;
+ static const int32_t VERSION_1 = 0x80010000;
+ // VERSION_2 (0x80020000) is taken by TDenseProtocol.
+
+ public:
+ TBinaryProtocol(boost::shared_ptr trans) :
+ TProtocol(trans),
+ string_limit_(0),
+ container_limit_(0),
+ strict_read_(false),
+ strict_write_(true),
+ string_buf_(NULL),
+ string_buf_size_(0) {}
+
+ TBinaryProtocol(boost::shared_ptr trans,
+ int32_t string_limit,
+ int32_t container_limit,
+ bool strict_read,
+ bool strict_write) :
+ TProtocol(trans),
+ string_limit_(string_limit),
+ container_limit_(container_limit),
+ strict_read_(strict_read),
+ strict_write_(strict_write),
+ string_buf_(NULL),
+ string_buf_size_(0) {}
+
+ ~TBinaryProtocol() {
+ if (string_buf_ != NULL) {
+ free(string_buf_);
+ string_buf_size_ = 0;
+ }
+ }
+
+ void setStringSizeLimit(int32_t string_limit) {
+ string_limit_ = string_limit;
+ }
+
+ void setContainerSizeLimit(int32_t container_limit) {
+ container_limit_ = container_limit;
+ }
+
+ void setStrict(bool strict_read, bool strict_write) {
+ strict_read_ = strict_read;
+ strict_write_ = strict_write;
+ }
+
+ /**
+ * Writing functions.
+ */
+
+ virtual uint32_t writeMessageBegin(const std::string& name,
+ const TMessageType messageType,
+ const int32_t seqid);
+
+ virtual uint32_t writeMessageEnd();
+
+
+ uint32_t writeStructBegin(const std::string& name);
+
+ uint32_t writeStructEnd();
+
+ uint32_t writeFieldBegin(const std::string& name,
+ const TType fieldType,
+ const int16_t fieldId);
+
+ uint32_t writeFieldEnd();
+
+ uint32_t writeFieldStop();
+
+ uint32_t writeMapBegin(const TType keyType,
+ const TType valType,
+ const uint32_t size);
+
+ uint32_t writeMapEnd();
+
+ uint32_t writeListBegin(const TType elemType,
+ const uint32_t size);
+
+ uint32_t writeListEnd();
+
+ uint32_t writeSetBegin(const TType elemType,
+ const uint32_t size);
+
+ uint32_t writeSetEnd();
+
+ uint32_t writeBool(const bool value);
+
+ uint32_t writeByte(const int8_t byte);
+
+ uint32_t writeI16(const int16_t i16);
+
+ uint32_t writeI32(const int32_t i32);
+
+ uint32_t writeI64(const int64_t i64);
+
+ uint32_t writeDouble(const double dub);
+
+
+ uint32_t writeString(const std::string& str);
+
+ /**
+ * Reading functions
+ */
+
+
+ uint32_t readMessageBegin(std::string& name,
+ TMessageType& messageType,
+ int32_t& seqid);
+
+ uint32_t readMessageEnd();
+
+ uint32_t readStructBegin(std::string& name);
+
+ uint32_t readStructEnd();
+
+ uint32_t readFieldBegin(std::string& name,
+ TType& fieldType,
+ int16_t& fieldId);
+
+ uint32_t readFieldEnd();
+
+ uint32_t readMapBegin(TType& keyType,
+ TType& valType,
+ uint32_t& size);
+
+ uint32_t readMapEnd();
+
+ uint32_t readListBegin(TType& elemType,
+ uint32_t& size);
+
+ uint32_t readListEnd();
+
+ uint32_t readSetBegin(TType& elemType,
+ uint32_t& size);
+
+ uint32_t readSetEnd();
+
+ uint32_t readBool(bool& value);
+
+ uint32_t readByte(int8_t& byte);
+
+ uint32_t readI16(int16_t& i16);
+
+ uint32_t readI32(int32_t& i32);
+
+ uint32_t readI64(int64_t& i64);
+
+ uint32_t readDouble(double& dub);
+
+ uint32_t readString(std::string& str);
+
+ protected:
+ uint32_t readStringBody(std::string& str, int32_t sz);
+
+ int32_t string_limit_;
+ int32_t container_limit_;
+
+ // Enforce presence of version identifier
+ bool strict_read_;
+ bool strict_write_;
+
+ // Buffer for reading strings, save for the lifetime of the protocol to
+ // avoid memory churn allocating memory on every string read
+ uint8_t* string_buf_;
+ int32_t string_buf_size_;
+
+};
+
+/**
+ * Constructs binary protocol handlers
+ */
+class TBinaryProtocolFactory : public TProtocolFactory {
+ public:
+ TBinaryProtocolFactory() :
+ string_limit_(0),
+ container_limit_(0),
+ strict_read_(false),
+ strict_write_(true) {}
+
+ TBinaryProtocolFactory(int32_t string_limit, int32_t container_limit, bool strict_read, bool strict_write) :
+ string_limit_(string_limit),
+ container_limit_(container_limit),
+ strict_read_(strict_read),
+ strict_write_(strict_write) {}
+
+ virtual ~TBinaryProtocolFactory() {}
+
+ void setStringSizeLimit(int32_t string_limit) {
+ string_limit_ = string_limit;
+ }
+
+ void setContainerSizeLimit(int32_t container_limit) {
+ container_limit_ = container_limit;
+ }
+
+ void setStrict(bool strict_read, bool strict_write) {
+ strict_read_ = strict_read;
+ strict_write_ = strict_write;
+ }
+
+ boost::shared_ptr getProtocol(boost::shared_ptr trans) {
+ return boost::shared_ptr(new TBinaryProtocol(trans, string_limit_, container_limit_, strict_read_, strict_write_));
+ }
+
+ private:
+ int32_t string_limit_;
+ int32_t container_limit_;
+ bool strict_read_;
+ bool strict_write_;
+
+};
+
+}}} // facebook::thrift::protocol
+
+#endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_
+#define _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ 1
+
+#include "TProtocol.h"
+
+#include
+
+namespace facebook { namespace thrift { namespace protocol {
+
+/**
+ * The default binary protocol for thrift. Writes all data in a very basic
+ * binary format, essentially just spitting out the raw bytes.
+ *
+ * @author Mark Slee
+ */
+class TBinaryProtocol : public TProtocol {
+ protected:
+ static const int32_t VERSION_MASK = 0xffff0000;
+ static const int32_t VERSION_1 = 0x80010000;
+ // VERSION_2 (0x80020000) is taken by TDenseProtocol.
+
+ public:
+ TBinaryProtocol(boost::shared_ptr trans) :
+ TProtocol(trans),
+ string_limit_(0),
+ container_limit_(0),
+ strict_read_(false),
+ strict_write_(true),
+ string_buf_(NULL),
+ string_buf_size_(0) {}
+
+ TBinaryProtocol(boost::shared_ptr trans,
+ int32_t string_limit,
+ int32_t container_limit,
+ bool strict_read,
+ bool strict_write) :
+ TProtocol(trans),
+ string_limit_(string_limit),
+ container_limit_(container_limit),
+ strict_read_(strict_read),
+ strict_write_(strict_write),
+ string_buf_(NULL),
+ string_buf_size_(0) {}
+
+ ~TBinaryProtocol() {
+ if (string_buf_ != NULL) {
+ free(string_buf_);
+ string_buf_size_ = 0;
+ }
+ }
+
+ void setStringSizeLimit(int32_t string_limit) {
+ string_limit_ = string_limit;
+ }
+
+ void setContainerSizeLimit(int32_t container_limit) {
+ container_limit_ = container_limit;
+ }
+
+ void setStrict(bool strict_read, bool strict_write) {
+ strict_read_ = strict_read;
+ strict_write_ = strict_write;
+ }
+
+ /**
+ * Writing functions.
+ */
+
+ virtual uint32_t writeMessageBegin(const std::string& name,
+ const TMessageType messageType,
+ const int32_t seqid);
+
+ virtual uint32_t writeMessageEnd();
+
+
+ uint32_t writeStructBegin(const std::string& name);
+
+ uint32_t writeStructEnd();
+
+ uint32_t writeFieldBegin(const std::string& name,
+ const TType fieldType,
+ const int16_t fieldId);
+
+ uint32_t writeFieldEnd();
+
+ uint32_t writeFieldStop();
+
+ uint32_t writeMapBegin(const TType keyType,
+ const TType valType,
+ const uint32_t size);
+
+ uint32_t writeMapEnd();
+
+ uint32_t writeListBegin(const TType elemType,
+ const uint32_t size);
+
+ uint32_t writeListEnd();
+
+ uint32_t writeSetBegin(const TType elemType,
+ const uint32_t size);
+
+ uint32_t writeSetEnd();
+
+ uint32_t writeBool(const bool value);
+
+ uint32_t writeByte(const int8_t byte);
+
+ uint32_t writeI16(const int16_t i16);
+
+ uint32_t writeI32(const int32_t i32);
+
+ uint32_t writeI64(const int64_t i64);
+
+ uint32_t writeDouble(const double dub);
+
+
+ uint32_t writeString(const std::string& str);
+
+ /**
+ * Reading functions
+ */
+
+
+ uint32_t readMessageBegin(std::string& name,
+ TMessageType& messageType,
+ int32_t& seqid);
+
+ uint32_t readMessageEnd();
+
+ uint32_t readStructBegin(std::string& name);
+
+ uint32_t readStructEnd();
+
+ uint32_t readFieldBegin(std::string& name,
+ TType& fieldType,
+ int16_t& fieldId);
+
+ uint32_t readFieldEnd();
+
+ uint32_t readMapBegin(TType& keyType,
+ TType& valType,
+ uint32_t& size);
+
+ uint32_t readMapEnd();
+
+ uint32_t readListBegin(TType& elemType,
+ uint32_t& size);
+
+ uint32_t readListEnd();
+
+ uint32_t readSetBegin(TType& elemType,
+ uint32_t& size);
+
+ uint32_t readSetEnd();
+
+ uint32_t readBool(bool& value);
+
+ uint32_t readByte(int8_t& byte);
+
+ uint32_t readI16(int16_t& i16);
+
+ uint32_t readI32(int32_t& i32);
+
+ uint32_t readI64(int64_t& i64);
+
+ uint32_t readDouble(double& dub);
+
+ uint32_t readString(std::string& str);
+
+ protected:
+ uint32_t readStringBody(std::string& str, int32_t sz);
+
+ int32_t string_limit_;
+ int32_t container_limit_;
+
+ // Enforce presence of version identifier
+ bool strict_read_;
+ bool strict_write_;
+
+ // Buffer for reading strings, save for the lifetime of the protocol to
+ // avoid memory churn allocating memory on every string read
+ uint8_t* string_buf_;
+ int32_t string_buf_size_;
+
+};
+
+/**
+ * Constructs binary protocol handlers
+ */
+class TBinaryProtocolFactory : public TProtocolFactory {
+ public:
+ TBinaryProtocolFactory() :
+ string_limit_(0),
+ container_limit_(0),
+ strict_read_(false),
+ strict_write_(true) {}
+
+ TBinaryProtocolFactory(int32_t string_limit, int32_t container_limit, bool strict_read, bool strict_write) :
+ string_limit_(string_limit),
+ container_limit_(container_limit),
+ strict_read_(strict_read),
+ strict_write_(strict_write) {}
+
+ virtual ~TBinaryProtocolFactory() {}
+
+ void setStringSizeLimit(int32_t string_limit) {
+ string_limit_ = string_limit;
+ }
+
+ void setContainerSizeLimit(int32_t container_limit) {
+ container_limit_ = container_limit;
+ }
+
+ void setStrict(bool strict_read, bool strict_write) {
+ strict_read_ = strict_read;
+ strict_write_ = strict_write;
+ }
+
+ boost::shared_ptr getProtocol(boost::shared_ptr trans) {
+ return boost::shared_ptr(new TBinaryProtocol(trans, string_limit_, container_limit_, strict_read_, strict_write_));
+ }
+
+ private:
+ int32_t string_limit_;
+ int32_t container_limit_;
+ bool strict_read_;
+ bool strict_write_;
+
+};
+
+}}} // facebook::thrift::protocol
+
+#endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_
Index: service/include/thrift/protocol/TDebugProtocol.h
===================================================================
--- service/include/thrift/protocol/TDebugProtocol.h (revision 0)
+++ service/include/thrift/protocol/TDebugProtocol.h (revision 0)
@@ -0,0 +1,388 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_PROTOCOL_TDEBUGPROTOCOL_H_
+#define _THRIFT_PROTOCOL_TDEBUGPROTOCOL_H_ 1
+
+#include "TProtocol.h"
+#include "TOneWayProtocol.h"
+
+#include
+
+#include
+
+namespace facebook { namespace thrift { namespace protocol {
+
+/*
+
+!!! EXPERIMENTAL CODE !!!
+
+This protocol is very much a work in progress.
+It doesn't handle many cases properly.
+It throws exceptions in many cases.
+It probably segfaults in many cases.
+Bug reports and feature requests are welcome.
+Complaints are not. :R
+
+*/
+
+
+/**
+ * Protocol that prints the payload in a nice human-readable format.
+ * Reading from this protocol is not supported.
+ *
+ * @author David Reiss
+ */
+class TDebugProtocol : public TWriteOnlyProtocol {
+ private:
+ enum write_state_t {
+ UNINIT,
+ STRUCT,
+ LIST,
+ SET,
+ MAP_KEY,
+ MAP_VALUE,
+ };
+
+ public:
+ TDebugProtocol(boost::shared_ptr trans)
+ : TWriteOnlyProtocol(trans, "TDebugProtocol")
+ {
+ write_state_.push_back(UNINIT);
+ }
+
+
+ virtual uint32_t writeMessageBegin(const std::string& name,
+ const TMessageType messageType,
+ const int32_t seqid);
+
+ virtual uint32_t writeMessageEnd();
+
+
+ uint32_t writeStructBegin(const std::string& name);
+
+ uint32_t writeStructEnd();
+
+ uint32_t writeFieldBegin(const std::string& name,
+ const TType fieldType,
+ const int16_t fieldId);
+
+ uint32_t writeFieldEnd();
+
+ uint32_t writeFieldStop();
+
+ uint32_t writeMapBegin(const TType keyType,
+ const TType valType,
+ const uint32_t size);
+
+ uint32_t writeMapEnd();
+
+ uint32_t writeListBegin(const TType elemType,
+ const uint32_t size);
+
+ uint32_t writeListEnd();
+
+ uint32_t writeSetBegin(const TType elemType,
+ const uint32_t size);
+
+ uint32_t writeSetEnd();
+
+ uint32_t writeBool(const bool value);
+
+ uint32_t writeByte(const int8_t byte);
+
+ uint32_t writeI16(const int16_t i16);
+
+ uint32_t writeI32(const int32_t i32);
+
+ uint32_t writeI64(const int64_t i64);
+
+ uint32_t writeDouble(const double dub);
+
+ uint32_t writeString(const std::string& str);
+
+
+ private:
+ void indentUp();
+ void indentDown();
+ uint32_t writePlain(const std::string& str);
+ uint32_t writeIndented(const std::string& str);
+ uint32_t startItem();
+ uint32_t endItem();
+ uint32_t writeItem(const std::string& str);
+
+ static std::string fieldTypeName(TType type);
+
+ std::string indent_str_;
+ static const int indent_inc = 2;
+
+ std::vector write_state_;
+ std::vector list_idx_;
+};
+
+/**
+ * Constructs debug protocol handlers
+ */
+class TDebugProtocolFactory : public TProtocolFactory {
+ public:
+ TDebugProtocolFactory() {}
+ virtual ~TDebugProtocolFactory() {}
+
+ boost::shared_ptr getProtocol(boost::shared_ptr trans) {
+ return boost::shared_ptr(new TDebugProtocol(trans));
+ }
+
+};
+
+}}} // facebook::thrift::protocol
+
+
+namespace facebook { namespace thrift {
+
+template
+std::string ThriftDebugString(const ThriftStruct& ts) {
+ using namespace facebook::thrift::transport;
+ using namespace facebook::thrift::protocol;
+ TMemoryBuffer* buffer = new TMemoryBuffer;
+ boost::shared_ptr trans(buffer);
+ TDebugProtocol protocol(trans);
+
+ ts.write(&protocol);
+
+ uint8_t* buf;
+ uint32_t size;
+ buffer->getBuffer(&buf, &size);
+ return std::string((char*)buf, (unsigned int)size);
+}
+
+// TODO(dreiss): This is badly broken. Don't use it unless you are me.
+#if 0
+template
+std::string DebugString(const std::vector