From 3c84f08b93ba01171aba5f1dd0ec312e978251d8 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 12 Feb 2024 12:59:21 +0800 Subject: [PATCH] alternator: add formatter for attribute_path_map_node before this change, we rely on the default-generated fmt::formatter created from operator<<, but fmt v10 dropped the default-generated formatter. in this change, we define formatters for `attribute_path_map_node`, and drop its operator<<. Refs #13245 Signed-off-by: Kefu Chai Closes scylladb/scylladb#17270 --- alternator/executor.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/alternator/executor.cc b/alternator/executor.cc index 47a9e53ec5..e2526310a7 100644 --- a/alternator/executor.cc +++ b/alternator/executor.cc @@ -2752,22 +2752,35 @@ static std::optional action_result( }, action._action); } +} + // Print an attribute_path_map_node as the list of paths it contains: -static std::ostream& operator<<(std::ostream& out, const attribute_path_map_node& h) { +template <> struct fmt::formatter> { + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } + // this function recursively call into itself, so we have to forward declare it. + auto format(const alternator::attribute_path_map_node& h, fmt::format_context& ctx) const + -> decltype(ctx.out()); +}; + +auto fmt::formatter>::format(const alternator::attribute_path_map_node& h, fmt::format_context& ctx) const + -> decltype(ctx.out()) { + auto out = ctx.out(); if (h.has_value()) { - out << " " << h.get_value()._path; + out = fmt::format_to(out, " {}", h.get_value()._path); } else if (h.has_members()) { for (auto& member : h.get_members()) { - out << *member.second; + out = fmt::format_to(out, "{}", *member.second); } } else if (h.has_indexes()) { for (auto& index : h.get_indexes()) { - out << *index.second; + out = fmt::format_to(out, "{}", *index.second); } } return out; } +namespace alternator { + // Apply the hierarchy of actions in an attribute_path_map_node to a // JSON object which uses DynamoDB's serialization conventions. The complete, // unmodified, previous_item is also necessary for the right-hand sides of the