mirror of
https://github.com/boostorg/json.git
synced 2025-05-11 13:44:06 +00:00
direct serialization docs
This commit is contained in:
parent
7b493e792a
commit
8e1fc20896
@ -13,8 +13,10 @@
|
||||
[section Direct parsing]
|
||||
|
||||
For large inputs parsing into the library's containers followed by conversion
|
||||
via __value_to__ might be prohibitively expensive. For these cases the library
|
||||
provides components that allow parsing directly into user-provided objects.
|
||||
via __value_to__ (or vice versa __value_from__ followed by serialization from
|
||||
a __value__) might be prohibitively expensive. For these cases the library
|
||||
provides components that allow parsing directly into and serializing directly
|
||||
from user-provided objects.
|
||||
|
||||
The drawback of this approach is that fully custom type representations are
|
||||
not supported, only the library-provided conversions are. Also all objects that
|
||||
@ -23,8 +25,8 @@ includes not only the top-level object, but e.g. elements of containers,
|
||||
members of described `struct`s, and alternatives of variants.
|
||||
|
||||
That being said, if your types are default-constructible and you don't need
|
||||
the customisability allowed by __value_to__, then you can get a significant
|
||||
performance boost with direct parsing.
|
||||
the customisability allowed by __value_to__ and __value_from__, then you can
|
||||
get a significant performance boost with direct parsing.
|
||||
|
||||
Direct parsing is performed by the __parse_into__ family of functions. The
|
||||
library provides overloads that take either __string_view__ or `std::istream`,
|
||||
@ -32,9 +34,12 @@ and can report errors either via throwing exceptions or setting an error code.
|
||||
|
||||
[doc_parse_into_1]
|
||||
|
||||
Finally, if you need to combine incremental parsing with direct parsing, you
|
||||
can resort to __parser_for__. `parser_for<T>` is an instantiation of
|
||||
__basic_parser__ that parses into an object of type `T`, and is what
|
||||
__parse_into__ uses under the hood.
|
||||
If you need to combine incremental parsing with direct parsing, you can resort
|
||||
to __parser_for__. `parser_for<T>` is an instantiation of __basic_parser__ that
|
||||
parses into an object of type `T`, and is what __parse_into__ uses under
|
||||
the hood.
|
||||
|
||||
Direct serialization doesn't require any special components and works with the
|
||||
refular __serializer__ and __serialize__.
|
||||
|
||||
[endsect]
|
||||
|
@ -1152,6 +1152,10 @@ usingParseInto()
|
||||
string_view input = R"( { "even": [2,4,6], "odd": [1,3,5] } )";
|
||||
parse_into(vectors, input);
|
||||
//]
|
||||
|
||||
std::string output = serialize(vectors);
|
||||
(void)output;
|
||||
assert( output == R"({"even":[2,4,6],"odd":[1,3,5]})" );
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user