![]() |
Argo
1.0
A C++ library for handling JSON.
|
A derived class of reader that reads from POSIX file descriptors. More...
#include <fd_reader.hpp>
Public Member Functions | |
fd_reader (int fd, int max_message_length, bool block_read) | |
![]() | |
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. | |
Protected Member Functions | |
virtual int | read_next_char () |
virtual bool | read_next_block () |
![]() | |
int | read_next_char_from_block () |
When in block read mode, get the next available character. | |
Protected Attributes | |
int | m_fd |
Underlying POSIX file descriptor. | |
![]() | |
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. | |
Additional Inherited Members | |
![]() | |
static const int | block_size = 8192 |
Amount of data to read at once when in block read mode. | |
![]() | |
static const int | no_put_back = 1000 |
Special character value indicating that no character has been put back. | |
A derived class of reader that reads from POSIX file descriptors.
Definition at line 33 of file fd_reader.hpp.
fd_reader::fd_reader | ( | int | fd, |
int | max_message_length, | ||
bool | block_read | ||
) |
Constructor.
fd | POSIX stream file descriptor. The instance does not take ownership of the open file and it is up to the calling code to close it when done. |
max_message_length | Longest message that can be read. |
block_read | Whether to read in blocks or one byte at a time. |
Definition at line 35 of file fd_reader.cpp.
|
protectedvirtual |
Read the next block of data up to block_size bytes.
json_io_error | if the read failed for some reason other than EOF. |
Implements argo::reader.
Definition at line 63 of file fd_reader.cpp.
|
protectedvirtual |
Read a character from the file descriptor using the read() system call.
json_io_exception | Thrown in the event the read() call fails. |
Implements argo::reader.
Definition at line 41 of file fd_reader.cpp.