You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by hc...@apache.org on 2014/11/18 10:02:39 UTC
[11/37] thrift git commit: THRIFT-2729: C++ - .clang-format created
and applied
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/processor/PeekProcessor.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/processor/PeekProcessor.cpp b/lib/cpp/src/thrift/processor/PeekProcessor.cpp
index 9303a13..8c9a463 100644
--- a/lib/cpp/src/thrift/processor/PeekProcessor.cpp
+++ b/lib/cpp/src/thrift/processor/PeekProcessor.cpp
@@ -23,13 +23,16 @@ using namespace apache::thrift::transport;
using namespace apache::thrift::protocol;
using namespace apache::thrift;
-namespace apache { namespace thrift { namespace processor {
+namespace apache {
+namespace thrift {
+namespace processor {
PeekProcessor::PeekProcessor() {
memoryBuffer_.reset(new TMemoryBuffer());
targetTransport_ = memoryBuffer_;
}
-PeekProcessor::~PeekProcessor() {}
+PeekProcessor::~PeekProcessor() {
+}
void PeekProcessor::initialize(boost::shared_ptr<TProcessor> actualProcessor,
boost::shared_ptr<TProtocolFactory> protocolFactory,
@@ -49,11 +52,13 @@ void PeekProcessor::setTargetTransport(boost::shared_ptr<TTransport> targetTrans
if (boost::dynamic_pointer_cast<TMemoryBuffer>(targetTransport_)) {
memoryBuffer_ = boost::dynamic_pointer_cast<TMemoryBuffer>(targetTransport);
} else if (boost::dynamic_pointer_cast<TPipedTransport>(targetTransport_)) {
- memoryBuffer_ = boost::dynamic_pointer_cast<TMemoryBuffer>(boost::dynamic_pointer_cast<TPipedTransport>(targetTransport_)->getTargetTransport());
+ memoryBuffer_ = boost::dynamic_pointer_cast<TMemoryBuffer>(
+ boost::dynamic_pointer_cast<TPipedTransport>(targetTransport_)->getTargetTransport());
}
if (!memoryBuffer_) {
- throw TException("Target transport must be a TMemoryBuffer or a TPipedTransport with TMemoryBuffer");
+ throw TException(
+ "Target transport must be a TMemoryBuffer or a TPipedTransport with TMemoryBuffer");
}
}
@@ -107,21 +112,21 @@ bool PeekProcessor::process(boost::shared_ptr<TProtocol> in,
}
void PeekProcessor::peekName(const std::string& fname) {
- (void) fname;
+ (void)fname;
}
void PeekProcessor::peekBuffer(uint8_t* buffer, uint32_t size) {
- (void) buffer;
- (void) size;
+ (void)buffer;
+ (void)size;
}
-void PeekProcessor::peek(boost::shared_ptr<TProtocol> in,
- TType ftype,
- int16_t fid) {
- (void) fid;
+void PeekProcessor::peek(boost::shared_ptr<TProtocol> in, TType ftype, int16_t fid) {
+ (void)fid;
in->skip(ftype);
}
-void PeekProcessor::peekEnd() {}
-
-}}}
+void PeekProcessor::peekEnd() {
+}
+}
+}
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/processor/PeekProcessor.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/processor/PeekProcessor.h b/lib/cpp/src/thrift/processor/PeekProcessor.h
index 9cfb35a..21c5999 100644
--- a/lib/cpp/src/thrift/processor/PeekProcessor.h
+++ b/lib/cpp/src/thrift/processor/PeekProcessor.h
@@ -27,7 +27,9 @@
#include <thrift/transport/TBufferTransports.h>
#include <boost/shared_ptr.hpp>
-namespace apache { namespace thrift { namespace processor {
+namespace apache {
+namespace thrift {
+namespace processor {
/*
* Class for peeking at the raw data that is being processed by another processor
@@ -36,7 +38,7 @@ namespace apache { namespace thrift { namespace processor {
*/
class PeekProcessor : public apache::thrift::TProcessor {
- public:
+public:
PeekProcessor();
virtual ~PeekProcessor();
@@ -44,11 +46,13 @@ class PeekProcessor : public apache::thrift::TProcessor {
// 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<apache::thrift::TProcessor> actualProcessor,
- boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> protocolFactory,
- boost::shared_ptr<apache::thrift::transport::TPipedTransportFactory> transportFactory);
+ void initialize(
+ boost::shared_ptr<apache::thrift::TProcessor> actualProcessor,
+ boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> protocolFactory,
+ boost::shared_ptr<apache::thrift::transport::TPipedTransportFactory> transportFactory);
- boost::shared_ptr<apache::thrift::transport::TTransport> getPipedTransport(boost::shared_ptr<apache::thrift::transport::TTransport> in);
+ boost::shared_ptr<apache::thrift::transport::TTransport> getPipedTransport(
+ boost::shared_ptr<apache::thrift::transport::TTransport> in);
void setTargetTransport(boost::shared_ptr<apache::thrift::transport::TTransport> targetTransport);
@@ -65,14 +69,15 @@ class PeekProcessor : public apache::thrift::TProcessor {
int16_t fid);
virtual void peekEnd();
- private:
+private:
boost::shared_ptr<apache::thrift::TProcessor> actualProcessor_;
boost::shared_ptr<apache::thrift::protocol::TProtocol> pipedProtocol_;
boost::shared_ptr<apache::thrift::transport::TPipedTransportFactory> transportFactory_;
boost::shared_ptr<apache::thrift::transport::TMemoryBuffer> memoryBuffer_;
boost::shared_ptr<apache::thrift::transport::TTransport> targetTransport_;
};
-
-}}} // apache::thrift::processor
+}
+}
+} // apache::thrift::processor
#endif
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/processor/StatsProcessor.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/processor/StatsProcessor.h b/lib/cpp/src/thrift/processor/StatsProcessor.h
index 0fc123e..e8ca067 100644
--- a/lib/cpp/src/thrift/processor/StatsProcessor.h
+++ b/lib/cpp/src/thrift/processor/StatsProcessor.h
@@ -25,7 +25,9 @@
#include <thrift/protocol/TProtocol.h>
#include <TProcessor.h>
-namespace apache { namespace thrift { namespace processor {
+namespace apache {
+namespace thrift {
+namespace processor {
/*
* Class for keeping track of function call statistics and printing them if desired
@@ -33,11 +35,8 @@ namespace apache { namespace thrift { namespace processor {
*/
class StatsProcessor : public apache::thrift::TProcessor {
public:
- StatsProcessor(bool print, bool frequency)
- : print_(print),
- frequency_(frequency)
- {}
- virtual ~StatsProcessor() {};
+ StatsProcessor(bool print, bool frequency) : print_(print), frequency_(frequency) {}
+ virtual ~StatsProcessor(){};
virtual bool process(boost::shared_ptr<apache::thrift::protocol::TProtocol> piprot,
boost::shared_ptr<apache::thrift::protocol::TProtocol> poprot,
@@ -88,169 +87,145 @@ public:
return true;
}
- const std::map<std::string, int64_t>& get_frequency_map() {
- return frequency_map_;
- }
+ const std::map<std::string, int64_t>& get_frequency_map() { return frequency_map_; }
protected:
void printAndPassToBuffer(apache::thrift::protocol::TType ftype) {
switch (ftype) {
- case apache::thrift::protocol::T_BOOL:
- {
- bool boolv;
- piprot_->readBool(boolv);
- if (print_) {
- printf("%d", boolv);
- }
- }
- break;
- case apache::thrift::protocol::T_BYTE:
- {
- int8_t bytev;
- piprot_->readByte(bytev);
- if (print_) {
- printf("%d", bytev);
- }
- }
- break;
- case apache::thrift::protocol::T_I16:
- {
- int16_t i16;
- piprot_->readI16(i16);
- if (print_) {
- printf("%d", i16);
- }
- }
- break;
- case apache::thrift::protocol::T_I32:
- {
- int32_t i32;
- piprot_->readI32(i32);
- if (print_) {
- printf("%d", i32);
- }
- }
- break;
- case apache::thrift::protocol::T_I64:
- {
- int64_t i64;
- piprot_->readI64(i64);
- if (print_) {
- printf("%ld", i64);
- }
+ case apache::thrift::protocol::T_BOOL: {
+ bool boolv;
+ piprot_->readBool(boolv);
+ if (print_) {
+ printf("%d", boolv);
+ }
+ } break;
+ case apache::thrift::protocol::T_BYTE: {
+ int8_t bytev;
+ piprot_->readByte(bytev);
+ if (print_) {
+ printf("%d", bytev);
+ }
+ } break;
+ case apache::thrift::protocol::T_I16: {
+ int16_t i16;
+ piprot_->readI16(i16);
+ if (print_) {
+ printf("%d", i16);
+ }
+ } break;
+ case apache::thrift::protocol::T_I32: {
+ int32_t i32;
+ piprot_->readI32(i32);
+ if (print_) {
+ printf("%d", i32);
+ }
+ } break;
+ case apache::thrift::protocol::T_I64: {
+ int64_t i64;
+ piprot_->readI64(i64);
+ if (print_) {
+ printf("%ld", i64);
+ }
+ } break;
+ case apache::thrift::protocol::T_DOUBLE: {
+ double dub;
+ piprot_->readDouble(dub);
+ if (print_) {
+ printf("%f", dub);
+ }
+ } break;
+ case apache::thrift::protocol::T_STRING: {
+ std::string str;
+ piprot_->readString(str);
+ if (print_) {
+ printf("%s", str.c_str());
+ }
+ } break;
+ case apache::thrift::protocol::T_STRUCT: {
+ std::string name;
+ int16_t fid;
+ apache::thrift::protocol::TType ftype;
+ piprot_->readStructBegin(name);
+ if (print_) {
+ printf("<");
+ }
+ while (true) {
+ piprot_->readFieldBegin(name, ftype, fid);
+ if (ftype == apache::thrift::protocol::T_STOP) {
+ break;
}
- break;
- case apache::thrift::protocol::T_DOUBLE:
- {
- double dub;
- piprot_->readDouble(dub);
- if (print_) {
- printf("%f", dub);
- }
+ printAndPassToBuffer(ftype);
+ if (print_) {
+ printf(",");
}
- break;
- case apache::thrift::protocol::T_STRING:
- {
- std::string str;
- piprot_->readString(str);
- if (print_) {
- printf("%s", str.c_str());
- }
+ piprot_->readFieldEnd();
+ }
+ piprot_->readStructEnd();
+ if (print_) {
+ printf("\b>");
+ }
+ } break;
+ case apache::thrift::protocol::T_MAP: {
+ apache::thrift::protocol::TType keyType;
+ apache::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("=>");
}
- break;
- case apache::thrift::protocol::T_STRUCT:
- {
- std::string name;
- int16_t fid;
- apache::thrift::protocol::TType ftype;
- piprot_->readStructBegin(name);
- if (print_) {
- printf("<");
- }
- while (true) {
- piprot_->readFieldBegin(name, ftype, fid);
- if (ftype == apache::thrift::protocol::T_STOP) {
- break;
- }
- printAndPassToBuffer(ftype);
- if (print_) {
- printf(",");
- }
- piprot_->readFieldEnd();
- }
- piprot_->readStructEnd();
- if (print_) {
- printf("\b>");
- }
+ printAndPassToBuffer(valType);
+ if (print_) {
+ printf(",");
}
- break;
- case apache::thrift::protocol::T_MAP:
- {
- apache::thrift::protocol::TType keyType;
- apache::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 apache::thrift::protocol::T_SET:
- {
- apache::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}");
- }
+ }
+ piprot_->readMapEnd();
+ if (print_) {
+ printf("\b}");
+ }
+ } break;
+ case apache::thrift::protocol::T_SET: {
+ apache::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(",");
}
- break;
- case apache::thrift::protocol::T_LIST:
- {
- apache::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]");
- }
+ }
+ piprot_->readSetEnd();
+ if (print_) {
+ printf("\b}");
+ }
+ } break;
+ case apache::thrift::protocol::T_LIST: {
+ apache::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(",");
}
- break;
- default:
- break;
+ }
+ piprot_->readListEnd();
+ if (print_) {
+ printf("\b]");
+ }
+ } break;
+ default:
+ break;
}
}
@@ -260,7 +235,8 @@ protected:
bool print_;
bool frequency_;
};
-
-}}} // apache::thrift::processor
+}
+}
+} // apache::thrift::processor
#endif
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/processor/TMultiplexedProcessor.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/processor/TMultiplexedProcessor.h b/lib/cpp/src/thrift/processor/TMultiplexedProcessor.h
index a352d90..a97f6a9 100644
--- a/lib/cpp/src/thrift/processor/TMultiplexedProcessor.h
+++ b/lib/cpp/src/thrift/processor/TMultiplexedProcessor.h
@@ -25,194 +25,177 @@
#include <thrift/TProcessor.h>
#include <boost/tokenizer.hpp>
-namespace apache
-{
- namespace thrift
- {
- using boost::shared_ptr;
-
- namespace protocol {
-
- /**
- * To be able to work with any protocol, we needed
- * to allow them to call readMessageBegin() and get a TMessage in exactly
- * the standard format, without the service name prepended to TMessage.name.
- */
- class StoredMessageProtocol : public TProtocolDecorator
- {
- public:
- StoredMessageProtocol( shared_ptr<protocol::TProtocol> _protocol,
- const std::string& _name, const TMessageType _type,
- const int32_t _seqid) :
- TProtocolDecorator(_protocol),
- name(_name),
- type(_type),
- seqid(_seqid)
- {
- }
-
- uint32_t readMessageBegin_virt(std::string& _name, TMessageType& _type, int32_t& _seqid)
- {
-
- _name = name;
- _type = type;
- _seqid = seqid;
-
- return 0; // (Normal TProtocol read functions return number of bytes read)
- }
-
- std::string name;
- TMessageType type;
- int32_t seqid;
- };
- } //namespace protocol
-
- /**
- * <code>TMultiplexedProcessor</code> is a <code>TProcessor</code> allowing
- * a single <code>TServer</code> to provide multiple services.
- *
- * <p>To do so, you instantiate the processor and then register additional
- * processors with it, as shown in the following example:</p>
- *
- * <blockquote><code>
- * shared_ptr<TMultiplexedProcessor> processor(new TMultiplexedProcessor());
- *
- * processor->registerProcessor(
- * "Calculator",
- * shared_ptr<TProcessor>( new CalculatorProcessor(
- * shared_ptr<CalculatorHandler>( new CalculatorHandler()))));
- *
- * processor->registerProcessor(
- * "WeatherReport",
- * shared_ptr<TProcessor>( new WeatherReportProcessor(
- * shared_ptr<WeatherReportHandler>( new WeatherReportHandler()))));
- *
- * shared_ptr<TServerTransport> transport(new TServerSocket(9090));
- * TSimpleServer server(processor, transport);
- *
- * server.serve();
- * </code></blockquote>
- */
- class TMultiplexedProcessor : public TProcessor
- {
- public:
- typedef std::map< std::string, shared_ptr<TProcessor> > services_t;
-
- /**
- * 'Register' a service with this <code>TMultiplexedProcessor</code>. This
- * allows us to broker requests to individual services by using the service
- * name to select them at request time.
- *
- * \param [in] serviceName Name of a service, has to be identical to the name
- * declared in the Thrift IDL, e.g. "WeatherReport".
- * \param [in] processor Implementation of a service, ususally referred to
- * as "handlers", e.g. WeatherReportHandler,
- * implementing WeatherReportIf interface.
- */
- void registerProcessor( const std::string & serviceName,
- shared_ptr<TProcessor> processor )
- {
- services[serviceName] = processor;
- }
-
- /**
- * This implementation of <code>process</code> performs the following steps:
- *
- * <ol>
- * <li>Read the beginning of the message.</li>
- * <li>Extract the service name from the message.</li>
- * <li>Using the service name to locate the appropriate processor.</li>
- * <li>Dispatch to the processor, with a decorated instance of TProtocol
- * that allows readMessageBegin() to return the original TMessage.</li>
- * </ol>
- *
- * \throws TException If the message type is not T_CALL or T_ONEWAY, if
- * the service name was not found in the message, or if the service
- * name was not found in the service map.
- */
- bool process( shared_ptr<protocol::TProtocol> in,
- shared_ptr<protocol::TProtocol> out,
- void *connectionContext)
- {
- std::string name;
- protocol::TMessageType type;
- int32_t seqid;
-
- // Use the actual underlying protocol (e.g. TBinaryProtocol) to read the
- // message header. This pulls the message "off the wire", which we'll
- // deal with at the end of this method.
- in->readMessageBegin(name, type, seqid);
-
- if( type != protocol::T_CALL && type != protocol::T_ONEWAY ) {
- // Unexpected message type.
- in->skip(::apache::thrift::protocol::T_STRUCT);
- in->readMessageEnd();
- in->getTransport()->readEnd();
- const std::string msg("TMultiplexedProcessor: Unexpected message type");
- ::apache::thrift::TApplicationException x(
- ::apache::thrift::TApplicationException::PROTOCOL_ERROR,
- msg);
- out->writeMessageBegin(name, ::apache::thrift::protocol::T_EXCEPTION, seqid);
- x.write(out.get());
- out->writeMessageEnd();
- out->getTransport()->writeEnd();
- out->getTransport()->flush();
- throw TException(msg);
- }
-
- // Extract the service name
-
- boost::tokenizer<boost::char_separator<char> > tok( name, boost::char_separator<char>(":") );
-
- std::vector<std::string> tokens;
- std::copy( tok.begin(), tok.end(), std::back_inserter(tokens) );
-
- // A valid message should consist of two tokens: the service
- // name and the name of the method to call.
- if( tokens.size() == 2 )
- {
- // Search for a processor associated with this service name.
- services_t::iterator it = services.find(tokens[0]);
-
- if( it != services.end() )
- {
- shared_ptr<TProcessor> processor = it->second;
- // Let the processor registered for this service name
- // process the message.
- return processor->process(
- shared_ptr<protocol::TProtocol>(
- new protocol::StoredMessageProtocol( in, tokens[1], type, seqid ) ),
- out, connectionContext );
- }
- else
- {
- // Unknown service.
- in->skip(::apache::thrift::protocol::T_STRUCT);
- in->readMessageEnd();
- in->getTransport()->readEnd();
-
- std::string msg("TMultiplexedProcessor: Unknown service: ");
- msg += tokens[0];
- ::apache::thrift::TApplicationException x(
- ::apache::thrift::TApplicationException::PROTOCOL_ERROR,
- msg);
- out->writeMessageBegin(name, ::apache::thrift::protocol::T_EXCEPTION, seqid);
- x.write(out.get());
- out->writeMessageEnd();
- out->getTransport()->writeEnd();
- out->getTransport()->flush();
- msg += ". Did you forget to call registerProcessor()?";
- throw TException(msg);
- }
- }
- return false;
- }
-
- private:
- /** Map of service processor objects, indexed by service names. */
- services_t services;
- };
+namespace apache {
+namespace thrift {
+using boost::shared_ptr;
+
+namespace protocol {
+
+/**
+ * To be able to work with any protocol, we needed
+ * to allow them to call readMessageBegin() and get a TMessage in exactly
+ * the standard format, without the service name prepended to TMessage.name.
+ */
+class StoredMessageProtocol : public TProtocolDecorator {
+public:
+ StoredMessageProtocol(shared_ptr<protocol::TProtocol> _protocol,
+ const std::string& _name,
+ const TMessageType _type,
+ const int32_t _seqid)
+ : TProtocolDecorator(_protocol), name(_name), type(_type), seqid(_seqid) {}
+
+ uint32_t readMessageBegin_virt(std::string& _name, TMessageType& _type, int32_t& _seqid) {
+
+ _name = name;
+ _type = type;
+ _seqid = seqid;
+
+ return 0; // (Normal TProtocol read functions return number of bytes read)
+ }
+
+ std::string name;
+ TMessageType type;
+ int32_t seqid;
+};
+} // namespace protocol
+
+/**
+ * <code>TMultiplexedProcessor</code> is a <code>TProcessor</code> allowing
+ * a single <code>TServer</code> to provide multiple services.
+ *
+ * <p>To do so, you instantiate the processor and then register additional
+ * processors with it, as shown in the following example:</p>
+ *
+ * <blockquote><code>
+ * shared_ptr<TMultiplexedProcessor> processor(new TMultiplexedProcessor());
+ *
+ * processor->registerProcessor(
+ * "Calculator",
+ * shared_ptr<TProcessor>( new CalculatorProcessor(
+ * shared_ptr<CalculatorHandler>( new CalculatorHandler()))));
+ *
+ * processor->registerProcessor(
+ * "WeatherReport",
+ * shared_ptr<TProcessor>( new WeatherReportProcessor(
+ * shared_ptr<WeatherReportHandler>( new WeatherReportHandler()))));
+ *
+ * shared_ptr<TServerTransport> transport(new TServerSocket(9090));
+ * TSimpleServer server(processor, transport);
+ *
+ * server.serve();
+ * </code></blockquote>
+ */
+class TMultiplexedProcessor : public TProcessor {
+public:
+ typedef std::map<std::string, shared_ptr<TProcessor> > services_t;
+
+ /**
+ * 'Register' a service with this <code>TMultiplexedProcessor</code>. This
+ * allows us to broker requests to individual services by using the service
+ * name to select them at request time.
+ *
+ * \param [in] serviceName Name of a service, has to be identical to the name
+ * declared in the Thrift IDL, e.g. "WeatherReport".
+ * \param [in] processor Implementation of a service, ususally referred to
+ * as "handlers", e.g. WeatherReportHandler,
+ * implementing WeatherReportIf interface.
+ */
+ void registerProcessor(const std::string& serviceName, shared_ptr<TProcessor> processor) {
+ services[serviceName] = processor;
+ }
+
+ /**
+ * This implementation of <code>process</code> performs the following steps:
+ *
+ * <ol>
+ * <li>Read the beginning of the message.</li>
+ * <li>Extract the service name from the message.</li>
+ * <li>Using the service name to locate the appropriate processor.</li>
+ * <li>Dispatch to the processor, with a decorated instance of TProtocol
+ * that allows readMessageBegin() to return the original TMessage.</li>
+ * </ol>
+ *
+ * \throws TException If the message type is not T_CALL or T_ONEWAY, if
+ * the service name was not found in the message, or if the service
+ * name was not found in the service map.
+ */
+ bool process(shared_ptr<protocol::TProtocol> in,
+ shared_ptr<protocol::TProtocol> out,
+ void* connectionContext) {
+ std::string name;
+ protocol::TMessageType type;
+ int32_t seqid;
+
+ // Use the actual underlying protocol (e.g. TBinaryProtocol) to read the
+ // message header. This pulls the message "off the wire", which we'll
+ // deal with at the end of this method.
+ in->readMessageBegin(name, type, seqid);
+
+ if (type != protocol::T_CALL && type != protocol::T_ONEWAY) {
+ // Unexpected message type.
+ in->skip(::apache::thrift::protocol::T_STRUCT);
+ in->readMessageEnd();
+ in->getTransport()->readEnd();
+ const std::string msg("TMultiplexedProcessor: Unexpected message type");
+ ::apache::thrift::TApplicationException
+ x(::apache::thrift::TApplicationException::PROTOCOL_ERROR, msg);
+ out->writeMessageBegin(name, ::apache::thrift::protocol::T_EXCEPTION, seqid);
+ x.write(out.get());
+ out->writeMessageEnd();
+ out->getTransport()->writeEnd();
+ out->getTransport()->flush();
+ throw TException(msg);
}
+
+ // Extract the service name
+
+ boost::tokenizer<boost::char_separator<char> > tok(name, boost::char_separator<char>(":"));
+
+ std::vector<std::string> tokens;
+ std::copy(tok.begin(), tok.end(), std::back_inserter(tokens));
+
+ // A valid message should consist of two tokens: the service
+ // name and the name of the method to call.
+ if (tokens.size() == 2) {
+ // Search for a processor associated with this service name.
+ services_t::iterator it = services.find(tokens[0]);
+
+ if (it != services.end()) {
+ shared_ptr<TProcessor> processor = it->second;
+ // Let the processor registered for this service name
+ // process the message.
+ return processor
+ ->process(shared_ptr<protocol::TProtocol>(
+ new protocol::StoredMessageProtocol(in, tokens[1], type, seqid)),
+ out,
+ connectionContext);
+ } else {
+ // Unknown service.
+ in->skip(::apache::thrift::protocol::T_STRUCT);
+ in->readMessageEnd();
+ in->getTransport()->readEnd();
+
+ std::string msg("TMultiplexedProcessor: Unknown service: ");
+ msg += tokens[0];
+ ::apache::thrift::TApplicationException
+ x(::apache::thrift::TApplicationException::PROTOCOL_ERROR, msg);
+ out->writeMessageBegin(name, ::apache::thrift::protocol::T_EXCEPTION, seqid);
+ x.write(out.get());
+ out->writeMessageEnd();
+ out->getTransport()->writeEnd();
+ out->getTransport()->flush();
+ msg += ". Did you forget to call registerProcessor()?";
+ throw TException(msg);
+ }
+ }
+ return false;
+ }
+
+private:
+ /** Map of service processor objects, indexed by service names. */
+ services_t services;
+};
+}
}
#endif // THRIFT_TMULTIPLEXEDPROCESSOR_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/protocol/TBase64Utils.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TBase64Utils.cpp b/lib/cpp/src/thrift/protocol/TBase64Utils.cpp
index cd343ed..beb76eb 100644
--- a/lib/cpp/src/thrift/protocol/TBase64Utils.cpp
+++ b/lib/cpp/src/thrift/protocol/TBase64Utils.cpp
@@ -23,13 +23,14 @@
using std::string;
-namespace apache { namespace thrift { namespace protocol {
+namespace apache {
+namespace thrift {
+namespace protocol {
+static const uint8_t* kBase64EncodeTable
+ = (const uint8_t*)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const uint8_t *kBase64EncodeTable = (const uint8_t *)
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-void base64_encode(const uint8_t *in, uint32_t len, uint8_t *buf) {
+void base64_encode(const uint8_t* in, uint32_t len, uint8_t* buf) {
buf[0] = kBase64EncodeTable[(in[0] >> 2) & 0x3f];
if (len == 3) {
buf[1] = kBase64EncodeTable[((in[0] << 4) & 0x30) | ((in[1] >> 4) & 0x0f)];
@@ -38,42 +39,279 @@ void base64_encode(const uint8_t *in, uint32_t len, uint8_t *buf) {
} else if (len == 2) {
buf[1] = kBase64EncodeTable[((in[0] << 4) & 0x30) | ((in[1] >> 4) & 0x0f)];
buf[2] = kBase64EncodeTable[(in[1] << 2) & 0x3c];
- } else { // len == 1
+ } else { // len == 1
buf[1] = kBase64EncodeTable[(in[0] << 4) & 0x30];
}
}
-static const uint8_t kBase64DecodeTable[256] ={
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3e,0xff,0xff,0xff,0x3f,
-0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,
-0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0xff,0xff,0xff,0xff,0xff,
-0xff,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
-0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+static const uint8_t kBase64DecodeTable[256] = {
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0x3e,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0x3f,
+ 0x34,
+ 0x35,
+ 0x36,
+ 0x37,
+ 0x38,
+ 0x39,
+ 0x3a,
+ 0x3b,
+ 0x3c,
+ 0x3d,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0x00,
+ 0x01,
+ 0x02,
+ 0x03,
+ 0x04,
+ 0x05,
+ 0x06,
+ 0x07,
+ 0x08,
+ 0x09,
+ 0x0a,
+ 0x0b,
+ 0x0c,
+ 0x0d,
+ 0x0e,
+ 0x0f,
+ 0x10,
+ 0x11,
+ 0x12,
+ 0x13,
+ 0x14,
+ 0x15,
+ 0x16,
+ 0x17,
+ 0x18,
+ 0x19,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0x1a,
+ 0x1b,
+ 0x1c,
+ 0x1d,
+ 0x1e,
+ 0x1f,
+ 0x20,
+ 0x21,
+ 0x22,
+ 0x23,
+ 0x24,
+ 0x25,
+ 0x26,
+ 0x27,
+ 0x28,
+ 0x29,
+ 0x2a,
+ 0x2b,
+ 0x2c,
+ 0x2d,
+ 0x2e,
+ 0x2f,
+ 0x30,
+ 0x31,
+ 0x32,
+ 0x33,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
+ 0xff,
};
-void base64_decode(uint8_t *buf, uint32_t len) {
- buf[0] = (kBase64DecodeTable[buf[0]] << 2) |
- (kBase64DecodeTable[buf[1]] >> 4);
+void base64_decode(uint8_t* buf, uint32_t len) {
+ buf[0] = (kBase64DecodeTable[buf[0]] << 2) | (kBase64DecodeTable[buf[1]] >> 4);
if (len > 2) {
- buf[1] = ((kBase64DecodeTable[buf[1]] << 4) & 0xf0) |
- (kBase64DecodeTable[buf[2]] >> 2);
+ buf[1] = ((kBase64DecodeTable[buf[1]] << 4) & 0xf0) | (kBase64DecodeTable[buf[2]] >> 2);
if (len > 3) {
- buf[2] = ((kBase64DecodeTable[buf[2]] << 6) & 0xc0) |
- (kBase64DecodeTable[buf[3]]);
+ buf[2] = ((kBase64DecodeTable[buf[2]] << 6) & 0xc0) | (kBase64DecodeTable[buf[3]]);
}
}
}
-
-
-}}} // apache::thrift::protocol
+}
+}
+} // apache::thrift::protocol
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/protocol/TBase64Utils.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TBase64Utils.h b/lib/cpp/src/thrift/protocol/TBase64Utils.h
index 3def733..1ea6744 100644
--- a/lib/cpp/src/thrift/protocol/TBase64Utils.h
+++ b/lib/cpp/src/thrift/protocol/TBase64Utils.h
@@ -23,20 +23,23 @@
#include <stdint.h>
#include <string>
-namespace apache { namespace thrift { namespace protocol {
+namespace apache {
+namespace thrift {
+namespace protocol {
// in must be at least len bytes
// len must be 1, 2, or 3
// buf must be a buffer of at least 4 bytes and may not overlap in
// the data is not padded with '='; the caller can do this if desired
-void base64_encode(const uint8_t *in, uint32_t len, uint8_t *buf);
+void base64_encode(const uint8_t* in, uint32_t len, uint8_t* buf);
// buf must be a buffer of at least 4 bytes and contain base64 encoded values
// buf will be changed to contain output bytes
// len is number of bytes to consume from input (must be 2, 3, or 4)
// no '=' padding should be included in the input
-void base64_decode(uint8_t *buf, uint32_t len);
-
-}}} // apache::thrift::protocol
+void base64_decode(uint8_t* buf, uint32_t len);
+}
+}
+} // apache::thrift::protocol
#endif // #define _THRIFT_PROTOCOL_TBASE64UTILS_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/protocol/TBinaryProtocol.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TBinaryProtocol.h b/lib/cpp/src/thrift/protocol/TBinaryProtocol.h
index a5b19e5..88b91e5 100644
--- a/lib/cpp/src/thrift/protocol/TBinaryProtocol.h
+++ b/lib/cpp/src/thrift/protocol/TBinaryProtocol.h
@@ -25,7 +25,9 @@
#include <boost/shared_ptr.hpp>
-namespace apache { namespace thrift { namespace protocol {
+namespace apache {
+namespace thrift {
+namespace protocol {
/**
* The default binary protocol for thrift. Writes all data in a very basic
@@ -33,37 +35,36 @@ namespace apache { namespace thrift { namespace protocol {
*
*/
template <class Transport_>
-class TBinaryProtocolT
- : public TVirtualProtocol< TBinaryProtocolT<Transport_> > {
- protected:
+class TBinaryProtocolT : public TVirtualProtocol<TBinaryProtocolT<Transport_> > {
+protected:
static const int32_t VERSION_MASK = ((int32_t)0xffff0000);
static const int32_t VERSION_1 = ((int32_t)0x80010000);
// VERSION_2 (0x80020000) is taken by TDenseProtocol.
- public:
- TBinaryProtocolT(boost::shared_ptr<Transport_> trans) :
- TVirtualProtocol< TBinaryProtocolT<Transport_> >(trans),
- trans_(trans.get()),
- string_limit_(0),
- container_limit_(0),
- strict_read_(false),
- strict_write_(true),
- string_buf_(NULL),
- string_buf_size_(0) {}
+public:
+ TBinaryProtocolT(boost::shared_ptr<Transport_> trans)
+ : TVirtualProtocol<TBinaryProtocolT<Transport_> >(trans),
+ trans_(trans.get()),
+ string_limit_(0),
+ container_limit_(0),
+ strict_read_(false),
+ strict_write_(true),
+ string_buf_(NULL),
+ string_buf_size_(0) {}
TBinaryProtocolT(boost::shared_ptr<Transport_> trans,
int32_t string_limit,
int32_t container_limit,
bool strict_read,
- bool strict_write) :
- TVirtualProtocol< TBinaryProtocolT<Transport_> >(trans),
- trans_(trans.get()),
- string_limit_(string_limit),
- container_limit_(container_limit),
- strict_read_(strict_read),
- strict_write_(strict_write),
- string_buf_(NULL),
- string_buf_size_(0) {}
+ bool strict_write)
+ : TVirtualProtocol<TBinaryProtocolT<Transport_> >(trans),
+ trans_(trans.get()),
+ string_limit_(string_limit),
+ container_limit_(container_limit),
+ strict_read_(strict_read),
+ strict_write_(strict_write),
+ string_buf_(NULL),
+ string_buf_size_(0) {}
~TBinaryProtocolT() {
if (string_buf_ != NULL) {
@@ -72,13 +73,9 @@ class TBinaryProtocolT
}
}
- void setStringSizeLimit(int32_t string_limit) {
- string_limit_ = string_limit;
- }
+ void setStringSizeLimit(int32_t string_limit) { string_limit_ = string_limit; }
- void setContainerSizeLimit(int32_t container_limit) {
- container_limit_ = container_limit;
- }
+ void setContainerSizeLimit(int32_t container_limit) { container_limit_ = container_limit; }
void setStrict(bool strict_read, bool strict_write) {
strict_read_ = strict_read;
@@ -95,22 +92,17 @@ class TBinaryProtocolT
/*ol*/ uint32_t writeMessageEnd();
-
inline uint32_t writeStructBegin(const char* name);
inline uint32_t writeStructEnd();
- inline uint32_t writeFieldBegin(const char* name,
- const TType fieldType,
- const int16_t fieldId);
+ inline uint32_t writeFieldBegin(const char* name, const TType fieldType, const int16_t fieldId);
inline uint32_t writeFieldEnd();
inline uint32_t writeFieldStop();
- inline uint32_t writeMapBegin(const TType keyType,
- const TType valType,
- const uint32_t size);
+ inline uint32_t writeMapBegin(const TType keyType, const TType valType, const uint32_t size);
inline uint32_t writeMapEnd();
@@ -143,10 +135,7 @@ class TBinaryProtocolT
* Reading functions
*/
-
- /*ol*/ uint32_t readMessageBegin(std::string& name,
- TMessageType& messageType,
- int32_t& seqid);
+ /*ol*/ uint32_t readMessageBegin(std::string& name, TMessageType& messageType, int32_t& seqid);
/*ol*/ uint32_t readMessageEnd();
@@ -154,15 +143,11 @@ class TBinaryProtocolT
inline uint32_t readStructEnd();
- inline uint32_t readFieldBegin(std::string& name,
- TType& fieldType,
- int16_t& fieldId);
+ inline uint32_t readFieldBegin(std::string& name, TType& fieldType, int16_t& fieldId);
inline uint32_t readFieldEnd();
- inline uint32_t readMapBegin(TType& keyType,
- TType& valType,
- uint32_t& size);
+ inline uint32_t readMapBegin(TType& keyType, TType& valType, uint32_t& size);
inline uint32_t readMapEnd();
@@ -176,7 +161,7 @@ class TBinaryProtocolT
inline uint32_t readBool(bool& value);
// Provide the default readBool() implementation for std::vector<bool>
- using TVirtualProtocol< TBinaryProtocolT<Transport_> >::readBool;
+ using TVirtualProtocol<TBinaryProtocolT<Transport_> >::readBool;
inline uint32_t readByte(int8_t& byte);
@@ -188,13 +173,13 @@ class TBinaryProtocolT
inline uint32_t readDouble(double& dub);
- template<typename StrType>
+ template <typename StrType>
inline uint32_t readString(StrType& str);
inline uint32_t readBinary(std::string& str);
- protected:
- template<typename StrType>
+protected:
+ template <typename StrType>
uint32_t readStringBody(StrType& str, int32_t sz);
Transport_* trans_;
@@ -210,7 +195,6 @@ class TBinaryProtocolT
// avoid memory churn allocating memory on every string read
uint8_t* string_buf_;
int32_t string_buf_size_;
-
};
typedef TBinaryProtocolT<TTransport> TBinaryProtocol;
@@ -220,29 +204,24 @@ typedef TBinaryProtocolT<TTransport> TBinaryProtocol;
*/
template <class Transport_>
class TBinaryProtocolFactoryT : public TProtocolFactory {
- public:
- TBinaryProtocolFactoryT() :
- string_limit_(0),
- container_limit_(0),
- strict_read_(false),
- strict_write_(true) {}
-
- TBinaryProtocolFactoryT(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) {}
+public:
+ TBinaryProtocolFactoryT()
+ : string_limit_(0), container_limit_(0), strict_read_(false), strict_write_(true) {}
+
+ TBinaryProtocolFactoryT(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 ~TBinaryProtocolFactoryT() {}
- void setStringSizeLimit(int32_t string_limit) {
- string_limit_ = string_limit;
- }
+ void setStringSizeLimit(int32_t string_limit) { string_limit_ = string_limit; }
- void setContainerSizeLimit(int32_t container_limit) {
- container_limit_ = container_limit;
- }
+ void setContainerSizeLimit(int32_t container_limit) { container_limit_ = container_limit; }
void setStrict(bool strict_read, bool strict_write) {
strict_read_ = strict_read;
@@ -250,32 +229,36 @@ class TBinaryProtocolFactoryT : public TProtocolFactory {
}
boost::shared_ptr<TProtocol> getProtocol(boost::shared_ptr<TTransport> trans) {
- boost::shared_ptr<Transport_> specific_trans =
- boost::dynamic_pointer_cast<Transport_>(trans);
+ boost::shared_ptr<Transport_> specific_trans = boost::dynamic_pointer_cast<Transport_>(trans);
TProtocol* prot;
if (specific_trans) {
- prot = new TBinaryProtocolT<Transport_>(specific_trans, string_limit_,
- container_limit_, strict_read_,
+ prot = new TBinaryProtocolT<Transport_>(specific_trans,
+ string_limit_,
+ container_limit_,
+ strict_read_,
strict_write_);
} else {
- prot = new TBinaryProtocol(trans, string_limit_, container_limit_,
- strict_read_, strict_write_);
+ prot = new TBinaryProtocol(trans,
+ string_limit_,
+ container_limit_,
+ strict_read_,
+ strict_write_);
}
return boost::shared_ptr<TProtocol>(prot);
}
- private:
+private:
int32_t string_limit_;
int32_t container_limit_;
bool strict_read_;
bool strict_write_;
-
};
typedef TBinaryProtocolFactoryT<TTransport> TBinaryProtocolFactory;
-
-}}} // apache::thrift::protocol
+}
+}
+} // apache::thrift::protocol
#include <thrift/protocol/TBinaryProtocol.tcc>
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc b/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
index 40226a5..0d72d8a 100644
--- a/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
+++ b/lib/cpp/src/thrift/protocol/TBinaryProtocol.tcc
@@ -24,8 +24,9 @@
#include <limits>
-
-namespace apache { namespace thrift { namespace protocol {
+namespace apache {
+namespace thrift {
+namespace protocol {
template <class Transport_>
uint32_t TBinaryProtocolT<Transport_>::writeMessageBegin(const std::string& name,
@@ -54,7 +55,7 @@ uint32_t TBinaryProtocolT<Transport_>::writeMessageEnd() {
template <class Transport_>
uint32_t TBinaryProtocolT<Transport_>::writeStructBegin(const char* name) {
- (void) name;
+ (void)name;
return 0;
}
@@ -67,7 +68,7 @@ template <class Transport_>
uint32_t TBinaryProtocolT<Transport_>::writeFieldBegin(const char* name,
const TType fieldType,
const int16_t fieldId) {
- (void) name;
+ (void)name;
uint32_t wsize = 0;
wsize += writeByte((int8_t)fieldType);
wsize += writeI16(fieldId);
@@ -81,8 +82,7 @@ uint32_t TBinaryProtocolT<Transport_>::writeFieldEnd() {
template <class Transport_>
uint32_t TBinaryProtocolT<Transport_>::writeFieldStop() {
- return
- writeByte((int8_t)T_STOP);
+ return writeByte((int8_t)T_STOP);
}
template <class Transport_>
@@ -102,10 +102,9 @@ uint32_t TBinaryProtocolT<Transport_>::writeMapEnd() {
}
template <class Transport_>
-uint32_t TBinaryProtocolT<Transport_>::writeListBegin(const TType elemType,
- const uint32_t size) {
+uint32_t TBinaryProtocolT<Transport_>::writeListBegin(const TType elemType, const uint32_t size) {
uint32_t wsize = 0;
- wsize += writeByte((int8_t) elemType);
+ wsize += writeByte((int8_t)elemType);
wsize += writeI32((int32_t)size);
return wsize;
}
@@ -116,8 +115,7 @@ uint32_t TBinaryProtocolT<Transport_>::writeListEnd() {
}
template <class Transport_>
-uint32_t TBinaryProtocolT<Transport_>::writeSetBegin(const TType elemType,
- const uint32_t size) {
+uint32_t TBinaryProtocolT<Transport_>::writeSetBegin(const TType elemType, const uint32_t size) {
uint32_t wsize = 0;
wsize += writeByte((int8_t)elemType);
wsize += writeI32((int32_t)size);
@@ -131,7 +129,7 @@ uint32_t TBinaryProtocolT<Transport_>::writeSetEnd() {
template <class Transport_>
uint32_t TBinaryProtocolT<Transport_>::writeBool(const bool value) {
- uint8_t tmp = value ? 1 : 0;
+ uint8_t tmp = value ? 1 : 0;
this->trans_->write(&tmp, 1);
return 1;
}
@@ -174,11 +172,10 @@ uint32_t TBinaryProtocolT<Transport_>::writeDouble(const double dub) {
return 8;
}
-
template <class Transport_>
-template<typename StrType>
+template <typename StrType>
uint32_t TBinaryProtocolT<Transport_>::writeString(const StrType& str) {
- if(str.size() > static_cast<size_t>((std::numeric_limits<int32_t>::max)()))
+ if (str.size() > static_cast<size_t>((std::numeric_limits<int32_t>::max)()))
throw TProtocolException(TProtocolException::SIZE_LIMIT);
uint32_t size = static_cast<uint32_t>(str.size());
uint32_t result = writeI32((int32_t)size);
@@ -216,7 +213,8 @@ uint32_t TBinaryProtocolT<Transport_>::readMessageBegin(std::string& name,
result += readI32(seqid);
} else {
if (this->strict_read_) {
- throw TProtocolException(TProtocolException::BAD_VERSION, "No version identifier... old protocol client in strict mode?");
+ throw TProtocolException(TProtocolException::BAD_VERSION,
+ "No version identifier... old protocol client in strict mode?");
} else {
// Handle pre-versioned input
int8_t type;
@@ -249,7 +247,7 @@ template <class Transport_>
uint32_t TBinaryProtocolT<Transport_>::readFieldBegin(std::string& name,
TType& fieldType,
int16_t& fieldId) {
- (void) name;
+ (void)name;
uint32_t result = 0;
int8_t type;
result += readByte(type);
@@ -294,8 +292,7 @@ uint32_t TBinaryProtocolT<Transport_>::readMapEnd() {
}
template <class Transport_>
-uint32_t TBinaryProtocolT<Transport_>::readListBegin(TType& elemType,
- uint32_t& size) {
+uint32_t TBinaryProtocolT<Transport_>::readListBegin(TType& elemType, uint32_t& size) {
int8_t e;
uint32_t result = 0;
int32_t sizei;
@@ -317,8 +314,7 @@ uint32_t TBinaryProtocolT<Transport_>::readListEnd() {
}
template <class Transport_>
-uint32_t TBinaryProtocolT<Transport_>::readSetBegin(TType& elemType,
- uint32_t& size) {
+uint32_t TBinaryProtocolT<Transport_>::readSetBegin(TType& elemType, uint32_t& size) {
int8_t e;
uint32_t result = 0;
int32_t sizei;
@@ -404,7 +400,7 @@ uint32_t TBinaryProtocolT<Transport_>::readDouble(double& dub) {
}
template <class Transport_>
-template<typename StrType>
+template <typename StrType>
uint32_t TBinaryProtocolT<Transport_>::readString(StrType& str) {
uint32_t result;
int32_t size;
@@ -418,9 +414,8 @@ uint32_t TBinaryProtocolT<Transport_>::readBinary(std::string& str) {
}
template <class Transport_>
-template<typename StrType>
-uint32_t TBinaryProtocolT<Transport_>::readStringBody(StrType& str,
- int32_t size) {
+template <typename StrType>
+uint32_t TBinaryProtocolT<Transport_>::readStringBody(StrType& str, int32_t size) {
uint32_t result = 0;
// Catch error cases
@@ -447,10 +442,11 @@ uint32_t TBinaryProtocolT<Transport_>::readStringBody(StrType& str,
}
str.resize(size);
- this->trans_->readAll(reinterpret_cast<uint8_t *>(&str[0]), size);
+ this->trans_->readAll(reinterpret_cast<uint8_t*>(&str[0]), size);
return (uint32_t)size;
}
-
-}}} // apache::thrift::protocol
+}
+}
+} // apache::thrift::protocol
#endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_TCC_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/protocol/TCompactProtocol.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TCompactProtocol.h b/lib/cpp/src/thrift/protocol/TCompactProtocol.h
index ce60b45..5b7ade2 100644
--- a/lib/cpp/src/thrift/protocol/TCompactProtocol.h
+++ b/lib/cpp/src/thrift/protocol/TCompactProtocol.h
@@ -25,21 +25,22 @@
#include <stack>
#include <boost/shared_ptr.hpp>
-namespace apache { namespace thrift { namespace protocol {
+namespace apache {
+namespace thrift {
+namespace protocol {
/**
* C++ Implementation of the Compact Protocol as described in THRIFT-110
*/
template <class Transport_>
-class TCompactProtocolT
- : public TVirtualProtocol< TCompactProtocolT<Transport_> > {
-
- protected:
- static const int8_t PROTOCOL_ID = (int8_t)0x82u;
- static const int8_t VERSION_N = 1;
- static const int8_t VERSION_MASK = 0x1f; // 0001 1111
- static const int8_t TYPE_MASK = (int8_t)0xE0u; // 1110 0000
- static const int8_t TYPE_BITS = 0x07; // 0000 0111
+class TCompactProtocolT : public TVirtualProtocol<TCompactProtocolT<Transport_> > {
+
+protected:
+ static const int8_t PROTOCOL_ID = (int8_t)0x82u;
+ static const int8_t VERSION_N = 1;
+ static const int8_t VERSION_MASK = 0x1f; // 0001 1111
+ static const int8_t TYPE_MASK = (int8_t)0xE0u; // 1110 0000
+ static const int8_t TYPE_BITS = 0x07; // 0000 0111
static const int32_t TYPE_SHIFT_AMOUNT = 5;
Transport_* trans_;
@@ -71,37 +72,34 @@ class TCompactProtocolT
std::stack<int16_t> lastField_;
int16_t lastFieldId_;
- public:
- TCompactProtocolT(boost::shared_ptr<Transport_> trans) :
- TVirtualProtocol< TCompactProtocolT<Transport_> >(trans),
- trans_(trans.get()),
- lastFieldId_(0),
- string_limit_(0),
- string_buf_(NULL),
- string_buf_size_(0),
- container_limit_(0) {
+public:
+ TCompactProtocolT(boost::shared_ptr<Transport_> trans)
+ : TVirtualProtocol<TCompactProtocolT<Transport_> >(trans),
+ trans_(trans.get()),
+ lastFieldId_(0),
+ string_limit_(0),
+ string_buf_(NULL),
+ string_buf_size_(0),
+ container_limit_(0) {
booleanField_.name = NULL;
boolValue_.hasBoolValue = false;
}
TCompactProtocolT(boost::shared_ptr<Transport_> trans,
int32_t string_limit,
- int32_t container_limit) :
- TVirtualProtocol< TCompactProtocolT<Transport_> >(trans),
- trans_(trans.get()),
- lastFieldId_(0),
- string_limit_(string_limit),
- string_buf_(NULL),
- string_buf_size_(0),
- container_limit_(container_limit) {
+ int32_t container_limit)
+ : TVirtualProtocol<TCompactProtocolT<Transport_> >(trans),
+ trans_(trans.get()),
+ lastFieldId_(0),
+ string_limit_(string_limit),
+ string_buf_(NULL),
+ string_buf_size_(0),
+ container_limit_(container_limit) {
booleanField_.name = NULL;
boolValue_.hasBoolValue = false;
}
- ~TCompactProtocolT() {
- free(string_buf_);
- }
-
+ ~TCompactProtocolT() { free(string_buf_); }
/**
* Writing functions
@@ -115,21 +113,15 @@ class TCompactProtocolT
uint32_t writeStructEnd();
- uint32_t writeFieldBegin(const char* name,
- const TType fieldType,
- const int16_t fieldId);
+ uint32_t writeFieldBegin(const char* name, const TType fieldType, const int16_t fieldId);
uint32_t writeFieldStop();
- uint32_t writeListBegin(const TType elemType,
- const uint32_t size);
+ uint32_t writeListBegin(const TType elemType, const uint32_t size);
- uint32_t writeSetBegin(const TType elemType,
- const uint32_t size);
+ uint32_t writeSetBegin(const TType elemType, const uint32_t size);
- virtual uint32_t writeMapBegin(const TType keyType,
- const TType valType,
- const uint32_t size);
+ virtual uint32_t writeMapBegin(const TType keyType, const TType valType, const uint32_t size);
uint32_t writeBool(const bool value);
@@ -157,7 +149,7 @@ class TCompactProtocolT
uint32_t writeSetEnd() { return 0; }
uint32_t writeFieldEnd() { return 0; }
- protected:
+protected:
int32_t writeFieldBeginInternal(const char* name,
const TType fieldType,
const int16_t fieldId,
@@ -169,32 +161,24 @@ class TCompactProtocolT
uint32_t i32ToZigzag(const int32_t n);
inline int8_t getCompactType(const TType ttype);
- public:
- uint32_t readMessageBegin(std::string& name,
- TMessageType& messageType,
- int32_t& seqid);
+public:
+ uint32_t readMessageBegin(std::string& name, TMessageType& messageType, int32_t& seqid);
uint32_t readStructBegin(std::string& name);
uint32_t readStructEnd();
- uint32_t readFieldBegin(std::string& name,
- TType& fieldType,
- int16_t& fieldId);
+ uint32_t readFieldBegin(std::string& name, TType& fieldType, int16_t& fieldId);
- uint32_t readMapBegin(TType& keyType,
- TType& valType,
- uint32_t& size);
+ uint32_t readMapBegin(TType& keyType, TType& valType, uint32_t& size);
- uint32_t readListBegin(TType& elemType,
- uint32_t& size);
+ uint32_t readListBegin(TType& elemType, uint32_t& size);
- uint32_t readSetBegin(TType& elemType,
- uint32_t& size);
+ uint32_t readSetBegin(TType& elemType, uint32_t& size);
uint32_t readBool(bool& value);
// Provide the default readBool() implementation for std::vector<bool>
- using TVirtualProtocol< TCompactProtocolT<Transport_> >::readBool;
+ using TVirtualProtocol<TCompactProtocolT<Transport_> >::readBool;
uint32_t readByte(int8_t& byte);
@@ -220,7 +204,7 @@ class TCompactProtocolT
uint32_t readListEnd() { return 0; }
uint32_t readSetEnd() { return 0; }
- protected:
+protected:
uint32_t readVarint32(int32_t& i32);
uint32_t readVarint64(int64_t& i64);
int32_t zigzagToI32(uint32_t n);
@@ -242,32 +226,23 @@ typedef TCompactProtocolT<TTransport> TCompactProtocol;
*/
template <class Transport_>
class TCompactProtocolFactoryT : public TProtocolFactory {
- public:
- TCompactProtocolFactoryT() :
- string_limit_(0),
- container_limit_(0) {}
+public:
+ TCompactProtocolFactoryT() : string_limit_(0), container_limit_(0) {}
- TCompactProtocolFactoryT(int32_t string_limit, int32_t container_limit) :
- string_limit_(string_limit),
- container_limit_(container_limit) {}
+ TCompactProtocolFactoryT(int32_t string_limit, int32_t container_limit)
+ : string_limit_(string_limit), container_limit_(container_limit) {}
virtual ~TCompactProtocolFactoryT() {}
- void setStringSizeLimit(int32_t string_limit) {
- string_limit_ = string_limit;
- }
+ void setStringSizeLimit(int32_t string_limit) { string_limit_ = string_limit; }
- void setContainerSizeLimit(int32_t container_limit) {
- container_limit_ = container_limit;
- }
+ void setContainerSizeLimit(int32_t container_limit) { container_limit_ = container_limit; }
boost::shared_ptr<TProtocol> getProtocol(boost::shared_ptr<TTransport> trans) {
- boost::shared_ptr<Transport_> specific_trans =
- boost::dynamic_pointer_cast<Transport_>(trans);
+ boost::shared_ptr<Transport_> specific_trans = boost::dynamic_pointer_cast<Transport_>(trans);
TProtocol* prot;
if (specific_trans) {
- prot = new TCompactProtocolT<Transport_>(specific_trans, string_limit_,
- container_limit_);
+ prot = new TCompactProtocolT<Transport_>(specific_trans, string_limit_, container_limit_);
} else {
prot = new TCompactProtocol(trans, string_limit_, container_limit_);
}
@@ -275,15 +250,15 @@ class TCompactProtocolFactoryT : public TProtocolFactory {
return boost::shared_ptr<TProtocol>(prot);
}
- private:
+private:
int32_t string_limit_;
int32_t container_limit_;
-
};
typedef TCompactProtocolFactoryT<TTransport> TCompactProtocolFactory;
-
-}}} // apache::thrift::protocol
+}
+}
+} // apache::thrift::protocol
#include <thrift/protocol/TCompactProtocol.tcc>
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/protocol/TDebugProtocol.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TDebugProtocol.cpp b/lib/cpp/src/thrift/protocol/TDebugProtocol.cpp
index 63ea14d..4687e82 100644
--- a/lib/cpp/src/thrift/protocol/TDebugProtocol.cpp
+++ b/lib/cpp/src/thrift/protocol/TDebugProtocol.cpp
@@ -28,7 +28,6 @@
using std::string;
-
static string byte_to_hex(const uint8_t byte) {
char buf[3];
int ret = std::sprintf(buf, "%02x", (int)byte);
@@ -38,28 +37,46 @@ static string byte_to_hex(const uint8_t byte) {
return buf;
}
-
-namespace apache { namespace thrift { namespace protocol {
+namespace apache {
+namespace thrift {
+namespace protocol {
string TDebugProtocol::fieldTypeName(TType type) {
switch (type) {
- case T_STOP : return "stop" ;
- case T_VOID : return "void" ;
- case T_BOOL : return "bool" ;
- case T_BYTE : return "byte" ;
- case T_I16 : return "i16" ;
- case T_I32 : return "i32" ;
- case T_U64 : return "u64" ;
- case T_I64 : return "i64" ;
- case T_DOUBLE : return "double" ;
- case T_STRING : return "string" ;
- case T_STRUCT : return "struct" ;
- case T_MAP : return "map" ;
- case T_SET : return "set" ;
- case T_LIST : return "list" ;
- case T_UTF8 : return "utf8" ;
- case T_UTF16 : return "utf16" ;
- default: return "unknown";
+ case T_STOP:
+ return "stop";
+ case T_VOID:
+ return "void";
+ case T_BOOL:
+ return "bool";
+ case T_BYTE:
+ return "byte";
+ case T_I16:
+ return "i16";
+ case T_I32:
+ return "i32";
+ case T_U64:
+ return "u64";
+ case T_I64:
+ return "i64";
+ case T_DOUBLE:
+ return "double";
+ case T_STRING:
+ return "string";
+ case T_STRUCT:
+ return "struct";
+ case T_MAP:
+ return "map";
+ case T_SET:
+ return "set";
+ case T_LIST:
+ return "list";
+ case T_UTF8:
+ return "utf8";
+ case T_UTF16:
+ return "utf16";
+ default:
+ return "unknown";
}
}
@@ -75,19 +92,19 @@ void TDebugProtocol::indentDown() {
}
uint32_t TDebugProtocol::writePlain(const string& str) {
- if(str.length() > (std::numeric_limits<uint32_t>::max)())
+ if (str.length() > (std::numeric_limits<uint32_t>::max)())
throw TProtocolException(TProtocolException::SIZE_LIMIT);
trans_->write((uint8_t*)str.data(), static_cast<uint32_t>(str.length()));
return static_cast<uint32_t>(str.length());
}
uint32_t TDebugProtocol::writeIndented(const string& str) {
- if(str.length() > (std::numeric_limits<uint32_t>::max)())
+ if (str.length() > (std::numeric_limits<uint32_t>::max)())
throw TProtocolException(TProtocolException::SIZE_LIMIT);
- if(indent_str_.length() > (std::numeric_limits<uint32_t>::max)())
+ if (indent_str_.length() > (std::numeric_limits<uint32_t>::max)())
throw TProtocolException(TProtocolException::SIZE_LIMIT);
uint64_t total_len = indent_str_.length() + str.length();
- if(total_len > (std::numeric_limits<uint32_t>::max)())
+ if (total_len > (std::numeric_limits<uint32_t>::max)())
throw TProtocolException(TProtocolException::SIZE_LIMIT);
trans_->write((uint8_t*)indent_str_.data(), static_cast<uint32_t>(indent_str_.length()));
trans_->write((uint8_t*)str.data(), static_cast<uint32_t>(str.length()));
@@ -98,52 +115,51 @@ uint32_t TDebugProtocol::startItem() {
uint32_t size;
switch (write_state_.back()) {
- case UNINIT:
- // XXX figure out what to do here.
- //throw TProtocolException(TProtocolException::INVALID_DATA);
- //return writeIndented(str);
- return 0;
- case STRUCT:
- return 0;
- case SET:
- return writeIndented("");
- case MAP_KEY:
- return writeIndented("");
- case MAP_VALUE:
- return writePlain(" -> ");
- case LIST:
- size = writeIndented(
- "[" + boost::lexical_cast<string>(list_idx_.back()) + "] = ");
- list_idx_.back()++;
- return size;
- default:
- throw std::logic_error("Invalid enum value.");
+ case UNINIT:
+ // XXX figure out what to do here.
+ // throw TProtocolException(TProtocolException::INVALID_DATA);
+ // return writeIndented(str);
+ return 0;
+ case STRUCT:
+ return 0;
+ case SET:
+ return writeIndented("");
+ case MAP_KEY:
+ return writeIndented("");
+ case MAP_VALUE:
+ return writePlain(" -> ");
+ case LIST:
+ size = writeIndented("[" + boost::lexical_cast<string>(list_idx_.back()) + "] = ");
+ list_idx_.back()++;
+ return size;
+ default:
+ throw std::logic_error("Invalid enum value.");
}
}
uint32_t TDebugProtocol::endItem() {
- //uint32_t size;
+ // uint32_t size;
switch (write_state_.back()) {
- case UNINIT:
- // XXX figure out what to do here.
- //throw TProtocolException(TProtocolException::INVALID_DATA);
- //return writeIndented(str);
- return 0;
- case STRUCT:
- return writePlain(",\n");
- case SET:
- return writePlain(",\n");
- case MAP_KEY:
- write_state_.back() = MAP_VALUE;
- return 0;
- case MAP_VALUE:
- write_state_.back() = MAP_KEY;
- return writePlain(",\n");
- case LIST:
- return writePlain(",\n");
- default:
- throw std::logic_error("Invalid enum value.");
+ case UNINIT:
+ // XXX figure out what to do here.
+ // throw TProtocolException(TProtocolException::INVALID_DATA);
+ // return writeIndented(str);
+ return 0;
+ case STRUCT:
+ return writePlain(",\n");
+ case SET:
+ return writePlain(",\n");
+ case MAP_KEY:
+ write_state_.back() = MAP_VALUE;
+ return 0;
+ case MAP_VALUE:
+ write_state_.back() = MAP_KEY;
+ return writePlain(",\n");
+ case LIST:
+ return writePlain(",\n");
+ default:
+ throw std::logic_error("Invalid enum value.");
}
}
@@ -158,13 +174,21 @@ uint32_t TDebugProtocol::writeItem(const std::string& str) {
uint32_t TDebugProtocol::writeMessageBegin(const std::string& name,
const TMessageType messageType,
const int32_t seqid) {
- (void) seqid;
+ (void)seqid;
string mtype;
switch (messageType) {
- case T_CALL : mtype = "call" ; break;
- case T_REPLY : mtype = "reply" ; break;
- case T_EXCEPTION : mtype = "exn" ; break;
- case T_ONEWAY : mtype = "oneway" ; break;
+ case T_CALL:
+ mtype = "call";
+ break;
+ case T_REPLY:
+ mtype = "reply";
+ break;
+ case T_EXCEPTION:
+ mtype = "exn";
+ break;
+ case T_ONEWAY:
+ mtype = "oneway";
+ break;
}
uint32_t size = writeIndented("(" + mtype + ") " + name + "(");
@@ -200,12 +224,10 @@ uint32_t TDebugProtocol::writeFieldBegin(const char* name,
const int16_t fieldId) {
// sprintf(id_str, "%02d", fieldId);
string id_str = boost::lexical_cast<string>(fieldId);
- if (id_str.length() == 1) id_str = '0' + id_str;
+ if (id_str.length() == 1)
+ id_str = '0' + id_str;
- return writeIndented(
- id_str + ": " +
- name + " (" +
- fieldTypeName(fieldType) + ") = ");
+ return writeIndented(id_str + ": " + name + " (" + fieldTypeName(fieldType) + ") = ");
}
uint32_t TDebugProtocol::writeFieldEnd() {
@@ -215,7 +237,7 @@ uint32_t TDebugProtocol::writeFieldEnd() {
uint32_t TDebugProtocol::writeFieldStop() {
return 0;
- //writeIndented("***STOP***\n");
+ // writeIndented("***STOP***\n");
}
uint32_t TDebugProtocol::writeMapBegin(const TType keyType,
@@ -241,8 +263,7 @@ uint32_t TDebugProtocol::writeMapEnd() {
return size;
}
-uint32_t TDebugProtocol::writeListBegin(const TType elemType,
- const uint32_t size) {
+uint32_t TDebugProtocol::writeListBegin(const TType elemType, const uint32_t size) {
// TODO(dreiss): Optimize short arrays.
uint32_t bsize = 0;
bsize += startItem();
@@ -265,8 +286,7 @@ uint32_t TDebugProtocol::writeListEnd() {
return size;
}
-uint32_t TDebugProtocol::writeSetBegin(const TType elemType,
- const uint32_t size) {
+uint32_t TDebugProtocol::writeSetBegin(const TType elemType, const uint32_t size) {
// TODO(dreiss): Optimize short sets.
uint32_t bsize = 0;
bsize += startItem();
@@ -311,7 +331,6 @@ uint32_t TDebugProtocol::writeDouble(const double dub) {
return writeItem(boost::lexical_cast<string>(dub));
}
-
uint32_t TDebugProtocol::writeString(const string& str) {
// XXX Raw/UTF-8?
@@ -332,16 +351,30 @@ uint32_t TDebugProtocol::writeString(const string& str) {
output += *it;
} else {
switch (*it) {
- case '\a': output += "\\a"; break;
- case '\b': output += "\\b"; break;
- case '\f': output += "\\f"; break;
- case '\n': output += "\\n"; break;
- case '\r': output += "\\r"; break;
- case '\t': output += "\\t"; break;
- case '\v': output += "\\v"; break;
- default:
- output += "\\x";
- output += byte_to_hex(*it);
+ case '\a':
+ output += "\\a";
+ break;
+ case '\b':
+ output += "\\b";
+ break;
+ case '\f':
+ output += "\\f";
+ break;
+ case '\n':
+ output += "\\n";
+ break;
+ case '\r':
+ output += "\\r";
+ break;
+ case '\t':
+ output += "\\t";
+ break;
+ case '\v':
+ output += "\\v";
+ break;
+ default:
+ output += "\\x";
+ output += byte_to_hex(*it);
}
}
}
@@ -354,5 +387,6 @@ uint32_t TDebugProtocol::writeBinary(const string& str) {
// XXX Hex?
return TDebugProtocol::writeString(str);
}
-
-}}} // apache::thrift::protocol
+}
+}
+} // apache::thrift::protocol
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/protocol/TDebugProtocol.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TDebugProtocol.h b/lib/cpp/src/thrift/protocol/TDebugProtocol.h
index f85e691..cc93230 100644
--- a/lib/cpp/src/thrift/protocol/TDebugProtocol.h
+++ b/lib/cpp/src/thrift/protocol/TDebugProtocol.h
@@ -24,7 +24,9 @@
#include <boost/shared_ptr.hpp>
-namespace apache { namespace thrift { namespace protocol {
+namespace apache {
+namespace thrift {
+namespace protocol {
/*
@@ -39,44 +41,30 @@ Complaints are not. :R
*/
-
/**
* Protocol that prints the payload in a nice human-readable format.
* Reading from this protocol is not supported.
*
*/
class TDebugProtocol : public TVirtualProtocol<TDebugProtocol> {
- private:
- enum write_state_t
- { UNINIT
- , STRUCT
- , LIST
- , SET
- , MAP_KEY
- , MAP_VALUE
- };
-
- public:
+private:
+ enum write_state_t { UNINIT, STRUCT, LIST, SET, MAP_KEY, MAP_VALUE };
+
+public:
TDebugProtocol(boost::shared_ptr<TTransport> trans)
- : TVirtualProtocol<TDebugProtocol>(trans)
- , trans_(trans.get())
- , string_limit_(DEFAULT_STRING_LIMIT)
- , string_prefix_size_(DEFAULT_STRING_PREFIX_SIZE)
- {
+ : TVirtualProtocol<TDebugProtocol>(trans),
+ trans_(trans.get()),
+ string_limit_(DEFAULT_STRING_LIMIT),
+ string_prefix_size_(DEFAULT_STRING_PREFIX_SIZE) {
write_state_.push_back(UNINIT);
}
static const int32_t DEFAULT_STRING_LIMIT = 256;
static const int32_t DEFAULT_STRING_PREFIX_SIZE = 16;
- void setStringSizeLimit(int32_t string_limit) {
- string_limit_ = string_limit;
- }
-
- void setStringPrefixSize(int32_t string_prefix_size) {
- string_prefix_size_ = string_prefix_size;
- }
+ void setStringSizeLimit(int32_t string_limit) { string_limit_ = string_limit; }
+ void setStringPrefixSize(int32_t string_prefix_size) { string_prefix_size_ = string_prefix_size; }
uint32_t writeMessageBegin(const std::string& name,
const TMessageType messageType,
@@ -84,32 +72,25 @@ class TDebugProtocol : public TVirtualProtocol<TDebugProtocol> {
uint32_t writeMessageEnd();
-
uint32_t writeStructBegin(const char* name);
uint32_t writeStructEnd();
- uint32_t writeFieldBegin(const char* name,
- const TType fieldType,
- const int16_t fieldId);
+ uint32_t writeFieldBegin(const char* 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 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 writeListBegin(const TType elemType, const uint32_t size);
uint32_t writeListEnd();
- uint32_t writeSetBegin(const TType elemType,
- const uint32_t size);
+ uint32_t writeSetBegin(const TType elemType, const uint32_t size);
uint32_t writeSetEnd();
@@ -129,8 +110,7 @@ class TDebugProtocol : public TVirtualProtocol<TDebugProtocol> {
uint32_t writeBinary(const std::string& str);
-
- private:
+private:
void indentUp();
void indentDown();
uint32_t writePlain(const std::string& str);
@@ -157,25 +137,25 @@ class TDebugProtocol : public TVirtualProtocol<TDebugProtocol> {
* Constructs debug protocol handlers
*/
class TDebugProtocolFactory : public TProtocolFactory {
- public:
+public:
TDebugProtocolFactory() {}
virtual ~TDebugProtocolFactory() {}
boost::shared_ptr<TProtocol> getProtocol(boost::shared_ptr<TTransport> trans) {
return boost::shared_ptr<TProtocol>(new TDebugProtocol(trans));
}
-
};
-
-}}} // apache::thrift::protocol
-
+}
+}
+} // apache::thrift::protocol
// TODO(dreiss): Move (part of) ThriftDebugString into a .cpp file and remove this.
#include <thrift/transport/TBufferTransports.h>
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
-template<typename ThriftStruct>
+template <typename ThriftStruct>
std::string ThriftDebugString(const ThriftStruct& ts) {
using namespace apache::thrift::transport;
using namespace apache::thrift::protocol;
@@ -218,10 +198,7 @@ std::string DebugString(const std::vector<Object>& vec) {
return std::string((char*)buf, (unsigned int)size);
}
#endif // 0
-
-}} // apache::thrift
-
+}
+} // apache::thrift
#endif // #ifndef _THRIFT_PROTOCOL_TDEBUGPROTOCOL_H_
-
-
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/protocol/TDenseProtocol.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/protocol/TDenseProtocol.cpp b/lib/cpp/src/thrift/protocol/TDenseProtocol.cpp
index 4fbfc13..d6644b7 100644
--- a/lib/cpp/src/thrift/protocol/TDenseProtocol.cpp
+++ b/lib/cpp/src/thrift/protocol/TDenseProtocol.cpp
@@ -117,24 +117,24 @@ using std::string;
#define UNLIKELY(val) (val)
#endif
-namespace apache { namespace thrift { namespace protocol {
+namespace apache {
+namespace thrift {
+namespace protocol {
-const int TDenseProtocol::FP_PREFIX_LEN =
- apache::thrift::reflection::local::FP_PREFIX_LEN;
+const int TDenseProtocol::FP_PREFIX_LEN = apache::thrift::reflection::local::FP_PREFIX_LEN;
// Top TypeSpec. TypeSpec of the structure being encoded.
-#define TTS (ts_stack_.back()) // type = TypeSpec*
+#define TTS (ts_stack_.back()) // type = TypeSpec*
// InDeX. Index into TTS of the current/next field to encode.
-#define IDX (idx_stack_.back()) // type = int
+#define IDX (idx_stack_.back()) // type = int
// Field TypeSpec. TypeSpec of the current/next field to encode.
-#define FTS (TTS->tstruct.specs[IDX]) // type = TypeSpec*
+#define FTS (TTS->tstruct.specs[IDX]) // type = TypeSpec*
// Field MeTa. Metadata of the current/next field to encode.
-#define FMT (TTS->tstruct.metas[IDX]) // type = FieldMeta
+#define FMT (TTS->tstruct.metas[IDX]) // type = FieldMeta
// SubType 1/2. TypeSpec of the first/second subtype of this container.
#define ST1 (TTS->tcontainer.subtype1)
#define ST2 (TTS->tcontainer.subtype2)
-
/**
* Checks that @c ttype is indeed the ttype that we should be writing,
* according to our typespec. Aborts if the test fails and debugging in on.
@@ -161,30 +161,28 @@ inline void TDenseProtocol::stateTransition() {
switch (TTS->ttype) {
- case T_STRUCT:
- assert(old_tts == FTS);
- break;
-
- case T_LIST:
- case T_SET:
- assert(old_tts == ST1);
- ts_stack_.push_back(old_tts);
- break;
-
- case T_MAP:
- assert(old_tts == (mkv_stack_.back() ? ST1 : ST2));
- mkv_stack_.back() = !mkv_stack_.back();
- ts_stack_.push_back(mkv_stack_.back() ? ST1 : ST2);
- break;
-
- default:
- assert(!"Invalid TType in stateTransition.");
- break;
-
+ case T_STRUCT:
+ assert(old_tts == FTS);
+ break;
+
+ case T_LIST:
+ case T_SET:
+ assert(old_tts == ST1);
+ ts_stack_.push_back(old_tts);
+ break;
+
+ case T_MAP:
+ assert(old_tts == (mkv_stack_.back() ? ST1 : ST2));
+ mkv_stack_.back() = !mkv_stack_.back();
+ ts_stack_.push_back(mkv_stack_.back() ? ST1 : ST2);
+ break;
+
+ default:
+ assert(!"Invalid TType in stateTransition.");
+ break;
}
}
-
/*
* Variable-length quantity functions.
*/
@@ -192,7 +190,7 @@ inline void TDenseProtocol::stateTransition() {
inline uint32_t TDenseProtocol::vlqRead(uint64_t& vlq) {
uint32_t used = 0;
uint64_t val = 0;
- uint8_t buf[10]; // 64 bits / (7 bits/byte) = 10 bytes.
+ uint8_t buf[10]; // 64 bits / (7 bits/byte) = 10 bytes.
uint32_t buf_size = sizeof(buf);
const uint8_t* borrowed = trans_->borrow(buf, &buf_size);
@@ -210,7 +208,8 @@ inline uint32_t TDenseProtocol::vlqRead(uint64_t& vlq) {
// Have to check for invalid data so we don't crash.
if (UNLIKELY(used == sizeof(buf))) {
resetState();
- throw TProtocolException(TProtocolException::INVALID_DATA, "Variable-length int over 10 bytes.");
+ throw TProtocolException(TProtocolException::INVALID_DATA,
+ "Variable-length int over 10 bytes.");
}
}
}
@@ -228,14 +227,15 @@ inline uint32_t TDenseProtocol::vlqRead(uint64_t& vlq) {
// Might as well check for invalid data on the slow path too.
if (UNLIKELY(used >= sizeof(buf))) {
resetState();
- throw TProtocolException(TProtocolException::INVALID_DATA, "Variable-length int over 10 bytes.");
+ throw TProtocolException(TProtocolException::INVALID_DATA,
+ "Variable-length int over 10 bytes.");
}
}
}
}
inline uint32_t TDenseProtocol::vlqWrite(uint64_t vlq) {
- uint8_t buf[10]; // 64 bits / (7 bits/byte) = 10 bytes.
+ uint8_t buf[10]; // 64 bits / (7 bits/byte) = 10 bytes.
int32_t pos = sizeof(buf) - 1;
// Write the thing from back to front.
@@ -253,12 +253,10 @@ inline uint32_t TDenseProtocol::vlqWrite(uint64_t vlq) {
// Back up one step before writing.
pos++;
- trans_->write(buf+pos, static_cast<uint32_t>(sizeof(buf) - pos));
+ trans_->write(buf + pos, static_cast<uint32_t>(sizeof(buf) - pos));
return static_cast<uint32_t>(sizeof(buf) - pos);
}
-
-
/*
* Writing functions.
*/
@@ -281,7 +279,7 @@ uint32_t TDenseProtocol::writeMessageEnd() {
}
uint32_t TDenseProtocol::writeStructBegin(const char* name) {
- (void) name;
+ (void)name;
uint32_t xfer = 0;
// The TypeSpec stack should be empty if this is the top-level read/write.
@@ -315,7 +313,7 @@ uint32_t TDenseProtocol::writeStructEnd() {
uint32_t TDenseProtocol::writeFieldBegin(const char* name,
const TType fieldType,
const int16_t fieldId) {
- (void) name;
+ (void)name;
uint32_t xfer = 0;
// Skip over optional fields.
@@ -380,8 +378,7 @@ uint32_t TDenseProtocol::writeMapEnd() {
return 0;
}
-uint32_t TDenseProtocol::writeListBegin(const TType elemType,
- const uint32_t size) {
+uint32_t TDenseProtocol::writeListBegin(const TType elemType, const uint32_t size) {
checkTType(T_LIST);
assert(elemType == ST1->ttype);
@@ -396,8 +393,7 @@ uint32_t TDenseProtocol::writeListEnd() {
return 0;
}
-uint32_t TDenseProtocol::writeSetBegin(const TType elemType,
- const uint32_t size) {
+uint32_t TDenseProtocol::writeSetBegin(const TType elemType, const uint32_t size) {
checkTType(T_SET);
assert(elemType == ST1->ttype);
@@ -463,7 +459,7 @@ inline uint32_t TDenseProtocol::subWriteI32(const int32_t i32) {
}
uint32_t TDenseProtocol::subWriteString(const std::string& str) {
- if(str.size() > static_cast<size_t>((std::numeric_limits<int32_t>::max)()))
+ if (str.size() > static_cast<size_t>((std::numeric_limits<int32_t>::max)()))
throw TProtocolException(TProtocolException::SIZE_LIMIT);
uint32_t size = static_cast<uint32_t>(str.size());
uint32_t xfer = subWriteI32((int32_t)size);
@@ -473,8 +469,6 @@ uint32_t TDenseProtocol::subWriteString(const std::string& str) {
return xfer + size;
}
-
-
/*
* Reading functions
*
@@ -501,7 +495,8 @@ uint32_t TDenseProtocol::readMessageBegin(std::string& name,
xfer += subReadString(name);
xfer += subReadI32(seqid);
} else {
- throw TProtocolException(TProtocolException::BAD_VERSION, "No version identifier... old protocol client in strict mode?");
+ throw TProtocolException(TProtocolException::BAD_VERSION,
+ "No version identifier... old protocol client in strict mode?");
}
return xfer;
}
@@ -511,7 +506,7 @@ uint32_t TDenseProtocol::readMessageEnd() {
}
uint32_t TDenseProtocol::readStructBegin(string& name) {
- (void) name;
+ (void)name;
uint32_t xfer = 0;
if (ts_stack_.empty()) {
@@ -530,7 +525,7 @@ uint32_t TDenseProtocol::readStructBegin(string& name) {
if (std::memcmp(buf, type_spec_->fp_prefix, FP_PREFIX_LEN) != 0) {
resetState();
throw TProtocolException(TProtocolException::INVALID_DATA,
- "Fingerprint in data does not match type_spec.");
+ "Fingerprint in data does not match type_spec.");
}
}
}
@@ -546,10 +541,8 @@ uint32_t TDenseProtocol::readStructEnd() {
return 0;
}
-uint32_t TDenseProtocol::readFieldBegin(string& name,
- TType& fieldType,
- int16_t& fieldId) {
- (void) name;
+uint32_t TDenseProtocol::readFieldBegin(string& name, TType& fieldType, int16_t& fieldId) {
+ (void)name;
uint32_t xfer = 0;
// For optional fields, check to see if they are there.
@@ -565,7 +558,7 @@ uint32_t TDenseProtocol::readFieldBegin(string& name,
// Once we hit a mandatory field, or an optional field that is present,
// we know that FMT and FTS point to the appropriate field.
- fieldId = FMT.tag;
+ fieldId = FMT.tag;
fieldType = FTS->ttype;
// Normally, we push the TypeSpec that we are about to read,
@@ -581,9 +574,7 @@ uint32_t TDenseProtocol::readFieldEnd() {
return 0;
}
-uint32_t TDenseProtocol::readMapBegin(TType& keyType,
- TType& valType,
- uint32_t& size) {
+uint32_t TDenseProtocol::readMapBegin(TType& keyType, TType& valType, uint32_t& size) {
checkTType(T_MAP);
uint32_t xfer = 0;
@@ -614,8 +605,7 @@ uint32_t TDenseProtocol::readMapEnd() {
return 0;
}
-uint32_t TDenseProtocol::readListBegin(TType& elemType,
- uint32_t& size) {
+uint32_t TDenseProtocol::readListBegin(TType& elemType, uint32_t& size) {
checkTType(T_LIST);
uint32_t xfer = 0;
@@ -643,8 +633,7 @@ uint32_t TDenseProtocol::readListEnd() {
return 0;
}
-uint32_t TDenseProtocol::readSetBegin(TType& elemType,
- uint32_t& size) {
+uint32_t TDenseProtocol::readSetBegin(TType& elemType, uint32_t& size) {
checkTType(T_SET);
uint32_t xfer = 0;
@@ -692,8 +681,7 @@ uint32_t TDenseProtocol::readI16(int16_t& i16) {
int64_t val = (int64_t)u64;
if (UNLIKELY(val > INT16_MAX || val < INT16_MIN)) {
resetState();
- throw TProtocolException(TProtocolException::INVALID_DATA,
- "i16 out of range.");
+ throw TProtocolException(TProtocolException::INVALID_DATA, "i16 out of range.");
}
i16 = (int16_t)val;
return rv;
@@ -707,8 +695,7 @@ uint32_t TDenseProtocol::readI32(int32_t& i32) {
int64_t val = (int64_t)u64;
if (UNLIKELY(val > INT32_MAX || val < INT32_MIN)) {
resetState();
- throw TProtocolException(TProtocolException::INVALID_DATA,
- "i32 out of range.");
+ throw TProtocolException(TProtocolException::INVALID_DATA, "i32 out of range.");
}
i32 = (int32_t)val;
return rv;
@@ -722,8 +709,7 @@ uint32_t TDenseProtocol::readI64(int64_t& i64) {
int64_t val = (int64_t)u64;
if (UNLIKELY(val > INT64_MAX || val < INT64_MIN)) {
resetState();
- throw TProtocolException(TProtocolException::INVALID_DATA,
- "i64 out of range.");
+ throw TProtocolException(TProtocolException::INVALID_DATA, "i64 out of range.");
}
i64 = (int64_t)val;
return rv;
@@ -751,8 +737,7 @@ uint32_t TDenseProtocol::subReadI32(int32_t& i32) {
int64_t val = (int64_t)u64;
if (UNLIKELY(val > INT32_MAX || val < INT32_MIN)) {
resetState();
- throw TProtocolException(TProtocolException::INVALID_DATA,
- "i32 out of range.");
+ throw TProtocolException(TProtocolException::INVALID_DATA, "i32 out of range.");
}
i32 = (int32_t)val;
return rv;
@@ -764,5 +749,6 @@ uint32_t TDenseProtocol::subReadString(std::string& str) {
xfer = subReadI32(size);
return xfer + readStringBody(str, size);
}
-
-}}} // apache::thrift::protocol
+}
+}
+} // apache::thrift::protocol