Internal Change

PiperOrigin-RevId: 553652444
This commit is contained in:
MediaPipe Team 2023-08-03 18:47:36 -07:00 committed by Copybara-Service
parent 360959e325
commit 11508f2291
3 changed files with 21 additions and 12 deletions

View File

@ -501,7 +501,6 @@ cc_library(
":calculator_graph_template_cc_proto", ":calculator_graph_template_cc_proto",
":proto_util_lite", ":proto_util_lite",
"//mediapipe/framework:calculator_cc_proto", "//mediapipe/framework:calculator_cc_proto",
"//mediapipe/framework/port:logging",
"//mediapipe/framework/port:numbers", "//mediapipe/framework/port:numbers",
"//mediapipe/framework/port:ret_check", "//mediapipe/framework/port:ret_check",
"//mediapipe/framework/port:status", "//mediapipe/framework/port:status",

View File

@ -15,20 +15,14 @@
#include "mediapipe/framework/tool/template_expander.h" #include "mediapipe/framework/tool/template_expander.h"
#include <algorithm> #include <algorithm>
#include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "absl/strings/ascii.h" #include "absl/strings/ascii.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "absl/strings/numbers.h" #include "absl/strings/numbers.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "mediapipe/framework/calculator.pb.h" #include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/numbers.h" #include "mediapipe/framework/port/numbers.h"
#include "mediapipe/framework/port/ret_check.h" #include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/port/status.h" #include "mediapipe/framework/port/status.h"
@ -183,8 +177,7 @@ FieldType GetFieldType(const TemplateExpression& rule) {
int FieldCount(const FieldValue& base, ProtoPath field_path, int FieldCount(const FieldValue& base, ProtoPath field_path,
FieldType field_type) { FieldType field_type) {
int result = 0; int result = 0;
CHECK( CHECK_OK(ProtoUtilLite::GetFieldCount(base, field_path, field_type, &result));
ProtoUtilLite::GetFieldCount(base, field_path, field_type, &result).ok());
return result; return result;
} }

View File

@ -471,7 +471,7 @@ class TemplateParser::Parser::ParserImpl {
"\" stored in google.protobuf.Any."); "\" stored in google.protobuf.Any.");
return false; return false;
} }
DO(ConsumeAnyValue(value_descriptor, &serialized_value)); DO(ConsumeAnyValue(any_value_field, value_descriptor, &serialized_value));
if (singular_overwrite_policy_ == FORBID_SINGULAR_OVERWRITES) { if (singular_overwrite_policy_ == FORBID_SINGULAR_OVERWRITES) {
// Fail if any_type_url_field has already been specified. // Fail if any_type_url_field has already been specified.
if ((!any_type_url_field->is_repeated() && if ((!any_type_url_field->is_repeated() &&
@ -709,7 +709,7 @@ class TemplateParser::Parser::ParserImpl {
// If the parse information tree is not NULL, create a nested one // If the parse information tree is not NULL, create a nested one
// for the nested message. // for the nested message.
ParseInfoTree* parent = parse_info_tree_; ParseInfoTree* parent = parse_info_tree_;
if (parent != NULL) { if (parent) {
parse_info_tree_ = parent->CreateNested(field); parse_info_tree_ = parent->CreateNested(field);
} }
@ -1191,8 +1191,20 @@ class TemplateParser::Parser::ParserImpl {
// A helper function for reconstructing Any::value. Consumes a text of // A helper function for reconstructing Any::value. Consumes a text of
// full_type_name, then serializes it into serialized_value. // full_type_name, then serializes it into serialized_value.
bool ConsumeAnyValue(const Descriptor* value_descriptor, bool ConsumeAnyValue(const FieldDescriptor* field,
const Descriptor* value_descriptor,
std::string* serialized_value) { std::string* serialized_value) {
if (--recursion_limit_ < 0) {
ReportError("Message is too deep");
return false;
}
// If the parse information tree is not NULL, create a nested one
// for the nested message.
ParseInfoTree* parent = parse_info_tree_;
if (parent) {
parse_info_tree_ = parent->CreateNested(field);
}
DynamicMessageFactory factory; DynamicMessageFactory factory;
const Message* value_prototype = factory.GetPrototype(value_descriptor); const Message* value_prototype = factory.GetPrototype(value_descriptor);
if (value_prototype == NULL) { if (value_prototype == NULL) {
@ -1214,6 +1226,11 @@ class TemplateParser::Parser::ParserImpl {
} }
value->AppendToString(serialized_value); value->AppendToString(serialized_value);
} }
++recursion_limit_;
// Reset the parse information tree.
parse_info_tree_ = parent;
return true; return true;
} }