Panda3D

Public Member Functions | List of all members
DCPackData Class Reference

This is a block of data that receives the results of DCPacker. More...

`#include "dcPackData.h"`

## Public Member Functions
void | append_data (const char *buffer, size_t size)
| Adds the indicated bytes to the end of the data. More...
void | append_junk (size_t size)
| Adds some uninitialized bytes to the end of the data. More...
void | clear ()
| Empties the contents of the data (without necessarily freeing its allocated memory). More...
const char * | get_data () const
| Returns the beginning of the data buffer. More...
size_t | get_length () const
| Returns the current length of the buffer. More...
char * | get_rewrite_pointer (size_t position, size_t size)
| Returns a pointer into the middle of the data at the indicated point. More...
std::string | get_string () const
| Returns the data buffer as a string. More...
char * | get_write_pointer (size_t size)
| Adds the indicated number of bytes to the end of the data without initializing them, and returns a pointer to the beginning of the new data. More...
void | rewrite_data (size_t position, const char *buffer, size_t size)
| Changes the data at the indicated position to the given value. More...
char * | take_data ()
| Returns the pointer to the beginning of the data buffer, and transfers ownership of the buffer to the caller. More...

## Detailed Description

This is a block of data that receives the results of DCPacker.

Definition at line 22 of file dcPackData.h.

## Member Function Documentation

## ◆ append_data()

void DCPackData::append_data | ( | const char * | buffer,
|  | size_t | size
| ) |  |
| inline

Adds the indicated bytes to the end of the data.

Definition at line 46 of file dcPackData.I.

Referenced by DCField::pack_default_value().

## ◆ append_junk()

void DCPackData::append_junk | ( | size_t | size | ) |
| inline

Adds some uninitialized bytes to the end of the data.

Definition at line 65 of file dcPackData.I.

Referenced by DCPacker::push().

## ◆ clear()

void DCPackData::clear | ( |  | ) |
| inline

Empties the contents of the data (without necessarily freeing its allocated memory).

Definition at line 38 of file dcPackData.I.

## ◆ get_data()

const char * DCPackData::get_data | ( |  | ) | const
| inline

Returns the beginning of the data buffer.

The buffer is not null- terminated, but see also get_string(). This may (or may not) return NULL if the buffer is empty.

This may be used in conjunction with get_length() to copy all of the bytes out of the buffer.

Definition at line 114 of file dcPackData.I.

## ◆ get_length()

size_t DCPackData::get_length | ( |  | ) | const
| inline

Returns the current length of the buffer.

This is the number of useful bytes stored in the buffer, not the amount of memory it takes up.

Definition at line 101 of file dcPackData.I.

Referenced by DCPacker::pop(), and DCPacker::push().

## ◆ get_rewrite_pointer()

char * DCPackData::get_rewrite_pointer | ( | size_t | position,
|  | size_t | size
| ) |  |
| inline

Returns a pointer into the middle of the data at the indicated point.

Definition at line 83 of file dcPackData.I.

Referenced by DCPacker::pop().

## ◆ get_string()

std::string DCPackData::get_string | ( |  | ) | const
| inline

Returns the data buffer as a string.

Also see get_data().

Definition at line 92 of file dcPackData.I.

## ◆ get_write_pointer()

char * DCPackData::get_write_pointer | ( | size_t | size | ) |
| inline

Adds the indicated number of bytes to the end of the data without initializing them, and returns a pointer to the beginning of the new data.

Definition at line 56 of file dcPackData.I.

## ◆ rewrite_data()

void DCPackData::rewrite_data | ( | size_t | position,
|  | const char * | buffer,
|  | size_t | size
| ) |  |
| inline

Changes the data at the indicated position to the given value.

It is an error if there are not at least position + size bytes in the data.

Definition at line 74 of file dcPackData.I.

## ◆ take_data()

char * DCPackData::take_data | ( |  | ) |
| inline

Returns the pointer to the beginning of the data buffer, and transfers ownership of the buffer to the caller.

The caller is now responsible for ultimately freeing the returned pointer with delete[], if it is non-NULL. This may (or may not) return NULL if the buffer is empty.

This also empties the DCPackData structure, and sets its length to zero (so you should call get_length() before calling this method).

Definition at line 128 of file dcPackData.I.

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

- direct/src/dcparser/dcPackData.h
- direct/src/dcparser/dcPackData.cxx
- direct/src/dcparser/dcPackData.I