scylladb / seastar

High performance server-side application framework
http://seastar.io
Apache License 2.0
8.38k stars 1.55k forks source link

json_formatter: Make formatter::write work for std::pair #2440

Closed StephanDollberg closed 1 month ago

StephanDollberg commented 2 months ago

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 recursively 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.

Adds some tests as well.

avikivity commented 2 months ago

Does the test fail before the patch? If so please reorder them.

StephanDollberg commented 2 months ago

Does the test fail before the patch? If so please reorder them.

Yep, it doesn't compile. Done.