Panda3D

Loading...
Searching...
No Matches
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:

## Public Member Functions
| DatagramBuffer ()
| Initializes an empty datagram buffer.
| DatagramBuffer (vector_uchar data)
| Initializes the buffer with the given data.
void | clear ()
| Clears the internal buffer.
virtual void | flush () override
| This does absolutely nothing.
const vector_uchar & | get_data () const
virtual bool | get_datagram (Datagram &data) override
| Reads the next datagram from the file.
virtual bool | is_eof () override
| Returns true if the buffer has reached the end-of-buffer.
virtual bool | is_error () override
| Returns true if the buffer has reached an error condition.
virtual bool | put_datagram (const Datagram &data) override
| Writes the given datagram to the file.
bool | read_header (std::string &header, size_t num_bytes)
| Reads a sequence of bytes from the beginning of the datagram file.
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.
bool | write_header (const std::string &header)
| Writes a sequence of bytes to the beginning of the datagram file.
Public Member Functions inherited from DatagramSink
| DatagramSink ()
| Does nothing since this is class is just the definition of an interface.
virtual | ~DatagramSink ()
| Does nothing since this is class is just the definition of an interface.
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.
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.
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.
virtual | ~DatagramGenerator ()
| Does nothing since this is class is just the definition of an interface.
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.
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.
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.
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.
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.
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.

## Public Attributes
| get_data
| Returns the internal buffer.
| set_data
| Replaces the data in the internal buffer.
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.
| 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.
| 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.

## 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 17 of file datagramBuffer.I.

## ◆ DatagramBuffer() [2/2]

DatagramBuffer::DatagramBuffer | ( | vector_uchar | data | ) |
| inline explicit

Initializes the buffer with the given data.

Definition at line 27 of file datagramBuffer.I.

## Member Function Documentation

## ◆ clear()

void DatagramBuffer::clear | ( |  | ) |
| inline

Clears the internal buffer.

Definition at line 38 of file datagramBuffer.I.

## ◆ flush()

void DatagramBuffer::flush | ( |  | ) |
| override virtual

This does absolutely nothing.

Implements DatagramSink.

Definition at line 70 of file datagramBuffer.cxx.

## ◆ get_datagram()

bool DatagramBuffer::get_datagram | ( | Datagram & | data | ) |
| override virtual

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 96 of file datagramBuffer.cxx.

References NativeNumericData::store_value().

Referenced by NodePath::decode_from_bam_stream().

## ◆ is_eof()

bool DatagramBuffer::is_eof | ( |  | ) |
| override virtual

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 141 of file datagramBuffer.cxx.

## ◆ is_error()

bool DatagramBuffer::is_error | ( |  | ) |
| override virtual

Returns true if the buffer has reached an error condition.

Implements DatagramSink.

Definition at line 149 of file datagramBuffer.cxx.

## ◆ put_datagram()

bool DatagramBuffer::put_datagram | ( | const Datagram & | data | ) |
| override virtual

Writes the given datagram to the file.

Returns true on success, false if there is an error.

Implements DatagramSink.

Definition at line 34 of file datagramBuffer.cxx.

References NativeNumericData::get_data().

Referenced by NodePath::encode_to_bam_stream().

## ◆ 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 80 of file datagramBuffer.cxx.

Referenced by NodePath::decode_from_bam_stream(), and TypedWritable::decode_raw_from_bam_stream().

## ◆ 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 65 of file datagramBuffer.I.

Referenced by NodePath::encode_to_bam_stream(), and TypedWritable::encode_to_bam_stream().

## ◆ 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 22 of file datagramBuffer.cxx.

Referenced by NodePath::encode_to_bam_stream(), and TypedWritable::encode_to_bam_stream().

## 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:

- panda/src/putil/datagramBuffer.h
- panda/src/putil/datagramBuffer.cxx
- panda/src/putil/datagramBuffer.I