libdap  Updated for version 3.20.6
libdap4 is an implementation of OPeNDAP's DAP protocol.
libdap::chunked_inbuf Class Reference
Inheritance diagram for libdap::chunked_inbuf:
Inheritance graph

Public Member Functions

int bytes_in_buffer () const
 
 chunked_inbuf (std::istream &is, int size)
 Build a chunked input buffer. More...
 
bool error () const
 
std::string error_message () const
 
int_type read_next_chunk ()
 Read a chunk Normally the chunked nature of a chunked_istream/chunked_inbuf is hidden from the caller. This method provides a way to get one chunk from the stream by forcing its read and returning the size. A subsequent call to read() for that number of bytes will return all of the data in the chunk. If there is any data in the chunk_inbuf object's buffer, it is lost. More...
 
bool twiddle_bytes () const
 

Protected Member Functions

virtual int_type underflow ()
 Insert new characters into the buffer This specialization of underflow is called when the gptr() is advanced to the end of the input buffer. At that point it calls the underlying I/O stream to read the next chunk of data and transfers the data read to the internal buffer. If an error is found, EOF is returned. If an END chunk with zero bytes is found, an EOF is returned. More...
 
virtual std::streamsize xsgetn (char *s, std::streamsize num)
 Read a block of data This specialization of xsgetn() reads num bytes and puts them in s first reading from the internal beffer and then from the stream. Any characters read from the last chunk that won't fit in to s are put in the buffer, otherwise all data are read directly into s, bypassing the internal buffer (and the extra copy operation that would imply). If the END chunk is found EOF is not returned and the final read of the underlying stream is not made; the next call to read(), get(), ..., will return EOF. More...
 

Detailed Description

Definition at line 42 of file chunked_istream.h.

Constructor & Destructor Documentation

◆ chunked_inbuf()

libdap::chunked_inbuf::chunked_inbuf ( std::istream &  is,
int  size 
)
inline

Build a chunked input buffer.

This reads from a chunked stream, extracting an entire chunk and storing it in a buffer in one operation. If the chunked_inbuf reads a chunk header that indicates the next chunk is going be bigger than its current buffer size, the object will make the buffer larger. This object support 128 characters of 'put back' space. Since DAP4 uses receiver makes right, the buffer must be told if it should 'twiddle' the header size information. In DAP4 the byte order is sent using a one-byte code before the chunked transmission starts.

Note
In the current implementation, the byte order of the sender is read from the first chunk header. The method twiddle_bytes() returns false until the first chunk is read, then it returns the correct value. Only the first chunk_header is tested for the byte order flag; all subsequent chunks are assumed to use the same byte order.
Parameters
isUse this as a data source
sizeThe size of the input buffer. This should match the likely chunk size. If it is smaller than a chunk, it will be resized.
twiddle_bytesShould the header bytes be twiddled? True if this host and the send use a different byte-order. The sender's byte order must be sent out-of-band.

Definition at line 98 of file chunked_istream.h.

Member Function Documentation

◆ read_next_chunk()

std::streambuf::int_type libdap::chunked_inbuf::read_next_chunk ( )

Read a chunk Normally the chunked nature of a chunked_istream/chunked_inbuf is hidden from the caller. This method provides a way to get one chunk from the stream by forcing its read and returning the size. A subsequent call to read() for that number of bytes will return all of the data in the chunk. If there is any data in the chunk_inbuf object's buffer, it is lost.

Returns
The number of bytes read, which is exactly the size of the next chunk in the stream. Returns EOF on error.

Definition at line 333 of file chunked_istream.cc.

◆ underflow()

std::streambuf::int_type libdap::chunked_inbuf::underflow ( )
protectedvirtual

Insert new characters into the buffer This specialization of underflow is called when the gptr() is advanced to the end of the input buffer. At that point it calls the underlying I/O stream to read the next chunk of data and transfers the data read to the internal buffer. If an error is found, EOF is returned. If an END chunk with zero bytes is found, an EOF is returned.

Returns
The character at the gptr() or EOF

Definition at line 84 of file chunked_istream.cc.

◆ xsgetn()

std::streamsize libdap::chunked_inbuf::xsgetn ( char *  s,
std::streamsize  num 
)
protectedvirtual

Read a block of data This specialization of xsgetn() reads num bytes and puts them in s first reading from the internal beffer and then from the stream. Any characters read from the last chunk that won't fit in to s are put in the buffer, otherwise all data are read directly into s, bypassing the internal buffer (and the extra copy operation that would imply). If the END chunk is found EOF is not returned and the final read of the underlying stream is not made; the next call to read(), get(), ..., will return EOF.

Parameters
sAddress of a buffer to hold the data
numNumber of bytes to read
Returns
NUmber of bytes actually transferred into s. Note that this number does not include the bytes read from the last chunk that won't fit into s so this will never return a number greater than num.

Definition at line 179 of file chunked_istream.cc.


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