-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json_formatter: Make formatter::write work for std::pair #2440
json_formatter: Make formatter::write work for std::pair #2440
Conversation
Does the test fail before the patch? If so please reorder them. |
Previously the un/associative container overloads for `formatter::write` were broken because it failed to find an overload for `write(output_stream, pair)`. To fix this we make the `write(output_stream<char>&, state, Iter, Iter)` overload actually `write(output_stream, state, pair)` so that the existing overload that handles `pair` can be found. Further we fix the fallback `write(output_stream, state, T)` overload to call `formatter::write` recurisvely with the state stripped instead of calling `to_json`. This keeps the recursive zero-copy nature of `formatter::write` intact. All of the above mirrors how the existing overloads for `to_json` already work.
db31414
to
d7d3388
Compare
Yep, it doesn't compile. Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm modulo some nits.
tests/unit/json_formatter_test.cc
Outdated
|
||
SEASTAR_THREAD_TEST_CASE(formatter_write) { | ||
|
||
formatter_check_expected("3", [](auto &out) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a space after []
. to be consistent the tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
tests/unit/json_formatter_test.cc
Outdated
f(out); | ||
if (close) { | ||
out.close().get(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could remove ;
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
tests/unit/json_formatter_test.cc
Outdated
|
||
|
||
SEASTAR_THREAD_TEST_CASE(test_stream_range_as_array) { | ||
sstring expected = "[{\"subject\":\"1\",\"values\":[1]}, {\"subject\":\"2\",\"values\":[2]}, {\"subject\":\"3\",\"values\":[3]}]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, could use raw-string literal. like
sstring expected = R"([{"subject":"1","values":[1]},....)";
more readable this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Adds some unit tests for the various `formatter::write` overloads.
d7d3388
to
67fe1a9
Compare
Previously the un/associative container overloads for
formatter::write
were broken because it failed to find an overload for
write(output_stream, pair)
.To fix this we make the
write(output_stream<char>&, state, Iter, Iter)
overload actually
write(output_stream, state, pair)
so that theexisting overload that handles
pair
can be found.Further we fix the fallback
write(output_stream, state, T)
overload tocall
formatter::write
recursively with the state stripped instead ofcalling
to_json
. This keeps the recursive zero-copy nature offormatter::write
intact.All of the above mirrors how the existing overloads for
to_json
already work.
Adds some tests as well.