Panda3D
Public Member Functions | Public Attributes | List of all members
DatagramBuffer Class Reference

This class can be used to write a series of datagrams into a memory buffer. More...

#include "datagramBuffer.h"

Inheritance diagram for DatagramBuffer:
DatagramSink DatagramGenerator

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 FileReferenceget_file ()
 
virtual std::streampos get_file_pos ()
 
virtual const Filenameget_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 FileReferenceget_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 Filenameget_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 VirtualFileget_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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DatagramBuffer() [1/2]

DatagramBuffer::DatagramBuffer ( )
inline

Initializes an empty datagram buffer.

Definition at line 18 of file datagramBuffer.I.

◆ DatagramBuffer() [2/2]

DatagramBuffer::DatagramBuffer ( vector_uchar  data)
inlineexplicit

Initializes the buffer with the given data.

Definition at line 28 of file datagramBuffer.I.

Member Function Documentation

◆ clear()

void DatagramBuffer::clear ( )
inline

Clears the internal buffer.

Definition at line 39 of file datagramBuffer.I.

◆ flush()

void DatagramBuffer::flush ( void  )
overridevirtual

This does absolutely nothing.

Implements DatagramSink.

Definition at line 71 of file datagramBuffer.cxx.

◆ get_datagram()

bool DatagramBuffer::get_datagram ( Datagram data)
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.

◆ is_eof()

bool DatagramBuffer::is_eof ( )
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.

◆ is_error()

bool DatagramBuffer::is_error ( )
overridevirtual

Returns true if the buffer has reached an error condition.

Implements DatagramGenerator.

Definition at line 150 of file datagramBuffer.cxx.

◆ put_datagram()

bool DatagramBuffer::put_datagram ( const Datagram data)
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.

◆ read_header()

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.

◆ swap_data()

void DatagramBuffer::swap_data ( vector_uchar &  other)
inline

Swaps the data in the internal buffer with that of the other buffer.

Definition at line 66 of file datagramBuffer.I.

◆ write_header()

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.

Member Data Documentation

◆ get_data

const vector_uchar & DatagramBuffer::get_data
inline

Returns the internal buffer.

Definition at line 53 of file datagramBuffer.h.

◆ set_data

void DatagramBuffer::set_data
inline

Replaces the data in the internal buffer.

Definition at line 53 of file datagramBuffer.h.


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