2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
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)
7 // Official repository: https://github.com/boostorg/json
10 #ifndef BOOST_JSON_IMPL_SERIALIZE_IPP
11 #define BOOST_JSON_IMPL_SERIALIZE_IPP
13 #include <boost/json/serialize.hpp>
14 #include <boost/json/serializer.hpp>
25 // serialize to a small buffer to avoid
26 // the first few allocations in std::string
27 char buf[BOOST_JSON_STACK_BUFFER_SIZE];
34 sv.data(), sv.size());
37 std::size_t len = sv.size();
39 s.resize(s.capacity());
43 sv.data(), sv.size());
67 serialize_impl(s, sr);
78 serialize_impl(s, sr);
89 serialize_impl(s, sr);
100 serialize_impl(s, sr);
104 // this is here for key_value_pair::key()
112 serialize_impl(s, sr);
116 //----------------------------------------------------------
118 //[example_operator_lt__lt_
119 // Serialize a value into an output stream
122 operator<<( std::ostream& os, value const& jv )
124 // Create a serializer
127 // Set the serializer up for our value
130 // Loop until all output is produced.
133 // Use a local buffer to avoid allocation.
134 char buf[ BOOST_JSON_STACK_BUFFER_SIZE ];
136 // Fill our buffer with serialized characters and write it to the output stream.
137 os << sr.read( buf );
152 char buf[BOOST_JSON_STACK_BUFFER_SIZE];
153 auto s = sr.read(buf);
154 os.write(s.data(), s.size());