This class can be used to write a series of datagrams into a memory buffer. More...
#include "datagramBuffer.h"
Public Member Functions | |
DatagramBuffer () | |
Initializes an empty datagram buffer. More... | |
DatagramBuffer (vector_uchar data) | |
Initializes the buffer with the given data. More... | |
void | clear () |
Clears the internal buffer. More... | |
virtual void | flush () override |
This does absolutely nothing. More... | |
const vector_uchar & | get_data () const |
virtual bool | get_datagram (Datagram &data) override |
Reads the next datagram from the file. More... | |
virtual bool | is_eof () override |
Returns true if the buffer has reached the end-of-buffer. More... | |
virtual bool | is_error () override |
Returns true if the buffer has reached an error condition. More... | |
virtual bool | put_datagram (const Datagram &data) override |
Writes the given datagram to the file. More... | |
bool | read_header (std::string &header, size_t num_bytes) |
Reads a sequence of bytes from the beginning of the datagram file. More... | |
void | set_data (vector_uchar data) |
void | swap_data (vector_uchar &other) |
Swaps the data in the internal buffer with that of the other buffer. More... | |
bool | write_header (const std::string &header) |
Writes a sequence of bytes to the beginning of the datagram file. More... | |
Public Member Functions inherited from DatagramSink | |
DatagramSink () | |
Does nothing since this is class is just the definition of an interface. More... | |
virtual | ~DatagramSink () |
Does nothing since this is class is just the definition of an interface. More... | |
virtual bool | copy_datagram (SubfileInfo &result, const Filename &filename) |
Copies the file data from the entire indicated file (via the vfs) as the next datagram. More... | |
virtual bool | copy_datagram (SubfileInfo &result, const SubfileInfo &source) |
Copies the file data from the range of the indicated file (outside of the vfs) as the next datagram. More... | |
virtual const FileReference * | get_file () |
virtual std::streampos | get_file_pos () |
virtual const Filename & | get_filename () |
Public Member Functions inherited from DatagramGenerator | |
DatagramGenerator () | |
Does nothing since this is class is just the definition of an interface. More... | |
virtual | ~DatagramGenerator () |
Does nothing since this is class is just the definition of an interface. More... | |
virtual const FileReference * | get_file () |
Returns the FileReference that provides the source for these datagrams, if any, or NULL if the datagrams do not originate from a file on disk. More... | |
virtual std::streampos | get_file_pos () |
Returns the current file position within the data stream, if any, or 0 if the file position is not meaningful or cannot be determined. More... | |
virtual const Filename & | get_filename () |
Returns the filename that provides the source for these datagrams, if any, or empty string if the datagrams do not originate from a file on disk. More... | |
virtual time_t | get_timestamp () const |
Returns the on-disk timestamp of the file that was read, at the time it was opened, if that is available, or 0 if it is not. More... | |
virtual VirtualFile * | get_vfile () |
Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagrams do not originate from a VirtualFile. More... | |
virtual bool | save_datagram (SubfileInfo &info) |
Skips over the next datagram without extracting it, but saves the relevant file information in the SubfileInfo object so that its data may be read later. More... | |
Public Attributes | |
get_data | |
Returns the internal buffer. More... | |
set_data | |
Replaces the data in the internal buffer. More... | |
Public Attributes inherited from DatagramSink | |
get_file | |
Returns the FileReference that provides the target for these datagrams, if any, or NULL if the datagrams do not written to a file on disk. More... | |
get_file_pos | |
Returns the current file position within the data stream, if any, or 0 if the file position is not meaningful or cannot be determined. More... | |
get_filename | |
Returns the filename that provides the target for these datagrams, if any, or empty string if the datagrams do not get written to a file on disk. More... | |
This class can be used to write a series of datagrams into a memory buffer.
It acts as both a datagram sink and generator; you can fill it up with datagrams and then read as many datagrams from it.
This uses the same format as DatagramInputFile and DatagramOutputFile, meaning that Datagram sizes are always stored little-endian.
Definition at line 30 of file datagramBuffer.h.
|
inline |
Initializes an empty datagram buffer.
Definition at line 18 of file datagramBuffer.I.
|
inlineexplicit |
Initializes the buffer with the given data.
Definition at line 28 of file datagramBuffer.I.
|
inline |
Clears the internal buffer.
Definition at line 39 of file datagramBuffer.I.
|
overridevirtual |
This does absolutely nothing.
Implements DatagramSink.
Definition at line 71 of file datagramBuffer.cxx.
|
overridevirtual |
Reads the next datagram from the file.
Returns true on success, false if there is an error or end of file.
Implements DatagramGenerator.
Definition at line 97 of file datagramBuffer.cxx.
|
overridevirtual |
Returns true if the buffer has reached the end-of-buffer.
This test may only be made after a call to read_header() or get_datagram() has failed.
Implements DatagramGenerator.
Definition at line 142 of file datagramBuffer.cxx.
|
overridevirtual |
Returns true if the buffer has reached an error condition.
Implements DatagramGenerator.
Definition at line 150 of file datagramBuffer.cxx.
|
overridevirtual |
Writes the given datagram to the file.
Returns true on success, false if there is an error.
Implements DatagramSink.
Definition at line 35 of file datagramBuffer.cxx.
bool DatagramBuffer::read_header | ( | std::string & | header, |
size_t | num_bytes | ||
) |
Reads a sequence of bytes from the beginning of the datagram file.
This may be called any number of times after the file has been opened and before the first datagram is read. It may not be called once the first datagram has been read.
Definition at line 81 of file datagramBuffer.cxx.
|
inline |
Swaps the data in the internal buffer with that of the other buffer.
Definition at line 66 of file datagramBuffer.I.
bool DatagramBuffer::write_header | ( | const std::string & | header | ) |
Writes a sequence of bytes to the beginning of the datagram file.
This may be called any number of times after the file has been opened and before the first datagram is written. It may not be called once the first datagram is written.
Definition at line 23 of file datagramBuffer.cxx.
|
inline |
Returns the internal buffer.
Definition at line 53 of file datagramBuffer.h.
|
inline |
Replaces the data in the internal buffer.
Definition at line 53 of file datagramBuffer.h.