parser::write_some
Parse a buffer containing a complete JSON text.
Synopsis
std::size_t
write_some(
char const* data,
std::size_t size,
boost::system::error_code& ec); (1)
std::size_t
write_some(
char const* data,
std::size_t size,
std::error_code& ec); (2)
std::size_t
write_some(
string_view s,
boost::system::error_code& ec); (3)
std::size_t
write_some(
string_view s,
std::error_code& ec); (4)
std::size_t
write_some(
char const* data,
std::size_t size); (5)
std::size_t
write_some(
string_view s); (6)
Description
This function parses a complete JSON text contained in the specified character buffer. Additional characters past the end of the complete JSON text are ignored. The function returns the actual number of characters parsed, which may be less than the size of the input. This allows parsing of a buffer containing multiple individual JSON texts or containing different protocol data:
Example
parser p; // construct a parser
size_t n = p.write_some( "[1,2,3] null" ); // parse a complete JSON text
assert( n == 8 ); // only some characters consumed
value jv = p.release(); // take ownership of the value
Complexity
Linear in size
.
Exception Safety
Basic guarantee. Calls to memory_resource::allocate
may throw. Upon error or exception, subsequent calls will fail until reset
is called to parse a new JSON text.
Return Value
The number of characters consumed from the buffer.
Return Value
The number of characters consumed from the buffer.
Return Value
The number of characters consumed from the buffer.
Return Value
The number of characters consumed from the buffer.
Return Value
The number of characters consumed from the buffer.
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. |