![]() |
Argo
1.0
A C++ library for handling JSON.
|
A class to read JSON messages from various types of input stream. More...
#include <reader.hpp>
Public Member Functions | |
reader (size_t max_message_length, bool block_read) | |
virtual int | next () |
Get the next character from the reader. More... | |
virtual void | put_back (int c) |
Put back a character so that it is returned by the next call to next(). | |
size_t | get_byte_index () const |
Get the current byte index in the input. | |
void | reset_byte_index () |
Reset the byte index at the start of parsing a messege. | |
Static Public Attributes | |
static const int | block_size = 8192 |
Amount of data to read at once when in block read mode. | |
Protected Member Functions | |
int | read_next_char_from_block () |
When in block read mode, get the next available character. | |
virtual int | read_next_char ()=0 |
Implemented by derived classes to do the actual reading. | |
virtual bool | read_next_block ()=0 |
Protected Attributes | |
int | m_put_back |
Character last put back. If equal to no_put_back then none was. | |
size_t | m_byte_index |
Total number of characters read. | |
size_t | m_max_message_length |
Maximum length of a message. | |
bool | m_block_read |
Whether to read in blocks or one byte at a time. | |
unsigned char | m_block [block_size] |
If we're reading blocks, the block data. | |
int | m_block_num_bytes |
If we're reading blocks, the number of bytes in the current block. | |
int | m_block_index |
If we're reading blocks, the index into the current block. | |
Static Protected Attributes | |
static const int | no_put_back = 1000 |
Special character value indicating that no character has been put back. | |
A class to read JSON messages from various types of input stream.
A class that acts as a proxy for the various places that JSON messages can be parsed from (or from which they can be parsed even). The base class tracks how many characters have been read and handles put back logic, actually reading from somewhere is in in derived classes.
Definition at line 42 of file reader.hpp.
reader::reader | ( | size_t | max_message_length, |
bool | block_read | ||
) |
Constructor.
max_message_length | maximum number bytes to be read in total |
block_read | if true read in blocks, if false read one byte at a time |
Definition at line 31 of file reader.cpp.
|
virtual |
Get the next character from the reader.
json_io_exception | after an IO error of some type. |
json_parser_exception | if the message is too long |
Definition at line 54 of file reader.cpp.
|
protectedpure virtual |
Implemented by derived classes to read the next block of data up to block_size bytes.
json_io_error | if the read failed for some reason other than EOF. |
Implemented in argo::file_reader, argo::stream_reader, and argo::fd_reader.