diff --git a/src/google/protobuf/json/internal/parser.cc b/src/google/protobuf/json/internal/parser.cc index 49c1b97adcc24..4bdc83e49314d 100644 --- a/src/google/protobuf/json/internal/parser.cc +++ b/src/google/protobuf/json/internal/parser.cc @@ -691,6 +691,21 @@ absl::Status ParseMapKey(const Desc& type, Msg& entry, return absl::OkStatus(); } +// Parses one map entry for 'map_field' in 'parent_msg' with already consumed +// 'key'. +template +absl::Status ParseMapEntry(JsonLexer& lex, Field map_field, + Msg& parent_msg, + LocationWith& key) { + return Traits::NewMsg( + map_field, parent_msg, + [&](const Desc& type, Msg& entry) -> absl::Status { + RETURN_IF_ERROR(ParseMapKey(type, entry, key)); + + return ParseSingular(lex, Traits::ValueField(type), entry); + }); +} + template absl::Status ParseMap(JsonLexer& lex, Field field, Msg& msg) { if (lex.Peek(JsonLexer::kNull)) { @@ -707,13 +722,7 @@ absl::Status ParseMap(JsonLexer& lex, Field field, Msg& msg) { "got unexpectedly-repeated repeated map key: '%s'", key.value.AsView())); } - return Traits::NewMsg( - field, msg, - [&](const Desc& type, Msg& entry) -> absl::Status { - RETURN_IF_ERROR(ParseMapKey(type, entry, key)); - return ParseSingular(lex, Traits::ValueField(type), - entry); - }); + return ParseMapEntry(lex, field, msg, key); }); }