Skip to content

Commit

Permalink
noop: move map entry parsing into a new function
Browse files Browse the repository at this point in the history
  • Loading branch information
antongrbin committed Jul 29, 2024
1 parent c995ff6 commit 4d16d95
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/google/protobuf/json/internal/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,21 @@ absl::Status ParseMapKey(const Desc<Traits>& type, Msg<Traits>& entry,
return absl::OkStatus();
}

// Parses one map entry for 'map_field' in 'parent_msg' with already consumed
// 'key'.
template <typename Traits>
absl::Status ParseMapEntry(JsonLexer& lex, Field<Traits> map_field,
Msg<Traits>& parent_msg,
LocationWith<MaybeOwnedString>& key) {
return Traits::NewMsg(
map_field, parent_msg,
[&](const Desc<Traits>& type, Msg<Traits>& entry) -> absl::Status {
RETURN_IF_ERROR(ParseMapKey<Traits>(type, entry, key));

return ParseSingular<Traits>(lex, Traits::ValueField(type), entry);
});
}

template <typename Traits>
absl::Status ParseMap(JsonLexer& lex, Field<Traits> field, Msg<Traits>& msg) {
if (lex.Peek(JsonLexer::kNull)) {
Expand All @@ -707,13 +722,7 @@ absl::Status ParseMap(JsonLexer& lex, Field<Traits> field, Msg<Traits>& msg) {
"got unexpectedly-repeated repeated map key: '%s'",
key.value.AsView()));
}
return Traits::NewMsg(
field, msg,
[&](const Desc<Traits>& type, Msg<Traits>& entry) -> absl::Status {
RETURN_IF_ERROR(ParseMapKey<Traits>(type, entry, key));
return ParseSingular<Traits>(lex, Traits::ValueField(type),
entry);
});
return ParseMapEntry<Traits>(lex, field, msg, key);
});
}

Expand Down

0 comments on commit 4d16d95

Please sign in to comment.