Skip to content

Commit 5ede551

Browse files
iahsfacebook-github-bot
authored andcommitted
Add binary protocol support to thrift2ast
Summary: This is a better choice when the output will be compressed or size does not matter. Reviewed By: thedavekwon Differential Revision: D59119356 fbshipit-source-id: 6afb0c657abe66307e22021eec8d82515a729789
1 parent 855fffc commit 5ede551

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

third-party/thrift/src/thrift/compiler/generate/t_ast_generator.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <folly/compression/Compression.h>
3333
#include <thrift/lib/cpp2/op/Sha256Hasher.h>
34+
#include <thrift/lib/cpp2/protocol/BinaryProtocol.h>
3435
#include <thrift/lib/cpp2/protocol/CompactProtocol.h>
3536
#include <thrift/lib/cpp2/protocol/DebugProtocol.h>
3637
#include <thrift/lib/cpp2/protocol/Serializer.h>
@@ -46,6 +47,7 @@ enum class ast_protocol {
4647
json,
4748
debug,
4849
compact,
50+
binary,
4951
};
5052

5153
template <typename Writer, typename T>
@@ -85,6 +87,8 @@ class t_ast_generator : public t_generator {
8587
protocol_ = ast_protocol::debug;
8688
} else if (pair.second == "compact") {
8789
protocol_ = ast_protocol::compact;
90+
} else if (pair.second == "binary") {
91+
protocol_ = ast_protocol::binary;
8892
} else {
8993
throw std::runtime_error(
9094
fmt::format("Unknown protocol `{}`", pair.second));
@@ -512,6 +516,9 @@ void t_ast_generator::generate_program() {
512516
case ast_protocol::compact:
513517
f_out_ << serialize<CompactProtocolWriter>(ast);
514518
break;
519+
case ast_protocol::binary:
520+
f_out_ << serialize<BinaryProtocolWriter>(ast);
521+
break;
515522
}
516523
f_out_.close();
517524
}

0 commit comments

Comments
 (0)