diff --git a/home/architecture.md b/home/architecture.md index 51ce62fda..295ea09ba 100644 --- a/home/architecture.md +++ b/home/architecture.md @@ -339,6 +339,11 @@ The `serializer` (used by [`dump`](../api/basic_json/dump.md) and [`operator<<`] - `output_stream_adapter` writes to a `std::ostream`. - `output_string_adapter` appends to a string. +The `binary_writer` does not call an adapter for every byte. The `to_*` functions that return a `std::vector` write +into the vector through a sink (`output_vector_sink`) that is not virtual. The functions that take an output adapter +write through a sink (`output_adapter_sink`) that collects the output in a buffer of one kibibyte and passes it to the +adapter in blocks, so that the adapter is called (and a stream locked) once per block instead of once per value. + ## Value conversion Values are converted from and to other types with the `JSONSerializer` template parameter. The default, diff --git a/home/architecture/index.html b/home/architecture/index.html index aab2c653c..3b59265c7 100644 --- a/home/architecture/index.html +++ b/home/architecture/index.html @@ -87,9 +87,9 @@
The lexer detects two optional extensions at compile time. Only iterator_input_adapter provides them, and only for random-access input of single-byte characters:
supports_seek, get_consumed_count(), and copy_consumed_range() let the lexer reconstruct already consumed input for error messages instead of copying every character it reads. With get_read_count() and count_consumed_lines(), the lexer also derives the read position from the adapter and counts lines only when an error needs them, instead of counting characters and lines on every read.supports_bulk_scan, bulk_data(), bulk_remaining(), and bulk_skip() let the lexer scan strings directly in contiguous memory, several bytes at a time, and skip the spaces that indent a line in 8-byte steps.The function input_adapter picks the right adapter for the argument passed to parse, accept, sax_parse, or the from_* functions:
iterator_input_adapter reads from an iterator range, which also covers strings, containers, and pointers.wide_string_input_adapter reads from ranges of wchar_t, char16_t, or char32_t and converts them to UTF-8. It cannot be used for binary formats; its get_elements() throws.input_stream_adapter reads from a std::istream.file_input_adapter reads from a std::FILE*.The parser does not build values itself. It reports what it reads as events to a SAX consumer, which implements the interface json_sax: null, boolean, number_integer, number_unsigned, number_float, string, binary, start_object, key, end_object, start_array, end_array, and parse_error.
The library comes with two consumers in detail/input/json_sax.hpp:
json_sax_dom_parser builds a basic_json value tree. parse uses it.json_sax_dom_callback_parser does the same, but calls a parser callback for each event, which can skip values. parse uses it when a callback is given.The binary_reader emits the same events for binary formats, so sax_parse works with a user-defined consumer for JSON and for all binary formats alike.
Output is written via output adapters:
void write_character(CharType c);
void write_characters(const CharType* s, std::size_t length);
-The serializer (used by dump and operator<<) and the binary_writer (used by the to_* functions) write to one of these adapters:
output_vector_adapter appends to a std::vector.output_stream_adapter writes to a std::ostream.output_string_adapter appends to a string.Values are converted from and to other types with the JSONSerializer template parameter. The default, adl_serializer, calls the free functions
template<class T>
+The serializer (used by dump and operator<<) and the binary_writer (used by the to_* functions) write to one of these adapters:
output_vector_adapter appends to a std::vector.output_stream_adapter writes to a std::ostream.output_string_adapter appends to a string.The binary_writer does not call an adapter for every byte. The to_* functions that return a std::vector write into the vector through a sink (output_vector_sink) that is not virtual. The functions that take an output adapter write through a sink (output_adapter_sink) that collects the output in a buffer of one kibibyte and passes it to the adapter in blocks, so that the adapter is called (and a stream locked) once per block instead of once per value.
Values are converted from and to other types with the JSONSerializer template parameter. The default, adl_serializer, calls the free functions
template<class T>
void to_json(basic_json& j, const T& t);
template<class T>
void from_json(const basic_json& j, T& t);
-found by argument-dependent lookup. The library defines them for standard types in detail/conversions; users add them for their own types, see Arbitrary Type Conversions. The serialization macros generate these functions.
json_pointer) addresses values inside a tree. It is also the basis of JSON Patch.binary_reader and written by binary_writer.basic_json value.to_json and from_json functions for user-defined types.Namespace nlohmann::detail contains all implementation details. It is not part of the public API and may change in any release. Besides the components above, it contains:
detail/meta/type_traits.hpp),detail/meta/cpp_future.hpp), andstring_concat and string_escape.