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

output buffer for a chunked stream This performs buffered output encoding the data in the stream using the simple chunking protocol defined for DAP4's binary data transmission. Each block of data is prefixed by four bytes: A CHUNK TYPE byte followed by three bytes that are the CHUNK SIZE. There are three CHUNK TYPES: data, end and error, indicated by the code values 0x00, 0x01 and 0x02. The size of a chunk is limited to 2^24 data bytes + 4 bytes for the chunk header. More...

#include <chunked_ostream.h>

Inheritance diagram for libdap::chunked_outbuf:
Inheritance graph

Public Member Functions

 chunked_outbuf (std::ostream &os, unsigned int buf_size)
 

Protected Member Functions

int_type data_chunk ()
 Write out the contents of the buffer as a chunk. More...
 
int_type end_chunk ()
 Send an end chunk. More...
 
int_type err_chunk (const std::string &msg)
 Send an error chunk While building up the next chunk, send an error chunk, ignoring the data currently write buffer. The buffer is left in a consistent state. More...
 
virtual int_type overflow (int c)
 Virtual method called when the internal buffer would overflow. When the internal buffer fills, this method is called by the byte that would cause that overflow. The buffer pointers have been set so that there is actually space for one more character, so c can really be sent. Put c into the buffer and send it, prefixing the buffer contents with a chunk header. More...
 
virtual int_type sync ()
 Synchronize the stream with its data sink. More...
 
virtual std::streamsize xsputn (const char *s, std::streamsize num)
 Write bytes to the chunked stream Write the bytes in s to the chunked stream. More...
 

Protected Attributes

bool d_big_endian
 
unsigned int d_buf_size
 
char * d_buffer
 
std::ostream & d_os
 

Friends

class chunked_ostream
 

Detailed Description

output buffer for a chunked stream This performs buffered output encoding the data in the stream using the simple chunking protocol defined for DAP4's binary data transmission. Each block of data is prefixed by four bytes: A CHUNK TYPE byte followed by three bytes that are the CHUNK SIZE. There are three CHUNK TYPES: data, end and error, indicated by the code values 0x00, 0x01 and 0x02. The size of a chunk is limited to 2^24 data bytes + 4 bytes for the chunk header.

Definition at line 53 of file chunked_ostream.h.

Member Function Documentation

◆ data_chunk()

std::streambuf::int_type libdap::chunked_outbuf::data_chunk ( )
protected

Write out the contents of the buffer as a chunk.

Returns
EOF on error, otherwise the number of bytes in the chunk body.

Definition at line 54 of file chunked_ostream.cc.

◆ end_chunk()

std::streambuf::int_type libdap::chunked_outbuf::end_chunk ( )
protected

Send an end chunk.

This is like calling flush_chunk(), but it sends a chunk header with a type of CHUNK_END (instead of CHUNK_DATA). Whatever is in the buffer is written out, but the stream is can be used to send more chunks.

Note
This is called by the chunked_outbuf destructor, so closing a stream using chunked_outbuf always sends a CHUNK_END type chunk, even if it will have zero bytes
Returns
EOF on error, otherwise the number of bytes sent in the chunk.

Definition at line 108 of file chunked_ostream.cc.

◆ err_chunk()

std::streambuf::int_type libdap::chunked_outbuf::err_chunk ( const std::string &  m)
protected

Send an error chunk While building up the next chunk, send an error chunk, ignoring the data currently write buffer. The buffer is left in a consistent state.

Parameters
msgThe error message to include in the error chunk
Returns
The number of characters ignored.

Definition at line 150 of file chunked_ostream.cc.

◆ overflow()

std::streambuf::int_type libdap::chunked_outbuf::overflow ( int  c)
protectedvirtual

Virtual method called when the internal buffer would overflow. When the internal buffer fills, this method is called by the byte that would cause that overflow. The buffer pointers have been set so that there is actually space for one more character, so c can really be sent. Put c into the buffer and send it, prefixing the buffer contents with a chunk header.

Note
This method is called by the std::ostream code.
Parameters
cThe last character to add to the buffer before sending the next chunk.
Returns
EOF on error, otherwise the value of c.

Definition at line 205 of file chunked_ostream.cc.

◆ sync()

std::streambuf::int_type libdap::chunked_outbuf::sync ( )
protectedvirtual

Synchronize the stream with its data sink.

Note
This method is called by flush() among others
Returns
-1 on error, 0 otherwise.

Definition at line 329 of file chunked_ostream.cc.

◆ xsputn()

std::streamsize libdap::chunked_outbuf::xsputn ( const char *  s,
std::streamsize  num 
)
protectedvirtual

Write bytes to the chunked stream Write the bytes in s to the chunked stream.

Parameters
s
num
Returns
The number of bytes written

Definition at line 247 of file chunked_ostream.cc.


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