Argo  1.0
A C++ library for handling JSON.
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
argo::reader Class Referenceabstract

A class to read JSON messages from various types of input stream. More...

#include <reader.hpp>

Inheritance diagram for argo::reader:
argo::fd_reader argo::file_reader argo::stream_reader

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

reader::reader ( size_t  max_message_length,
bool  block_read 
)

Constructor.

Parameters
max_message_lengthmaximum number bytes to be read in total
block_readif true read in blocks, if false read one byte at a time

Definition at line 31 of file reader.cpp.

Member Function Documentation

int reader::next ( )
virtual

Get the next character from the reader.

Returns
A character or EOF on end of file.
Exceptions
json_io_exceptionafter an IO error of some type.
json_parser_exceptionif the message is too long

Definition at line 54 of file reader.cpp.

virtual bool argo::reader::read_next_block ( )
protectedpure virtual

Implemented by derived classes to read the next block of data up to block_size bytes.

Returns
true if some data was read, false if EOF.
Exceptions
json_io_errorif the read failed for some reason other than EOF.

Implemented in argo::file_reader, argo::stream_reader, and argo::fd_reader.


The documentation for this class was generated from the following files: