Protobuf: added proper error handling for unknown fields, updated error_codes. Fixed a bug, when errorCode field could be resetted to 0
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
1 - mismatch of expected and actual WireType in parseFieldFrom method
|
||||
2 - read message of size that exceeds expected in parseFromWithSize method
|
||||
3 - read message of size that is not equal to expected. Can occur when deserializing nested message (code generated in C++ method generateSerializationMethods)
|
||||
4 - unsupported feature: unknown field encountered
|
||||
+7
-2
@@ -170,6 +170,7 @@ void ClassGenerator::generateMergeMethods(io::Printer *printer) const {
|
||||
}
|
||||
}
|
||||
|
||||
printer->Print("this.errorCode = other.errorCode\n");
|
||||
printer->Outdent();
|
||||
printer->Print("}\n");
|
||||
|
||||
@@ -246,14 +247,18 @@ void ClassGenerator::generateBuildMethod(io::Printer * printer) const {
|
||||
|
||||
// pass all fields to constructor of enclosing class
|
||||
printer->Print(vars,
|
||||
"return $returnType$(");
|
||||
"val res = $returnType$(");
|
||||
for (int i = 0; i < properties.size(); ++i) {
|
||||
printer->Print(properties[i]->simpleName.c_str());
|
||||
if (i + 1 != properties.size()) {
|
||||
printer->Print(", ");
|
||||
}
|
||||
}
|
||||
|
||||
printer->Print(")\n");
|
||||
printer->Print("res.errorCode = errorCode\n");
|
||||
printer->Print("return res\n");
|
||||
|
||||
printer->Outdent();
|
||||
printer->Print("}\n");
|
||||
}
|
||||
@@ -318,7 +323,7 @@ void ClassGenerator::generateParseMethods(io::Printer *printer) const {
|
||||
printer->Print("}\n");
|
||||
}
|
||||
|
||||
// TODO: add parsing of unknown fields
|
||||
printer->Print(vars, "else -> errorCode = 4\n");
|
||||
|
||||
printer->Outdent();
|
||||
printer->Print("}\n"); // when-clause
|
||||
|
||||
Reference in New Issue
Block a user