THRIFT-4989: Fix run time exception when using Swift TCompactProtocol
Client: Swift
Patch: David Furey
This closes #1908
Sort TStruct members by key before generating class properties so that Swift Thrift lib can use delta encoding for CompactProtocol.
diff --git a/compiler/cpp/src/thrift/generate/t_swift_generator.cc b/compiler/cpp/src/thrift/generate/t_swift_generator.cc
index eb746c1..4a2f87d 100644
--- a/compiler/cpp/src/thrift/generate/t_swift_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_swift_generator.cc
@@ -697,7 +697,9 @@
}
block_open(out);
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+ vector<t_field*> sorted = members;
+ sort(sorted.begin(), sorted.end(), [](t_field *a, t_field *b) { return (a->get_key() < b->get_key()); } );
+ for (m_iter = sorted.begin(); m_iter != sorted.end(); ++m_iter) {
out << endl;
// TODO: Defaults