1  
//
1  
//
2  
// Copyright (c) 2023 Dmitry Arkhipov (grisumbras@yandex.ru)
2  
// Copyright (c) 2023 Dmitry Arkhipov (grisumbras@yandex.ru)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/boostorg/json
7  
// Official repository: https://github.com/boostorg/json
8  
//
8  
//
9  

9  

10  
#ifndef BOOST_JSON_IMPL_SERIALIZE_HPP
10  
#ifndef BOOST_JSON_IMPL_SERIALIZE_HPP
11  
#define BOOST_JSON_IMPL_SERIALIZE_HPP
11  
#define BOOST_JSON_IMPL_SERIALIZE_HPP
12  

12  

13  
#include <boost/json/serializer.hpp>
13  
#include <boost/json/serializer.hpp>
14  

14  

15  
namespace boost {
15  
namespace boost {
16  
namespace json {
16  
namespace json {
17  
namespace detail {
17  
namespace detail {
18  

18  

19  
BOOST_JSON_DECL
19  
BOOST_JSON_DECL
20  
void
20  
void
21  
serialize_impl(std::string& s, serializer& sr);
21  
serialize_impl(std::string& s, serializer& sr);
22  

22  

23  
} // namespace detail
23  
} // namespace detail
24  

24  

25  
template<class T>
25  
template<class T>
26  
std::string
26  
std::string
27  
serialize(T const& t, serialize_options const& opts)
27  
serialize(T const& t, serialize_options const& opts)
28  
{
28  
{
29  
    unsigned char buf[256];
29  
    unsigned char buf[256];
30  
    serializer sr(
30  
    serializer sr(
31  
        storage_ptr(),
31  
        storage_ptr(),
32  
        buf,
32  
        buf,
33  
        sizeof(buf),
33  
        sizeof(buf),
34  
        opts);
34  
        opts);
35  
    std::string s;
35  
    std::string s;
36  
    sr.reset(&t);
36  
    sr.reset(&t);
37  
    detail::serialize_impl(s, sr);
37  
    detail::serialize_impl(s, sr);
38  
    return s;
38  
    return s;
39  
}
39  
}
40  

40  

41  
} // namespace json
41  
} // namespace json
42  
} // namespace boost
42  
} // namespace boost
43  

43  

44  
#endif // BOOST_JSON_IMPL_SERIALIZE_HPP
44  
#endif // BOOST_JSON_IMPL_SERIALIZE_HPP