serializer.ipp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. //
  2. // Copyright (c) 2019 Vinnie Falco ([email protected])
  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_SERIALIZER_IPP
  10. #define BOOST_JSON_IMPL_SERIALIZER_IPP
  11. #include <boost/json/serializer.hpp>
  12. #include <boost/json/detail/format.hpp>
  13. #include <boost/json/detail/sse2.hpp>
  14. #include <ostream>
  15. #ifdef _MSC_VER
  16. #pragma warning(push)
  17. #pragma warning(disable: 4127) // conditional expression is constant
  18. #endif
  19. namespace boost {
  20. namespace json {
  21. enum class serializer::state : char
  22. {
  23. nul1, nul2, nul3, nul4,
  24. tru1, tru2, tru3, tru4,
  25. fal1, fal2, fal3, fal4, fal5,
  26. str1, str2, str3, esc1, utf1,
  27. utf2, utf3, utf4, utf5,
  28. num,
  29. arr1, arr2, arr3, arr4,
  30. obj1, obj2, obj3, obj4, obj5, obj6
  31. };
  32. //----------------------------------------------------------
  33. serializer::
  34. serializer(
  35. storage_ptr sp,
  36. unsigned char* buf,
  37. std::size_t buf_size,
  38. serialize_options const& opts) noexcept
  39. : st_(
  40. std::move(sp),
  41. buf,
  42. buf_size)
  43. , opts_(opts)
  44. {
  45. }
  46. bool
  47. serializer::
  48. suspend(state st)
  49. {
  50. st_.push(st);
  51. return false;
  52. }
  53. bool
  54. serializer::
  55. suspend(
  56. state st,
  57. array::const_iterator it,
  58. array const* pa)
  59. {
  60. st_.push(pa);
  61. st_.push(it);
  62. st_.push(st);
  63. return false;
  64. }
  65. bool
  66. serializer::
  67. suspend(
  68. state st,
  69. object::const_iterator it,
  70. object const* po)
  71. {
  72. st_.push(po);
  73. st_.push(it);
  74. st_.push(st);
  75. return false;
  76. }
  77. template<bool StackEmpty>
  78. bool
  79. serializer::
  80. write_null(stream& ss0)
  81. {
  82. local_stream ss(ss0);
  83. if(! StackEmpty && ! st_.empty())
  84. {
  85. state st;
  86. st_.pop(st);
  87. switch(st)
  88. {
  89. default:
  90. case state::nul1: goto do_nul1;
  91. case state::nul2: goto do_nul2;
  92. case state::nul3: goto do_nul3;
  93. case state::nul4: goto do_nul4;
  94. }
  95. }
  96. do_nul1:
  97. if(BOOST_JSON_LIKELY(ss))
  98. ss.append('n');
  99. else
  100. return suspend(state::nul1);
  101. do_nul2:
  102. if(BOOST_JSON_LIKELY(ss))
  103. ss.append('u');
  104. else
  105. return suspend(state::nul2);
  106. do_nul3:
  107. if(BOOST_JSON_LIKELY(ss))
  108. ss.append('l');
  109. else
  110. return suspend(state::nul3);
  111. do_nul4:
  112. if(BOOST_JSON_LIKELY(ss))
  113. ss.append('l');
  114. else
  115. return suspend(state::nul4);
  116. return true;
  117. }
  118. template<bool StackEmpty>
  119. bool
  120. serializer::
  121. write_true(stream& ss0)
  122. {
  123. local_stream ss(ss0);
  124. if(! StackEmpty && ! st_.empty())
  125. {
  126. state st;
  127. st_.pop(st);
  128. switch(st)
  129. {
  130. default:
  131. case state::tru1: goto do_tru1;
  132. case state::tru2: goto do_tru2;
  133. case state::tru3: goto do_tru3;
  134. case state::tru4: goto do_tru4;
  135. }
  136. }
  137. do_tru1:
  138. if(BOOST_JSON_LIKELY(ss))
  139. ss.append('t');
  140. else
  141. return suspend(state::tru1);
  142. do_tru2:
  143. if(BOOST_JSON_LIKELY(ss))
  144. ss.append('r');
  145. else
  146. return suspend(state::tru2);
  147. do_tru3:
  148. if(BOOST_JSON_LIKELY(ss))
  149. ss.append('u');
  150. else
  151. return suspend(state::tru3);
  152. do_tru4:
  153. if(BOOST_JSON_LIKELY(ss))
  154. ss.append('e');
  155. else
  156. return suspend(state::tru4);
  157. return true;
  158. }
  159. template<bool StackEmpty>
  160. bool
  161. serializer::
  162. write_false(stream& ss0)
  163. {
  164. local_stream ss(ss0);
  165. if(! StackEmpty && ! st_.empty())
  166. {
  167. state st;
  168. st_.pop(st);
  169. switch(st)
  170. {
  171. default:
  172. case state::fal1: goto do_fal1;
  173. case state::fal2: goto do_fal2;
  174. case state::fal3: goto do_fal3;
  175. case state::fal4: goto do_fal4;
  176. case state::fal5: goto do_fal5;
  177. }
  178. }
  179. do_fal1:
  180. if(BOOST_JSON_LIKELY(ss))
  181. ss.append('f');
  182. else
  183. return suspend(state::fal1);
  184. do_fal2:
  185. if(BOOST_JSON_LIKELY(ss))
  186. ss.append('a');
  187. else
  188. return suspend(state::fal2);
  189. do_fal3:
  190. if(BOOST_JSON_LIKELY(ss))
  191. ss.append('l');
  192. else
  193. return suspend(state::fal3);
  194. do_fal4:
  195. if(BOOST_JSON_LIKELY(ss))
  196. ss.append('s');
  197. else
  198. return suspend(state::fal4);
  199. do_fal5:
  200. if(BOOST_JSON_LIKELY(ss))
  201. ss.append('e');
  202. else
  203. return suspend(state::fal5);
  204. return true;
  205. }
  206. template<bool StackEmpty>
  207. bool
  208. serializer::
  209. write_string(stream& ss0)
  210. {
  211. local_stream ss(ss0);
  212. local_const_stream cs(cs0_);
  213. if(! StackEmpty && ! st_.empty())
  214. {
  215. state st;
  216. st_.pop(st);
  217. switch(st)
  218. {
  219. default:
  220. case state::str1: goto do_str1;
  221. case state::str2: goto do_str2;
  222. case state::str3: goto do_str3;
  223. case state::esc1: goto do_esc1;
  224. case state::utf1: goto do_utf1;
  225. case state::utf2: goto do_utf2;
  226. case state::utf3: goto do_utf3;
  227. case state::utf4: goto do_utf4;
  228. case state::utf5: goto do_utf5;
  229. }
  230. }
  231. static constexpr char hex[] = "0123456789abcdef";
  232. static constexpr char esc[] =
  233. "uuuuuuuubtnufruuuuuuuuuuuuuuuuuu"
  234. "\0\0\"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  235. "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\0\0\0"
  236. "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  237. "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  238. "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  239. "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  240. "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  241. // opening quote
  242. do_str1:
  243. if(BOOST_JSON_LIKELY(ss))
  244. ss.append('\x22'); // '"'
  245. else
  246. return suspend(state::str1);
  247. // fast loop,
  248. // copy unescaped
  249. do_str2:
  250. if(BOOST_JSON_LIKELY(ss))
  251. {
  252. std::size_t n = cs.remain();
  253. if(BOOST_JSON_LIKELY(n > 0))
  254. {
  255. if(ss.remain() > n)
  256. n = detail::count_unescaped(
  257. cs.data(), n);
  258. else
  259. n = detail::count_unescaped(
  260. cs.data(), ss.remain());
  261. if(n > 0)
  262. {
  263. ss.append(cs.data(), n);
  264. cs.skip(n);
  265. if(! ss)
  266. return suspend(state::str2);
  267. }
  268. }
  269. else
  270. {
  271. ss.append('\x22'); // '"'
  272. return true;
  273. }
  274. }
  275. else
  276. {
  277. return suspend(state::str2);
  278. }
  279. // slow loop,
  280. // handle escapes
  281. do_str3:
  282. while(BOOST_JSON_LIKELY(ss))
  283. {
  284. if(BOOST_JSON_LIKELY(cs))
  285. {
  286. auto const ch = *cs;
  287. auto const c = esc[static_cast<
  288. unsigned char>(ch)];
  289. ++cs;
  290. if(! c)
  291. {
  292. ss.append(ch);
  293. }
  294. else if(c != 'u')
  295. {
  296. ss.append('\\');
  297. if(BOOST_JSON_LIKELY(ss))
  298. {
  299. ss.append(c);
  300. }
  301. else
  302. {
  303. buf_[0] = c;
  304. return suspend(
  305. state::esc1);
  306. }
  307. }
  308. else
  309. {
  310. if(BOOST_JSON_LIKELY(
  311. ss.remain() >= 6))
  312. {
  313. ss.append("\\u00", 4);
  314. ss.append(hex[static_cast<
  315. unsigned char>(ch) >> 4]);
  316. ss.append(hex[static_cast<
  317. unsigned char>(ch) & 15]);
  318. }
  319. else
  320. {
  321. ss.append('\\');
  322. buf_[0] = hex[static_cast<
  323. unsigned char>(ch) >> 4];
  324. buf_[1] = hex[static_cast<
  325. unsigned char>(ch) & 15];
  326. goto do_utf1;
  327. }
  328. }
  329. }
  330. else
  331. {
  332. ss.append('\x22'); // '"'
  333. return true;
  334. }
  335. }
  336. return suspend(state::str3);
  337. do_esc1:
  338. if(BOOST_JSON_LIKELY(ss))
  339. ss.append(buf_[0]);
  340. else
  341. return suspend(state::esc1);
  342. goto do_str3;
  343. do_utf1:
  344. if(BOOST_JSON_LIKELY(ss))
  345. ss.append('u');
  346. else
  347. return suspend(state::utf1);
  348. do_utf2:
  349. if(BOOST_JSON_LIKELY(ss))
  350. ss.append('0');
  351. else
  352. return suspend(state::utf2);
  353. do_utf3:
  354. if(BOOST_JSON_LIKELY(ss))
  355. ss.append('0');
  356. else
  357. return suspend(state::utf3);
  358. do_utf4:
  359. if(BOOST_JSON_LIKELY(ss))
  360. ss.append(buf_[0]);
  361. else
  362. return suspend(state::utf4);
  363. do_utf5:
  364. if(BOOST_JSON_LIKELY(ss))
  365. ss.append(buf_[1]);
  366. else
  367. return suspend(state::utf5);
  368. goto do_str3;
  369. }
  370. template<bool StackEmpty>
  371. bool
  372. serializer::
  373. write_number(stream& ss0)
  374. {
  375. local_stream ss(ss0);
  376. if(StackEmpty || st_.empty())
  377. {
  378. switch(jv_->kind())
  379. {
  380. default:
  381. case kind::int64:
  382. if(BOOST_JSON_LIKELY(
  383. ss.remain() >=
  384. detail::max_number_chars))
  385. {
  386. ss.advance(detail::format_int64(
  387. ss.data(), jv_->get_int64()));
  388. return true;
  389. }
  390. cs0_ = { buf_, detail::format_int64(
  391. buf_, jv_->get_int64()) };
  392. break;
  393. case kind::uint64:
  394. if(BOOST_JSON_LIKELY(
  395. ss.remain() >=
  396. detail::max_number_chars))
  397. {
  398. ss.advance(detail::format_uint64(
  399. ss.data(), jv_->get_uint64()));
  400. return true;
  401. }
  402. cs0_ = { buf_, detail::format_uint64(
  403. buf_, jv_->get_uint64()) };
  404. break;
  405. case kind::double_:
  406. if(BOOST_JSON_LIKELY(
  407. ss.remain() >=
  408. detail::max_number_chars))
  409. {
  410. ss.advance(
  411. detail::format_double(
  412. ss.data(),
  413. jv_->get_double(),
  414. opts_.allow_infinity_and_nan));
  415. return true;
  416. }
  417. cs0_ = { buf_, detail::format_double(
  418. buf_, jv_->get_double(), opts_.allow_infinity_and_nan) };
  419. break;
  420. }
  421. }
  422. else
  423. {
  424. state st;
  425. st_.pop(st);
  426. BOOST_ASSERT(
  427. st == state::num);
  428. }
  429. auto const n = ss.remain();
  430. if(n < cs0_.remain())
  431. {
  432. ss.append(cs0_.data(), n);
  433. cs0_.skip(n);
  434. return suspend(state::num);
  435. }
  436. ss.append(
  437. cs0_.data(), cs0_.remain());
  438. return true;
  439. }
  440. template<bool StackEmpty>
  441. bool
  442. serializer::
  443. write_array(stream& ss0)
  444. {
  445. array const* pa;
  446. local_stream ss(ss0);
  447. array::const_iterator it;
  448. array::const_iterator end;
  449. if(StackEmpty || st_.empty())
  450. {
  451. pa = pa_;
  452. it = pa->begin();
  453. end = pa->end();
  454. }
  455. else
  456. {
  457. state st;
  458. st_.pop(st);
  459. st_.pop(it);
  460. st_.pop(pa);
  461. end = pa->end();
  462. switch(st)
  463. {
  464. default:
  465. case state::arr1: goto do_arr1;
  466. case state::arr2: goto do_arr2;
  467. case state::arr3: goto do_arr3;
  468. case state::arr4: goto do_arr4;
  469. break;
  470. }
  471. }
  472. do_arr1:
  473. if(BOOST_JSON_LIKELY(ss))
  474. ss.append('[');
  475. else
  476. return suspend(
  477. state::arr1, it, pa);
  478. if(it == end)
  479. goto do_arr4;
  480. for(;;)
  481. {
  482. do_arr2:
  483. jv_ = &*it;
  484. if(! write_value<StackEmpty>(ss))
  485. return suspend(
  486. state::arr2, it, pa);
  487. if(BOOST_JSON_UNLIKELY(
  488. ++it == end))
  489. break;
  490. do_arr3:
  491. if(BOOST_JSON_LIKELY(ss))
  492. ss.append(',');
  493. else
  494. return suspend(
  495. state::arr3, it, pa);
  496. }
  497. do_arr4:
  498. if(BOOST_JSON_LIKELY(ss))
  499. ss.append(']');
  500. else
  501. return suspend(
  502. state::arr4, it, pa);
  503. return true;
  504. }
  505. template<bool StackEmpty>
  506. bool
  507. serializer::
  508. write_object(stream& ss0)
  509. {
  510. object const* po;
  511. local_stream ss(ss0);
  512. object::const_iterator it;
  513. object::const_iterator end;
  514. if(StackEmpty || st_.empty())
  515. {
  516. po = po_;
  517. it = po->begin();
  518. end = po->end();
  519. }
  520. else
  521. {
  522. state st;
  523. st_.pop(st);
  524. st_.pop(it);
  525. st_.pop(po);
  526. end = po->end();
  527. switch(st)
  528. {
  529. default:
  530. case state::obj1: goto do_obj1;
  531. case state::obj2: goto do_obj2;
  532. case state::obj3: goto do_obj3;
  533. case state::obj4: goto do_obj4;
  534. case state::obj5: goto do_obj5;
  535. case state::obj6: goto do_obj6;
  536. break;
  537. }
  538. }
  539. do_obj1:
  540. if(BOOST_JSON_LIKELY(ss))
  541. ss.append('{');
  542. else
  543. return suspend(
  544. state::obj1, it, po);
  545. if(BOOST_JSON_UNLIKELY(
  546. it == end))
  547. goto do_obj6;
  548. for(;;)
  549. {
  550. cs0_ = {
  551. it->key().data(),
  552. it->key().size() };
  553. do_obj2:
  554. if(BOOST_JSON_UNLIKELY(
  555. ! write_string<StackEmpty>(ss)))
  556. return suspend(
  557. state::obj2, it, po);
  558. do_obj3:
  559. if(BOOST_JSON_LIKELY(ss))
  560. ss.append(':');
  561. else
  562. return suspend(
  563. state::obj3, it, po);
  564. do_obj4:
  565. jv_ = &it->value();
  566. if(BOOST_JSON_UNLIKELY(
  567. ! write_value<StackEmpty>(ss)))
  568. return suspend(
  569. state::obj4, it, po);
  570. ++it;
  571. if(BOOST_JSON_UNLIKELY(it == end))
  572. break;
  573. do_obj5:
  574. if(BOOST_JSON_LIKELY(ss))
  575. ss.append(',');
  576. else
  577. return suspend(
  578. state::obj5, it, po);
  579. }
  580. do_obj6:
  581. if(BOOST_JSON_LIKELY(ss))
  582. {
  583. ss.append('}');
  584. return true;
  585. }
  586. return suspend(
  587. state::obj6, it, po);
  588. }
  589. template<bool StackEmpty>
  590. bool
  591. serializer::
  592. write_value(stream& ss)
  593. {
  594. if(StackEmpty || st_.empty())
  595. {
  596. auto const& jv(*jv_);
  597. switch(jv.kind())
  598. {
  599. default:
  600. case kind::object:
  601. po_ = &jv.get_object();
  602. return write_object<true>(ss);
  603. case kind::array:
  604. pa_ = &jv.get_array();
  605. return write_array<true>(ss);
  606. case kind::string:
  607. {
  608. auto const& js = jv.get_string();
  609. cs0_ = { js.data(), js.size() };
  610. return write_string<true>(ss);
  611. }
  612. case kind::int64:
  613. case kind::uint64:
  614. case kind::double_:
  615. return write_number<true>(ss);
  616. case kind::bool_:
  617. if(jv.get_bool())
  618. {
  619. if(BOOST_JSON_LIKELY(
  620. ss.remain() >= 4))
  621. {
  622. ss.append("true", 4);
  623. return true;
  624. }
  625. return write_true<true>(ss);
  626. }
  627. else
  628. {
  629. if(BOOST_JSON_LIKELY(
  630. ss.remain() >= 5))
  631. {
  632. ss.append("false", 5);
  633. return true;
  634. }
  635. return write_false<true>(ss);
  636. }
  637. case kind::null:
  638. if(BOOST_JSON_LIKELY(
  639. ss.remain() >= 4))
  640. {
  641. ss.append("null", 4);
  642. return true;
  643. }
  644. return write_null<true>(ss);
  645. }
  646. }
  647. else
  648. {
  649. state st;
  650. st_.peek(st);
  651. switch(st)
  652. {
  653. default:
  654. case state::nul1: case state::nul2:
  655. case state::nul3: case state::nul4:
  656. return write_null<StackEmpty>(ss);
  657. case state::tru1: case state::tru2:
  658. case state::tru3: case state::tru4:
  659. return write_true<StackEmpty>(ss);
  660. case state::fal1: case state::fal2:
  661. case state::fal3: case state::fal4:
  662. case state::fal5:
  663. return write_false<StackEmpty>(ss);
  664. case state::str1: case state::str2:
  665. case state::str3: case state::esc1:
  666. case state::utf1: case state::utf2:
  667. case state::utf3: case state::utf4:
  668. case state::utf5:
  669. return write_string<StackEmpty>(ss);
  670. case state::num:
  671. return write_number<StackEmpty>(ss);
  672. case state::arr1: case state::arr2:
  673. case state::arr3: case state::arr4:
  674. return write_array<StackEmpty>(ss);
  675. case state::obj1: case state::obj2:
  676. case state::obj3: case state::obj4:
  677. case state::obj5: case state::obj6:
  678. return write_object<StackEmpty>(ss);
  679. }
  680. }
  681. }
  682. string_view
  683. serializer::
  684. read_some(
  685. char* dest, std::size_t size)
  686. {
  687. // If this goes off it means you forgot
  688. // to call reset() before seriailzing a
  689. // new value, or you never checked done()
  690. // to see if you should stop.
  691. BOOST_ASSERT(! done_);
  692. stream ss(dest, size);
  693. if(st_.empty())
  694. (this->*fn0_)(ss);
  695. else
  696. (this->*fn1_)(ss);
  697. if(st_.empty())
  698. {
  699. done_ = true;
  700. jv_ = nullptr;
  701. }
  702. return string_view(
  703. dest, ss.used(dest));
  704. }
  705. //----------------------------------------------------------
  706. serializer::
  707. serializer( serialize_options const& opts ) noexcept
  708. : opts_(opts)
  709. {
  710. // ensure room for \uXXXX escape plus one
  711. BOOST_STATIC_ASSERT(
  712. sizeof(serializer::buf_) >= 7);
  713. }
  714. void
  715. serializer::
  716. reset(value const* p) noexcept
  717. {
  718. pv_ = p;
  719. fn0_ = &serializer::write_value<true>;
  720. fn1_ = &serializer::write_value<false>;
  721. jv_ = p;
  722. st_.clear();
  723. done_ = false;
  724. }
  725. void
  726. serializer::
  727. reset(array const* p) noexcept
  728. {
  729. pa_ = p;
  730. fn0_ = &serializer::write_array<true>;
  731. fn1_ = &serializer::write_array<false>;
  732. st_.clear();
  733. done_ = false;
  734. }
  735. void
  736. serializer::
  737. reset(object const* p) noexcept
  738. {
  739. po_ = p;
  740. fn0_ = &serializer::write_object<true>;
  741. fn1_ = &serializer::write_object<false>;
  742. st_.clear();
  743. done_ = false;
  744. }
  745. void
  746. serializer::
  747. reset(string const* p) noexcept
  748. {
  749. cs0_ = { p->data(), p->size() };
  750. fn0_ = &serializer::write_string<true>;
  751. fn1_ = &serializer::write_string<false>;
  752. st_.clear();
  753. done_ = false;
  754. }
  755. void
  756. serializer::
  757. reset(string_view sv) noexcept
  758. {
  759. cs0_ = { sv.data(), sv.size() };
  760. fn0_ = &serializer::write_string<true>;
  761. fn1_ = &serializer::write_string<false>;
  762. st_.clear();
  763. done_ = false;
  764. }
  765. string_view
  766. serializer::
  767. read(char* dest, std::size_t size)
  768. {
  769. if(! jv_)
  770. {
  771. static value const null;
  772. jv_ = &null;
  773. }
  774. return read_some(dest, size);
  775. }
  776. } // namespace json
  777. } // namespace boost
  778. #ifdef _MSC_VER
  779. #pragma warning(pop)
  780. #endif
  781. #endif