basic_parser::write_some

Parse some of input characters as JSON, incrementally.

Synopsis

std::size_t
write_some(
    bool more,
    char const* data,
    std::size_t size,
    boost::system::error_code& ec); (1)

std::size_t
write_some(
    bool more,
    char const* data,
    std::size_t size,
    std::error_code& ec); (2)

Description

This function parses the JSON text in the specified buffer, calling the handler to emit each SAX parsing event. The parse proceeds from the current state, which is at the beginning of a new JSON or in the middle of the current JSON if any characters were already parsed.

The characters in the buffer are processed starting from the beginning, until one of the following conditions is met:

  • All of the characters in the buffer have been parsed, or

  • Some of the characters in the buffer have been parsed and the JSON is complete, or

  • A parsing error occurs.

The supplied buffer does not need to contain the entire JSON. Subsequent calls can provide more serialized data, allowing JSON to be processed incrementally. The end of the serialized JSON can be indicated by passing more = false.

Complexity

Linear in size.

Exception Safety

Basic guarantee. Calls to the handler 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 successfully parsed, which may be smaller than size.

Return Value

The number of characters successfully parsed, which may be smaller than size.

Parameters

Name Description

more

true if there are possibly more buffers in the current JSON, otherwise false.

data

A pointer to a buffer of size characters to parse.

size

The number of characters pointed to by data.

ec

Set to the error, if any occurred.