| 328 | |
| 329 | template <typename ThriftStruct> |
| 330 | std::string ThriftJSONString(const ThriftStruct& ts) { |
| 331 | using namespace apache::thrift::transport; |
| 332 | using namespace apache::thrift::protocol; |
| 333 | auto* buffer = new TMemoryBuffer; |
| 334 | std::shared_ptr<TTransport> trans(buffer); |
| 335 | TJSONProtocol protocol(trans); |
| 336 | |
| 337 | ts.write(&protocol); |
| 338 | |
| 339 | uint8_t* buf; |
| 340 | uint32_t size; |
| 341 | buffer->getBuffer(&buf, &size); |
| 342 | return std::string((char*)buf, (unsigned int)size); |
| 343 | } |
| 344 | } |
| 345 | } // apache::thrift |
| 346 |