Mark Slee | 9f0c651 | 2007-02-28 23:58:26 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 7 | #include <Thrift.h> |
| 8 | #include <protocol/TProtocol.h> |
| 9 | |
| 10 | namespace facebook { namespace thrift { |
| 11 | |
boz | 6ded775 | 2007-06-05 22:41:18 +0000 | [diff] [blame] | 12 | TOutput GlobalOutput; |
| 13 | |
David Reiss | 9b20955 | 2008-04-08 06:26:05 +0000 | [diff] [blame^] | 14 | std::string TOutput::strerror_s(int errno_copy) { |
| 15 | #ifndef HAVE_STRERROR_R |
| 16 | return "errno = " + lexical_cast<string>(errno_copy); |
| 17 | #else // HAVE_STRERROR_R |
| 18 | |
| 19 | char b_errbuf[1024] = { '\0' }; |
| 20 | #ifdef STRERROR_R_CHAR_P |
| 21 | char *b_error = strerror_r(errno_copy, b_errbuf, sizeof(b_errbuf)); |
| 22 | #else |
| 23 | char *b_error = b_errbuf; |
| 24 | int rv = strerror_r(errno_copy, b_errbuf, sizeof(b_errbuf)); |
| 25 | if (rv == -1) { |
| 26 | // strerror_r failed. omgwtfbbq. |
| 27 | return "XSI-compliant strerror_r() failed with errno = " + |
| 28 | lexical_cast<string>(errno_copy); |
| 29 | } |
| 30 | #endif |
| 31 | // Can anyone prove that explicit cast is probably not necessary |
| 32 | // to ensure that the string object is constructed before |
| 33 | // b_error becomes invalid? |
| 34 | return std::string(b_error); |
| 35 | |
| 36 | #endif // HAVE_STRERROR_R |
| 37 | } |
| 38 | |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 39 | uint32_t TApplicationException::read(facebook::thrift::protocol::TProtocol* iprot) { |
| 40 | uint32_t xfer = 0; |
| 41 | std::string fname; |
| 42 | facebook::thrift::protocol::TType ftype; |
| 43 | int16_t fid; |
| 44 | |
| 45 | xfer += iprot->readStructBegin(fname); |
| 46 | |
| 47 | while (true) { |
| 48 | xfer += iprot->readFieldBegin(fname, ftype, fid); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 49 | if (ftype == facebook::thrift::protocol::T_STOP) { |
Mark Slee | f983108 | 2007-02-20 20:59:21 +0000 | [diff] [blame] | 50 | break; |
| 51 | } |
| 52 | switch (fid) { |
| 53 | case 1: |
| 54 | if (ftype == facebook::thrift::protocol::T_STRING) { |
| 55 | xfer += iprot->readString(message_); |
| 56 | } else { |
| 57 | xfer += iprot->skip(ftype); |
| 58 | } |
| 59 | break; |
| 60 | case 2: |
| 61 | if (ftype == facebook::thrift::protocol::T_I32) { |
| 62 | int32_t type; |
| 63 | xfer += iprot->readI32(type); |
| 64 | type_ = (TApplicationExceptionType)type; |
| 65 | } else { |
| 66 | xfer += iprot->skip(ftype); |
| 67 | } |
| 68 | break; |
| 69 | default: |
| 70 | xfer += iprot->skip(ftype); |
| 71 | break; |
| 72 | } |
| 73 | xfer += iprot->readFieldEnd(); |
| 74 | } |
| 75 | |
| 76 | xfer += iprot->readStructEnd(); |
| 77 | return xfer; |
| 78 | } |
| 79 | |
| 80 | uint32_t TApplicationException::write(facebook::thrift::protocol::TProtocol* oprot) const { |
| 81 | uint32_t xfer = 0; |
| 82 | xfer += oprot->writeStructBegin("TApplicationException"); |
| 83 | xfer += oprot->writeFieldBegin("message", facebook::thrift::protocol::T_STRING, 1); |
| 84 | xfer += oprot->writeString(message_); |
| 85 | xfer += oprot->writeFieldEnd(); |
| 86 | xfer += oprot->writeFieldBegin("type", facebook::thrift::protocol::T_I32, 2); |
| 87 | xfer += oprot->writeI32(type_); |
| 88 | xfer += oprot->writeFieldEnd(); |
| 89 | xfer += oprot->writeFieldStop(); |
| 90 | xfer += oprot->writeStructEnd(); |
| 91 | return xfer; |
| 92 | } |
| 93 | |
| 94 | }} // facebook::thrift |