File indexing completed on 2025-01-18 09:39:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_JSON_IMPL_STREAM_PARSER_IPP
0011 #define BOOST_JSON_IMPL_STREAM_PARSER_IPP
0012
0013 #include <boost/json/stream_parser.hpp>
0014 #include <boost/json/basic_parser_impl.hpp>
0015 #include <boost/json/error.hpp>
0016 #include <cstring>
0017 #include <stdexcept>
0018 #include <utility>
0019
0020 namespace boost {
0021 namespace json {
0022
0023 stream_parser::
0024 stream_parser(
0025 storage_ptr sp,
0026 parse_options const& opt,
0027 unsigned char* buffer,
0028 std::size_t size) noexcept
0029 : p_(
0030 opt,
0031 std::move(sp),
0032 buffer,
0033 size)
0034 {
0035 reset();
0036 }
0037
0038 stream_parser::
0039 stream_parser(
0040 storage_ptr sp,
0041 parse_options const& opt) noexcept
0042 : p_(
0043 opt,
0044 std::move(sp),
0045 nullptr,
0046 0)
0047 {
0048 reset();
0049 }
0050
0051 void
0052 stream_parser::
0053 reset(storage_ptr sp) noexcept
0054 {
0055 p_.reset();
0056 p_.handler().st.reset(sp);
0057 }
0058
0059 std::size_t
0060 stream_parser::
0061 write_some(
0062 char const* data,
0063 std::size_t size,
0064 error_code& ec)
0065 {
0066 return p_.write_some(
0067 true, data, size, ec);
0068 }
0069
0070 std::size_t
0071 stream_parser::
0072 write_some(
0073 char const* data,
0074 std::size_t size,
0075 std::error_code& ec)
0076 {
0077 error_code jec;
0078 std::size_t const result = write_some(data, size, jec);
0079 ec = jec;
0080 return result;
0081 }
0082
0083 std::size_t
0084 stream_parser::
0085 write_some(
0086 char const* data,
0087 std::size_t size)
0088 {
0089 error_code ec;
0090 auto const n = write_some(
0091 data, size, ec);
0092 if(ec)
0093 detail::throw_system_error( ec );
0094 return n;
0095 }
0096
0097 std::size_t
0098 stream_parser::
0099 write(
0100 char const* data,
0101 std::size_t size,
0102 error_code& ec)
0103 {
0104 auto const n = write_some(
0105 data, size, ec);
0106 if(! ec && n < size)
0107 {
0108 BOOST_JSON_FAIL(ec, error::extra_data);
0109 p_.fail(ec);
0110 }
0111 return n;
0112 }
0113
0114 std::size_t
0115 stream_parser::
0116 write(
0117 char const* data,
0118 std::size_t size,
0119 std::error_code& ec)
0120 {
0121 error_code jec;
0122 std::size_t const result = write(data, size, jec);
0123 ec = jec;
0124 return result;
0125 }
0126
0127 std::size_t
0128 stream_parser::
0129 write(
0130 char const* data,
0131 std::size_t size)
0132 {
0133 error_code ec;
0134 auto const n = write(
0135 data, size, ec);
0136 if(ec)
0137 detail::throw_system_error( ec );
0138 return n;
0139 }
0140
0141 void
0142 stream_parser::
0143 finish(error_code& ec)
0144 {
0145 p_.write_some(false, nullptr, 0, ec);
0146 }
0147
0148 void
0149 stream_parser::
0150 finish()
0151 {
0152 error_code ec;
0153 finish(ec);
0154 if(ec)
0155 detail::throw_system_error( ec );
0156 }
0157
0158 void
0159 stream_parser::
0160 finish(std::error_code& ec)
0161 {
0162 error_code jec;
0163 finish(jec);
0164 ec = jec;
0165 }
0166
0167 value
0168 stream_parser::
0169 release()
0170 {
0171 if(! p_.done())
0172 {
0173
0174 finish();
0175 }
0176 return p_.handler().st.release();
0177 }
0178
0179 }
0180 }
0181
0182 #endif