| Home | Libraries | People | FAQ | More

###### stream_parser::write (2 of 4 overloads)

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

<h7> Synopsis </h7>

    std::size_t
    write(
        char const* data,
        std::size_t size);

<h7> Description </h7>

This function parses a all or part of a JSON contained in the specified character buffer. The entire buffer must be consumed; if there are additional characters past the end of the complete JSON, the parse fails and an error is returned.

<h7> Example </h7>

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

<h7> Remarks </h7>

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

<h7> Complexity </h7>

Linear in `size`.

<h7> Exception Safety </h7>

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.

<h7> Return Value </h7>

The number of characters consumed from the buffer.

<h7> Parameters </h7>

Name | Description
--- | ---
`data` | A pointer to a buffer of `size` characters to parse.
`size` | The number of characters pointed to by `data`.

<h7> Exceptions </h7>

Type | Thrown On
--- | ---
`system_error` | Thrown on error.