MCPcopy Create free account
hub / github.com/apache/brpc / ReadThriftStruct

Function ReadThriftStruct

src/brpc/policy/thrift_protocol.cpp:126–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126bool ReadThriftStruct(const butil::IOBuf& body,
127 ThriftMessageBase* raw_msg,
128 int16_t expected_fid) {
129 const size_t body_len = body.size();
130 uint8_t* thrift_buffer = (uint8_t*)malloc(body_len);
131 body.copy_to(thrift_buffer, body_len);
132 auto in_buffer =
133 THRIFT_STDCXX::make_shared<apache::thrift::transport::TMemoryBuffer>(
134 thrift_buffer, body_len,
135 ::apache::thrift::transport::TMemoryBuffer::TAKE_OWNERSHIP);
136 apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TMemoryBuffer> iprot(in_buffer);
137
138 bool success = false;
139 try {
140 // The following code was taken from thrift auto generate code
141 std::string fname;
142
143 uint32_t xfer = 0;
144 ::apache::thrift::protocol::TType ftype;
145 int16_t fid;
146 xfer += iprot.readStructBegin(fname);
147 while (true) {
148 xfer += iprot.readFieldBegin(fname, ftype, fid);
149 if (ftype == ::apache::thrift::protocol::T_STOP) {
150 break;
151 }
152 if (fid == expected_fid) {
153 if (ftype == ::apache::thrift::protocol::T_STRUCT) {
154 xfer += raw_msg->Read(&iprot);
155 success = true;
156 } else {
157 xfer += iprot.skip(ftype);
158 }
159 } else {
160 xfer += iprot.skip(ftype);
161 }
162 xfer += iprot.readFieldEnd();
163 }
164
165 xfer += iprot.readStructEnd();
166 (void)xfer;
167 iprot.getTransport()->readEnd();
168 } catch (std::exception& e) {
169 LOG(WARNING) << "Catched thrift exception: " << e.what();
170 } catch (...) {
171 LOG(WARNING) << "Catched unknown thrift exception";
172 }
173 return success;
174}
175
176void ReadThriftException(const butil::IOBuf& body,
177 ::apache::thrift::TApplicationException* x) {

Callers 2

CastMethod · 0.85
ProcessThriftResponseFunction · 0.85

Calls 4

sizeMethod · 0.45
copy_toMethod · 0.45
ReadMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected