#ifndef _LBUG_THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_
#define _LBUG_THRIFT_PROTOCOL_TPROTOCOLEXCEPTION_H_ 1
#include <string>
namespace lbug_apache {
namespace thrift {
namespace protocol {
class TProtocolException : public lbug_apache::thrift::TException {
public:
enum TProtocolExceptionType {
UNKNOWN = 0,
INVALID_DATA = 1,
NEGATIVE_SIZE = 2,
SIZE_LIMIT = 3,
BAD_VERSION = 4,
NOT_IMPLEMENTED = 5,
DEPTH_LIMIT = 6
};
TProtocolException() : lbug_apache::thrift::TException(), type_(UNKNOWN) {}
TProtocolException(TProtocolExceptionType type) : lbug_apache::thrift::TException(), type_(type) {}
TProtocolException(const std::string& message)
: lbug_apache::thrift::TException(message), type_(UNKNOWN) {}
TProtocolException(TProtocolExceptionType type, const std::string& message)
: lbug_apache::thrift::TException(message), type_(type) {}
~TProtocolException() noexcept override = default;
TProtocolExceptionType getType() const { return type_; }
const char* what() const noexcept override {
if (message_.empty()) {
switch (type_) {
case UNKNOWN:
return "TProtocolException: Unknown protocol exception";
case INVALID_DATA:
return "TProtocolException: Invalid data";
case NEGATIVE_SIZE:
return "TProtocolException: Negative size";
case SIZE_LIMIT:
return "TProtocolException: Exceeded size limit";
case BAD_VERSION:
return "TProtocolException: Invalid version";
case NOT_IMPLEMENTED:
return "TProtocolException: Not implemented";
default:
return "TProtocolException: (Invalid exception type)";
}
} else {
return message_.c_str();
}
}
protected:
TProtocolExceptionType type_;
};
}
}
}
#endif