8#include <userver/formats/bson/bson_builder.hpp>
9#include <userver/formats/bson/document.hpp>
10#include <userver/formats/bson/types.hpp>
11#include <userver/formats/bson/value.hpp>
12#include <userver/utils/fast_pimpl.hpp>
14USERVER_NAMESPACE_BEGIN
19template <
typename... Args>
23template <
typename... Args>
28class InlineDocBuilder {
30 using Key = std::string_view;
34 template <
typename FieldValue,
typename... Tail>
35 Document Build(Key key, FieldValue&& value, Tail&&... tail) {
36 builder_.Append(key, std::forward<FieldValue>(value));
37 return Build(std::forward<Tail>(tail)...);
44class InlineArrayBuilder {
47 ~InlineArrayBuilder();
51 template <
typename Element,
typename... Tail>
52 Value Build(Element&& element, Tail&&... tail) {
53 builder_.Append(GetKey(), std::forward<Element>(element));
54 return Build(std::forward<Tail>(tail)...);
58 std::string_view GetKey();
61 static constexpr size_t kSize = 20;
62 static constexpr size_t kAlignment = 4;
63 utils::FastPimpl<Helper, kSize, kAlignment,
true> helper_;
70template <
typename... Args>
72 return impl::InlineDocBuilder().Build(std::forward<Args>(args)...);
75template <
typename... Args>
77 return impl::InlineArrayBuilder().Build(std::forward<Args>(args)...);