-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
36 lines (30 loc) · 1.02 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* ====================================================
# Copyright (C)2018 All rights reserved.
#
# Author : anlongfei
# Email : [email protected]
# File Name : main.cpp
# Last Modified : 2018-11-21 14:20
# Describe :
#
# ====================================================*/
#include <iostream>
#include <protocol/TBinaryProtocol.h>
#include <protocol/TJSONProtocol.h>
#include <transport/TBufferTransports.h>
#include "gen-cpp/student_types.h"
using namespace std;
template <class T>
std::string serializeToJSON(const T& r) {
boost::shared_ptr<apache::thrift::transport::TMemoryBuffer> buffer(new apache::thrift::transport::TMemoryBuffer);
boost::shared_ptr<apache::thrift::protocol::TJSONProtocol> protocol(new apache::thrift::protocol::TJSONProtocol(buffer));
r.write(protocol.get());
return buffer->getBufferAsString();
}
int main() {
SharedStruct stu;
stu.__set_num(123);
stu.__set_name("alf");
std::cout << serializeToJSON(stu) << std::endl;
return 0;
}