Thrift: Generate structural fingerprints for thrift structs.
Summary:
We are going to write a dense protocol soon that eliminates some metadata.
To prevent version conflicts, we want each structure to have a
structural fingerprint that will change whenever the struct changes
in a way that will affect the dense protocol.
This change computes those fingerprints and puts them in
the generated C++ code.
Reviewed By: aditya, mcslee
Test Plan:
Recompiled thrift.
Thrifted DebugProtoTest with old and new compilers.
Compared output.
Also ran thrift with those "cout"s uncommented,
examined the fingerprint material,
and verified the hashes.
Revert Plan: ok
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665227 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index ba88ae3..7e561e1 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -514,6 +514,27 @@
}
/**
+ * Call generate_fingerprint for every structure.
+ */
+void generate_all_fingerprints(t_program* program) {
+ const vector<t_struct*>& structs = program->get_structs();
+ vector<t_struct*>::const_iterator s_iter;
+ for (s_iter = structs.begin(); s_iter != structs.end(); ++s_iter) {
+ t_struct* st = *s_iter;
+ st->generate_fingerprint();
+ }
+
+ // If you want to generate fingerprints for implicit structures, start here.
+ /*
+ const vector<t_service*>& services = program->get_services();
+ vector<t_service*>::const_iterator v_iter;
+ for (v_iter = services.begin(); v_iter != services.end(); ++v_iter) {
+ t_service* sv = *v_iter;
+ }
+ */
+}
+
+/**
* Diplays the usage message and then exits with an error code.
*/
void usage() {
@@ -740,6 +761,9 @@
try {
pverbose("Program: %s\n", program->get_path().c_str());
+ // Compute fingerprints.
+ generate_all_fingerprints(program);
+
if (gen_cpp) {
pverbose("Generating C++\n");
t_cpp_generator* cpp = new t_cpp_generator(program);