123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- #ifndef BOOST_JSON_SERIALIZER_HPP
- #define BOOST_JSON_SERIALIZER_HPP
- #include <boost/json/detail/config.hpp>
- #include <boost/json/value.hpp>
- #include <boost/json/detail/format.hpp>
- #include <boost/json/detail/stack.hpp>
- #include <boost/json/detail/stream.hpp>
- BOOST_JSON_NS_BEGIN
- class serializer
- {
- enum class state : char;
-
- using stream = detail::stream;
- using const_stream = detail::const_stream;
- using local_stream = detail::local_stream;
- using local_const_stream =
- detail::local_const_stream;
- using fn_t = bool (serializer::*)(stream&);
- #ifndef BOOST_JSON_DOCS
- union
- {
- value const* pv_;
- array const* pa_;
- object const* po_;
- };
- #endif
- fn_t fn0_ = &serializer::write_null<true>;
- fn_t fn1_ = &serializer::write_null<false>;
- value const* jv_ = nullptr;
- detail::stack st_;
- const_stream cs0_;
- char buf_[detail::max_number_chars + 1];
- bool done_ = false;
- inline bool suspend(state st);
- inline bool suspend(
- state st, array::const_iterator it, array const* pa);
- inline bool suspend(
- state st, object::const_iterator it, object const* po);
- template<bool StackEmpty> bool write_null (stream& ss);
- template<bool StackEmpty> bool write_true (stream& ss);
- template<bool StackEmpty> bool write_false (stream& ss);
- template<bool StackEmpty> bool write_string (stream& ss);
- template<bool StackEmpty> bool write_number (stream& ss);
- template<bool StackEmpty> bool write_array (stream& ss);
- template<bool StackEmpty> bool write_object (stream& ss);
- template<bool StackEmpty> bool write_value (stream& ss);
- inline string_view read_some(char* dest, std::size_t size);
- public:
-
- serializer(serializer&&) = delete;
-
- BOOST_JSON_DECL
- ~serializer() noexcept;
-
- BOOST_JSON_DECL
- serializer() noexcept;
-
- bool
- done() const noexcept
- {
- return done_;
- }
-
-
- BOOST_JSON_DECL
- void
- reset(value const* p) noexcept;
- BOOST_JSON_DECL
- void
- reset(array const* p) noexcept;
- BOOST_JSON_DECL
- void
- reset(object const* p) noexcept;
- BOOST_JSON_DECL
- void
- reset(string const* p) noexcept;
-
-
- BOOST_JSON_DECL
- void
- reset(string_view sv) noexcept;
-
- BOOST_JSON_DECL
- string_view
- read(char* dest, std::size_t size);
-
- template<std::size_t N>
- string_view
- read(char(&dest)[N])
- {
- return read(dest, N);
- }
- #ifndef BOOST_JSON_DOCS
-
- template<std::size_t N>
- string_view
- read(char(&dest)[N], std::size_t n)
- {
-
-
-
- BOOST_ASSERT(n <= N);
- return read(dest, n);
- }
- #endif
- };
- BOOST_JSON_NS_END
- #endif
|