serialize.hpp 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #ifndef BOOST_JSON_IMPL_SERIALIZE_HPP
  10. #define BOOST_JSON_IMPL_SERIALIZE_HPP
  11. #include <boost/json/serializer.hpp>
  12. namespace boost {
  13. namespace json {
  14. namespace detail {
  15. BOOST_JSON_DECL
  16. void
  17. serialize_impl(std::string& s, serializer& sr);
  18. } // namespace detail
  19. template<class T>
  20. std::string
  21. serialize(T const& t, serialize_options const& opts)
  22. {
  23. unsigned char buf[256];
  24. serializer sr(
  25. storage_ptr(),
  26. buf,
  27. sizeof(buf),
  28. opts);
  29. std::string s;
  30. sr.reset(&t);
  31. detail::serialize_impl(s, sr);
  32. return s;
  33. }
  34. } // namespace json
  35. } // namespace boost
  36. #endif // BOOST_JSON_IMPL_SERIALIZE_HPP