stream_parser::write
Parse a buffer containing all or part of a complete JSON text.
Synopsis
std::size_t
write(
char const* data,
std::size_t size,
boost::system::error_code& ec); (1)
std::size_t
write(
char const* data,
std::size_t size,
std::error_code& ec); (2)
std::size_t
write(
char const* data,
std::size_t size); (3)
std::size_t
write(
string_view s,
boost::system::error_code& ec); (4)
std::size_t
write(
string_view s,
std::error_code& ec); (5)
std::size_t
write(
string_view s); (6)
Description
This function parses all or part of a JSON text contained in the specified character buffer. The entire buffer must be consumed; if there are additional characters past the end of the complete JSON text, the parse fails and an error is returned.
Overloads (1), (2), (4), and (5) report errors by setting ec
. Overloads (3) and (6) report errors by throwing exceptions. Upon error or exception, subsequent calls will fail until reset
is called to parse a new JSON text.
Example
stream_parser p; // construct a parser
std::size_t n; // number of characters used
n = p.write( "[1,2" ); // parse some of the JSON text
assert( n == 4 ); // all characters consumed
n = p.write( "3,4]" ); // parse the rest of the JSON text
assert( n == 4 ); // all characters consumed
value jv = p.release(); // take ownership of the value
Complexity
-
(1)–(3) linear in
size
. -
(4)–(6) linear in
s.size()
.
Exception Safety
Basic guarantee. Calls to memory_resource::allocate
may throw.
Return Value
The number of characters consumed from the buffer.
Parameters
Name | Description |
---|---|
|
A pointer to a buffer of |
|
The number of characters pointed to by |
|
Set to the error, if any occurred. |
|
The character string to parse. |
Exceptions
Type | Thrown On |
---|---|
|
Thrown on error. |