libdap  Updated for version 3.20.6
libdap4 is an implementation of OPeNDAP's DAP protocol.
libdap::chunked_ostream Class Reference

A C++ stream class for chunked data. This class uses the chunked_outbuf class to provide for chunked binary serialization of data as specified by DAP4. Information to be serialized is broken into 'chunks' that are no more than 2^24 bytes in length. Each chunk is prefixed by a 4 byte header that indicates the type of chunk and size (number of bytes in the chunk body). There are three types of chunk: Data; End; and Error. In normal operation, a DAP4 data document/response is serialized as a sequence of DATA chunks followed by one END chunk (which may be zero bytes in length). If, during serialization, an error is detected, the currently buffered (but not sent) data are discarded and an ERROR chunk is sent with an error message. More...

#include <chunked_ostream.h>

Inheritance diagram for libdap::chunked_ostream:
Inheritance graph

Public Member Functions

 chunked_ostream (std::ostream &os, unsigned int buf_size)
 
int_type write_data_chunk ()
 Send the current contents of the buffer as a data chunk. Normally, the chunked_ostream object waits until the buffer is full before sending the next data chunk. This will force a send with whatever is in the buffer (e.g., the DMR text). Data added after this call will be sent in subsequent chunks. More...
 
int_type write_end_chunk ()
 Send an end chunk. Normally, an end chunk is sent by closing the chunked_ostream, but this method can be used to force sending it without closing the stream. Subsequent calls to send data will send data chunks. More...
 
int_type write_err_chunk (const std::string &msg)
 Send an error message down the stream. When called, this method dumps all the data currently in the buffer and sends the error message text instead, using a chunk type of CHUNK_ERR. The write buffer is maintained, however, so the stream ibject can still be used. More...
 

Protected Attributes

chunked_outbuf d_cbuf
 

Detailed Description

A C++ stream class for chunked data. This class uses the chunked_outbuf class to provide for chunked binary serialization of data as specified by DAP4. Information to be serialized is broken into 'chunks' that are no more than 2^24 bytes in length. Each chunk is prefixed by a 4 byte header that indicates the type of chunk and size (number of bytes in the chunk body). There are three types of chunk: Data; End; and Error. In normal operation, a DAP4 data document/response is serialized as a sequence of DATA chunks followed by one END chunk (which may be zero bytes in length). If, during serialization, an error is detected, the currently buffered (but not sent) data are discarded and an ERROR chunk is sent with an error message.

This class sends the END chunk when its destructor is called.

Calling flush() on the ostream object will force a DATA chunk to be sent with the currently buffered data. Normal operation is to wait for the buffer to fill before sending a DATA chunk.

See also
chunked_outbuf

Definition at line 120 of file chunked_ostream.h.

Constructor & Destructor Documentation

◆ chunked_ostream()

libdap::chunked_ostream::chunked_ostream ( std::ostream &  os,
unsigned int  buf_size 
)
inline

Get a chunked_ostream with a buffer.

Note
The buffer size must not be more than 2^24 bytes (0x00ffffff)
Parameters
buf_sizeThe size of the buffer in bytes.

Definition at line 129 of file chunked_ostream.h.

Member Function Documentation

◆ write_data_chunk()

int_type libdap::chunked_ostream::write_data_chunk ( )
inline

Send the current contents of the buffer as a data chunk. Normally, the chunked_ostream object waits until the buffer is full before sending the next data chunk. This will force a send with whatever is in the buffer (e.g., the DMR text). Data added after this call will be sent in subsequent chunks.

Note
Calling flush() on the stream forces a data chunk to be sent.
Returns
EOF on error, otherwise the number of bytes sent in the chunk body.

Definition at line 149 of file chunked_ostream.h.

◆ write_end_chunk()

int_type libdap::chunked_ostream::write_end_chunk ( )
inline

Send an end chunk. Normally, an end chunk is sent by closing the chunked_ostream, but this method can be used to force sending it without closing the stream. Subsequent calls to send data will send data chunks.

Note
An end chunk is sent when the stream is closed.
Returns
EOF on error or the number of bytes sent in the chunk body.

Definition at line 139 of file chunked_ostream.h.

◆ write_err_chunk()

int_type libdap::chunked_ostream::write_err_chunk ( const std::string &  msg)
inline

Send an error message down the stream. When called, this method dumps all the data currently in the buffer and sends the error message text instead, using a chunk type of CHUNK_ERR. The write buffer is maintained, however, so the stream ibject can still be used.

Parameters
msgThe error message text
Returns
The number of bytes 'dumped' from the write buffer.

Definition at line 159 of file chunked_ostream.h.


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