impl/serialize.hpp

100.0% Lines (8/8) 100.0% Functions (11/11) 100.0% Branches (1/1)
impl/serialize.hpp
Line Branch Hits Source Code
1 //
2 // Copyright (c) 2023 Dmitry Arkhipov (grisumbras@yandex.ru)
3 //
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)
6 //
7 // Official repository: https://github.com/boostorg/json
8 //
9
10 #ifndef BOOST_JSON_IMPL_SERIALIZE_HPP
11 #define BOOST_JSON_IMPL_SERIALIZE_HPP
12
13 #include <boost/json/serializer.hpp>
14
15 namespace boost {
16 namespace json {
17 namespace detail {
18
19 BOOST_JSON_DECL
20 void
21 serialize_impl(std::string& s, serializer& sr);
22
23 } // namespace detail
24
25 template<class T>
26 std::string
27 40 serialize(T const& t, serialize_options const& opts)
28 {
29 unsigned char buf[256];
30 40 serializer sr(
31 80 storage_ptr(),
32 buf,
33 sizeof(buf),
34 opts);
35 40 std::string s;
36 40 sr.reset(&t);
37
1/1
✓ Branch 1 taken 40 times.
40 detail::serialize_impl(s, sr);
38 80 return s;
39 40 }
40
41 } // namespace json
42 } // namespace boost
43
44 #endif // BOOST_JSON_IMPL_SERIALIZE_HPP
45