THRIFT-4023 Skip unexpected field types on read/write
Client: Go
Patch: Chen Zhiming <chenzhiming@domob.cn>
This closes #1154
diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc
index 9919cb1..defc682 100644
--- a/compiler/cpp/src/thrift/generate/t_go_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc
@@ -1527,9 +1527,15 @@
thriftFieldTypeId = "thrift.STRING";
}
- out << indent() << "if err := p." << field_method_prefix << field_method_suffix << "(iprot); err != nil {"
+ out << indent() << "if fieldTypeId == " << thriftFieldTypeId << " {" << endl;
+ out << indent() << " if err := p." << field_method_prefix << field_method_suffix << "(iprot); err != nil {"
<< endl;
- out << indent() << " return err" << endl;
+ out << indent() << " return err" << endl;
+ out << indent() << " }" << endl;
+ out << indent() << "} else {" << endl;
+ out << indent() << " if err := iprot.Skip(fieldTypeId); err != nil {" << endl;
+ out << indent() << " return err" << endl;
+ out << indent() << " }" << endl;
out << indent() << "}" << endl;
// Mark required field as read