Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
stream_parser::write_some (4 of 4 overloads)

Parse a buffer containing all or part of a complete JSON.

Synopsis
std::size_t
write_some(
    string_view s);
Description

This function parses JSON contained in the specified character buffer. If parsing completes, any additional characters past the end of the complete JSON 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 JSONs or containing different protocol data.

Example
stream_parser p;                                // construct a parser
std::size_t n;                                  // number of characters used
n = p.write_some( "\[1,2" );                     // parse the first part of the JSON
assert( n == 4 );                               // all characters consumed
n = p.write_some( "3,4\] null" );                // parse the rest of the JSON
assert( n == 5 );                               // only some characters consumed
value jv = p.release();                         // take ownership of the value
Remarks

To indicate there are no more character buffers, such as when done returns false after writing, call finish.

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.

Return Value

The number of characters consumed from the buffer.

Parameters

Name

Description

s

The character string to parse.

Exceptions

Type

Thrown On

system_error

Thrown on error.


PrevUpHomeNext