16 #ifndef IMPALA_RPC_THRIFT_UTIL_H
17 #define IMPALA_RPC_THRIFT_UTIL_H
19 #include <boost/shared_ptr.hpp>
20 #include <thrift/protocol/TBinaryProtocol.h>
23 #include <thrift/TApplicationException.h>
24 #include <thrift/protocol/TDebugProtocol.h>
25 #include <thrift/transport/TBufferTransports.h>
32 class TNetworkAddress;
50 uint8_t* buffer = NULL;
53 memcpy(&((*result)[0]), buffer, len);
65 }
catch (std::exception& e) {
66 std::stringstream msg;
67 msg <<
"Couldn't serialize thrift object:\n" << e.what();
79 }
catch (std::exception& e) {
80 std::stringstream msg;
81 msg <<
"Couldn't serialize thrift object:\n" << e.what();
89 boost::shared_ptr<apache::thrift::transport::TMemoryBuffer>
mem_buffer_;
90 boost::shared_ptr<apache::thrift::protocol::TProtocol>
protocol_;
98 boost::shared_ptr<apache::thrift::protocol::TProtocolFactory>
factory_;
99 boost::shared_ptr<apache::thrift::protocol::TProtocol>
tproto_;
103 boost::shared_ptr<apache::thrift::protocol::TProtocol>
105 boost::shared_ptr<apache::thrift::transport::TMemoryBuffer> mem,
bool compact);
112 T* deserialized_msg) {
116 boost::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
117 new apache::thrift::transport::TMemoryBuffer(const_cast<uint8_t*>(buf), *len));
118 boost::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
121 deserialized_msg->read(tproto.get());
122 }
catch (std::exception& e) {
123 std::stringstream msg;
124 msg <<
"couldn't deserialize thrift msg:\n" << e.what();
128 return Status(
"Unknown exception");
130 uint32_t bytes_left = tmem_transport->available_read();
131 *len = *len - bytes_left;
141 int retry_interval_ms);
144 Status
WaitForServer(
const std::string& host,
int port,
int num_retries,
145 int retry_interval_ms);
148 std::ostream&
operator<<(std::ostream& out,
const TColumnValue& colval);
void InitThriftLogging()
Redirects all Thrift logging to VLOG(1)
ThriftSerializer(bool compact, int initial_buffer_size=1024)
#define RETURN_IF_ERROR(stmt)
some generally useful macros
Status Serialize(T *obj, std::string *result)
ThriftDeserializer(bool compact)
boost::shared_ptr< apache::thrift::protocol::TProtocol > protocol_
bool TNetworkAddressComparator(const TNetworkAddress &a, const TNetworkAddress &b)
Status Serialize(T *obj, std::vector< uint8_t > *result)
Serializes obj into result. Result will contain a copy of the memory.
bool IsTimeoutTException(const TException &e)
Status Serialize(T *obj, uint32_t *len, uint8_t **buffer)
Status WaitForServer(const string &host, int port, int num_retries, int retry_interval_ms)
Status WaitForLocalServer(const ThriftServer &server, int num_retries, int retry_interval_ms)
boost::shared_ptr< apache::thrift::transport::TMemoryBuffer > mem_buffer_
Status DeserializeThriftMsg(JNIEnv *env, jbyteArray serialized_msg, T *deserialized_msg)
shared_ptr< TProtocol > CreateDeserializeProtocol(shared_ptr< TMemoryBuffer > mem, bool compact)
boost::shared_ptr< apache::thrift::protocol::TProtocolFactory > factory_
ostream & operator<<(ostream &os, const map< TNetworkAddress, llama::TAllocatedResource > &resources)
boost::shared_ptr< apache::thrift::protocol::TProtocol > tproto_