Panda3D
Classes | Public Member Functions | Static Public Member Functions | List of all members
DCPacker Class Reference

This class can be used for packing a series of numeric and string data into a binary stream, according to the DC specification. More...

#include "dcPacker.h"

Public Member Functions

void append_data (const unsigned char *buffer, size_t size)
 Adds the indicated bytes to the end of the data. More...
 
void begin_pack (const DCPackerInterface *root)
 Begins a packing session. More...
 
void begin_repack (const DCPackerInterface *root)
 Begins a repacking session. More...
 
void begin_unpack (const DCPackerInterface *root)
 Begins an unpacking session. More...
 
void clear_data ()
 Empties the data in the pack buffer and unpack buffer. More...
 
bool end_pack ()
 Finishes a packing session. More...
 
bool end_repack ()
 Finishes the repacking session. More...
 
bool end_unpack ()
 Finishes the unpacking session. More...
 
vector_uchar get_bytes () const
 Returns the packed data buffer as a bytes object. More...
 
const DCPackerInterfaceget_current_field () const
 Returns the field that will be referenced by the next call to pack_*() or unpack_*(). More...
 
std::string get_current_field_name () const
 Returns the name of the current field, if it has a name, or the empty string if the field does not have a name or there is no current field. More...
 
const DCPackerInterfaceget_current_parent () const
 Returns the field that we left in our last call to push(): the owner of the current level of fields. More...
 
const char * get_data () const
 Returns the beginning of the data buffer. More...
 
const DCSwitchParameterget_last_switch () const
 Returns a pointer to the last DCSwitch instance that we have passed by and selected one case of during the pack/unpack process. More...
 
size_t get_length () const
 Returns the current length of the buffer. More...
 
int get_num_nested_fields () const
 Returns the number of nested fields associated with the current field, if has_nested_fields() returned true. More...
 
size_t get_num_unpacked_bytes () const
 Returns the number of bytes that have been unpacked so far, or after unpack_end(), the total number of bytes that were unpacked at all. More...
 
DCPackType get_pack_type () const
 Returns the type of value expected by the current field. More...
 
std::string get_string () const
 Returns the packed data buffer as a string. More...
 
void get_string (std::string &data) const
 Copies the packed data into the indicated string. More...
 
const char * get_unpack_data () const
 Returns a read pointer to the unpack data buffer. More...
 
size_t get_unpack_length () const
 Returns the total number of bytes in the unpack data buffer. More...
 
std::string get_unpack_string () const
 Returns the unpack 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...
 
bool had_error () const
 Returns true if there has been any error (either a pack error or a range error) since the most recent call to begin(). More...
 
bool had_pack_error () const
 Returns true if there has been an packing error since the most recent call to begin(); in particular, this may be called after end() has returned false to determine the nature of the failure. More...
 
bool had_parse_error () const
 Returns true if there has been an parse error since the most recent call to begin(); this can only happen if you call parse_and_pack(). More...
 
bool had_range_error () const
 Returns true if there has been an range validation error since the most recent call to begin(); in particular, this may be called after end() has returned false to determine the nature of the failure. More...
 
bool has_nested_fields () const
 Returns true if the current field has any nested fields (and thus expects a push() . More...
 
bool more_nested_fields () const
 Returns true if there are more nested fields to pack or unpack in the current push sequence, false if it is time to call pop(). More...
 
void pack_blob (const vector_uchar &value)
 Packs the indicated numeric or string value into the stream. More...
 
void pack_default_value ()
 Adds the default value for the current element into the stream. More...
 
void pack_double (double value)
 Packs the indicated numeric or string value into the stream. More...
 
void pack_int (int value)
 Packs the indicated numeric or string value into the stream. More...
 
void pack_int64 (int64_t value)
 Packs the indicated numeric or string value into the stream. More...
 
void pack_literal_value (const vector_uchar &value)
 Adds the indicated string value into the stream, representing a single pre- packed field element, or a whole group of field elements at once. More...
 
void pack_string (const std::string &value)
 Packs the indicated numeric or string value into the stream. More...
 
void pack_uint (unsigned int value)
 Packs the indicated numeric or string value into the stream. More...
 
void pack_uint64 (uint64_t value)
 Packs the indicated numeric or string value into the stream. More...
 
bool parse_and_pack (const std::string &formatted_object)
 Parses an object's value according to the DC file syntax (e.g. More...
 
bool parse_and_pack (std::istream &in)
 Parses an object's value according to the DC file syntax (e.g. More...
 
void pop ()
 Marks the end of a nested series of fields. More...
 
void push ()
 Marks the beginning of a nested series of fields. More...
 
void raw_pack_blob (const vector_uchar &value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_float64 (double value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_int16 (int value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_int32 (int value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_int64 (int64_t value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_int8 (int value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_string (const std::string &value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_uint16 (unsigned int value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_uint32 (unsigned int value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_uint64 (uint64_t value)
 Packs the data into the buffer between packing sessions. More...
 
void raw_pack_uint8 (unsigned int value)
 Packs the data into the buffer between packing sessions. More...
 
vector_uchar raw_unpack_blob ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_blob (vector_uchar &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
double raw_unpack_float64 ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_float64 (double &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
int raw_unpack_int16 ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_int16 (int &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
int raw_unpack_int32 ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_int32 (int &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
int64_t raw_unpack_int64 ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_int64 (int64_t &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
int raw_unpack_int8 ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_int8 (int &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
std::string raw_unpack_string ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_string (std::string &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
unsigned int raw_unpack_uint16 ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_uint16 (unsigned int &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
unsigned int raw_unpack_uint32 ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_uint32 (unsigned int &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
uint64_t raw_unpack_uint64 ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_uint64 (uint64_t &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
unsigned int raw_unpack_uint8 ()
 Unpacks the data from the buffer between unpacking sessions. More...
 
void raw_unpack_uint8 (unsigned int &value)
 Unpacks the data from the buffer between unpacking sessions. More...
 
bool seek (const std::string &field_name)
 Sets the current unpack (or repack) position to the named field. More...
 
bool seek (int seek_index)
 Seeks to the field indentified by seek_index, which was returned by an earlier call to DCField::find_seek_index() to get the index of some nested field. More...
 
void set_unpack_data (const vector_uchar &data)
 Sets up the unpack_data pointer. More...
 
void set_unpack_data (const char *unpack_data, size_t unpack_length, bool owns_unpack_data)
 Sets up the unpack_data pointer. More...
 
char * take_data ()
 Returns the pointer to the beginning of the data buffer, and transfers ownership of the buffer to the caller. More...
 
std::string unpack_and_format (bool show_field_names=true)
 Unpacks an object and formats its value into a syntax suitable for parsing in the dc file (e.g. More...
 
void unpack_and_format (std::ostream &out, bool show_field_names=true)
 Unpacks an object and formats its value into a syntax suitable for parsing in the dc file (e.g. More...
 
vector_uchar unpack_blob ()
 Unpacks the current binary data value from the stream. More...
 
void unpack_blob (vector_uchar &value)
 Unpacks the current numeric or string value from the stream. More...
 
double unpack_double ()
 Unpacks the current numeric or string value from the stream. More...
 
void unpack_double (double &value)
 Unpacks the current numeric or string value from the stream. More...
 
int unpack_int ()
 Unpacks the current numeric or string value from the stream. More...
 
void unpack_int (int &value)
 Unpacks the current numeric or string value from the stream. More...
 
int64_t unpack_int64 ()
 Unpacks the current numeric or string value from the stream. More...
 
void unpack_int64 (int64_t &value)
 Unpacks the current numeric or string value from the stream. More...
 
vector_uchar unpack_literal_value ()
 Returns the literal string that represents the packed value of the current field, and advances the field pointer. More...
 
void unpack_literal_value (vector_uchar &value)
 Returns the literal string that represents the packed value of the current field, and advances the field pointer. More...
 
void unpack_skip ()
 Skips the current field without unpacking it and advances to the next field. More...
 
std::string unpack_string ()
 Unpacks the current numeric or string value from the stream. More...
 
void unpack_string (std::string &value)
 Unpacks the current numeric or string value from the stream. More...
 
unsigned int unpack_uint ()
 Unpacks the current numeric or string value from the stream. More...
 
void unpack_uint (unsigned int &value)
 Unpacks the current numeric or string value from the stream. More...
 
uint64_t unpack_uint64 ()
 Unpacks the current numeric or string value from the stream. More...
 
void unpack_uint64 (uint64_t &value)
 Unpacks the current numeric or string value from the stream. More...
 
void unpack_validate ()
 Internally unpacks the current numeric or string value and validates it against the type range limits, but does not return the value. More...
 

Static Public Member Functions

static void enquote_string (std::ostream &out, char quote_mark, const std::string &str)
 Outputs the indicated string within quotation marks. More...
 
static int get_num_stack_elements_ever_allocated ()
 Returns the number of DCPacker::StackElement pointers ever simultaneously allocated; these are now either in active use or have been recycled into the deleted DCPacker::StackElement pool to be used again. More...
 
static void output_hex_string (std::ostream &out, const vector_uchar &str)
 Outputs the indicated string as a hex constant. More...
 

Detailed Description

This class can be used for packing a series of numeric and string data into a binary stream, according to the DC specification.

See also direct/src/doc/dcPacker.txt for a more complete description and examples of using this class.

Definition at line 34 of file dcPacker.h.

Member Function Documentation

◆ append_data()

void DCPacker::append_data ( const unsigned char *  buffer,
size_t  size 
)
inline

Adds the indicated bytes to the end of the data.

This may only be called between packing sessions.

Definition at line 664 of file dcPacker.I.

◆ begin_pack()

void DCPacker::begin_pack ( const DCPackerInterface root)

Begins a packing session.

The parameter is the DC object that describes the packing format; it may be a DCParameter or DCField.

Unless you call clear_data() between sessions, multiple packing sessions will be concatenated together into the same buffer. If you wish to add bytes to the buffer between packing sessions, use append_data() or get_write_pointer().

Definition at line 73 of file dcPacker.cxx.

Referenced by DCArrayParameter::pack_default_value(), DCSimpleParameter::pack_default_value(), DCSwitch::pack_default_value(), and DCField::parse_string().

◆ begin_repack()

void DCPacker::begin_repack ( const DCPackerInterface root)

Begins a repacking session.

You must have previously called set_unpack_data() to specify a buffer to unpack.

Unlike begin_pack() or begin_unpack() you may not concatenate the results of multiple begin_repack() sessions in one buffer.

Also, unlike in packing or unpacking modes, you may not walk through the fields from beginning to end, or even pack two consecutive fields at once. Instead, you must call seek() for each field you wish to modify and pack only that one field; then call seek() again to modify another field.

Definition at line 213 of file dcPacker.cxx.

◆ begin_unpack()

void DCPacker::begin_unpack ( const DCPackerInterface root)

Begins an unpacking session.

You must have previously called set_unpack_data() to specify a buffer to unpack.

If there was data left in the buffer after a previous begin_unpack() .. end_unpack() session, the new session will resume from the current point. This method may be used, therefore, to unpack a sequence of objects from the same buffer.

Definition at line 153 of file dcPacker.cxx.

Referenced by DCField::format_data(), and DCField::validate_ranges().

◆ clear_data()

void DCPacker::clear_data ( )
inline

Empties the data in the pack buffer and unpack buffer.

This should be called between calls to begin_pack(), unless you want to concatenate all of the pack results together.

Definition at line 20 of file dcPacker.I.

References DCPackData::clear().

◆ end_pack()

bool DCPacker::end_pack ( )

Finishes a packing session.

The return value is true on success, or false if there has been some error during packing.

Definition at line 98 of file dcPacker.cxx.

Referenced by DCSwitch::pack_default_value(), and DCField::parse_string().

◆ end_repack()

bool DCPacker::end_repack ( )

Finishes the repacking session.

The return value is true on success, or false if there has been some error during repacking (or if all fields have not been repacked).

Definition at line 248 of file dcPacker.cxx.

◆ end_unpack()

bool DCPacker::end_unpack ( )

Finishes the unpacking session.

The return value is true on success, or false if there has been some error during unpacking (or if all fields have not been unpacked).

Definition at line 179 of file dcPacker.cxx.

Referenced by DCField::format_data(), and DCField::validate_ranges().

◆ enquote_string()

void DCPacker::enquote_string ( std::ostream &  out,
char  quote_mark,
const std::string &  str 
)
static

Outputs the indicated string within quotation marks.

Definition at line 1097 of file dcPacker.cxx.

◆ get_bytes()

vector_uchar DCPacker::get_bytes ( ) const
inline

Returns the packed data buffer as a bytes object.

Also see get_data().

Definition at line 599 of file dcPacker.I.

References DCPackData::get_data(), and DCPackData::get_length().

Referenced by DCField::parse_string().

◆ get_current_field()

const DCPackerInterface * DCPacker::get_current_field ( ) const
inline

Returns the field that will be referenced by the next call to pack_*() or unpack_*().

This will be NULL if we have unpacked (or packed) all fields, or if it is time to call pop().

Definition at line 87 of file dcPacker.I.

◆ get_current_field_name()

std::string DCPacker::get_current_field_name ( ) const
inline

Returns the name of the current field, if it has a name, or the empty string if the field does not have a name or there is no current field.

Definition at line 127 of file dcPacker.I.

References DCPackerInterface::get_name().

Referenced by unpack_and_format().

◆ get_current_parent()

const DCPackerInterface * DCPacker::get_current_parent ( ) const
inline

Returns the field that we left in our last call to push(): the owner of the current level of fields.

This may be NULL at the beginning of the pack operation.

Definition at line 77 of file dcPacker.I.

◆ get_data()

const char * DCPacker::get_data ( ) const
inline

Returns the beginning of the data buffer.

The buffer is not null- terminated, but see also get_string().

This may be used in conjunction with get_length() to copy all of the bytes out of the buffer. Also see take_data() to get the packed data without a copy operation.

Definition at line 641 of file dcPacker.I.

References DCPackData::get_data().

◆ get_last_switch()

const DCSwitchParameter * DCPacker::get_last_switch ( ) const
inline

Returns a pointer to the last DCSwitch instance that we have passed by and selected one case of during the pack/unpack process.

Each time we encounter a new DCSwitch and select a case, this will change state.

This may be used to detect when a DCSwitch has been selected. At the moment this changes state, get_current_parent() will contain the particular SwitchCase that was selected by the switch.

Definition at line 101 of file dcPacker.I.

◆ get_length()

size_t DCPacker::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 583 of file dcPacker.I.

References DCPackData::get_length().

◆ get_num_nested_fields()

int DCPacker::get_num_nested_fields ( ) const
inline

Returns the number of nested fields associated with the current field, if has_nested_fields() returned true.

The return value may be -1 to indicate that a variable number of nested fields are accepted by this field type (e.g. a variable-length array).

Note that this method is unreliable to determine how many fields you must traverse before you can call pop(), since particularly in the presence of a DCSwitch, it may change during traversal. Use more_nested_fields() instead.

Definition at line 58 of file dcPacker.I.

◆ get_num_stack_elements_ever_allocated()

int DCPacker::get_num_stack_elements_ever_allocated ( )
inlinestatic

Returns the number of DCPacker::StackElement pointers ever simultaneously allocated; these are now either in active use or have been recycled into the deleted DCPacker::StackElement pool to be used again.

Definition at line 696 of file dcPacker.I.

◆ get_num_unpacked_bytes()

size_t DCPacker::get_num_unpacked_bytes ( ) const
inline

Returns the number of bytes that have been unpacked so far, or after unpack_end(), the total number of bytes that were unpacked at all.

This can be used to validate that all of the bytes in the buffer were actually unpacked (which is not otherwise considered an error).

Definition at line 574 of file dcPacker.I.

Referenced by DCField::validate_ranges().

◆ get_pack_type()

DCPackType DCPacker::get_pack_type ( ) const
inline

Returns the type of value expected by the current field.

See the enumerated type definition at the top of DCPackerInterface.h. If this returns one of PT_double, PT_int, PT_int64, or PT_string, then you should call the corresponding pack_double(), pack_int() function (or unpack_double(), unpack_int(), etc.) to transfer data. Otherwise, you should call push() and begin packing or unpacking the nested fields.

Definition at line 114 of file dcPacker.I.

Referenced by unpack_and_format().

◆ get_string() [1/2]

std::string DCPacker::get_string ( ) const
inline

Returns the packed data buffer as a string.

Also see get_data().

Definition at line 591 of file dcPacker.I.

References DCPackData::get_string().

◆ get_string() [2/2]

void DCPacker::get_string ( std::string &  data) const
inline

Copies the packed data into the indicated string.

Also see get_data().

Definition at line 628 of file dcPacker.I.

◆ get_unpack_data()

const char * DCPacker::get_unpack_data ( ) const
inline

Returns a read pointer to the unpack data buffer.

This is the buffer used when unpacking; it is separate from the pack data returned by get_data(), which is filled during packing.

Definition at line 686 of file dcPacker.I.

◆ get_unpack_length()

size_t DCPacker::get_unpack_length ( ) const
inline

Returns the total number of bytes in the unpack data buffer.

This is the buffer used when unpacking; it is separate from the pack data returned by get_length(), which is filled during packing.

Definition at line 610 of file dcPacker.I.

◆ get_unpack_string()

std::string DCPacker::get_unpack_string ( ) const
inline

Returns the unpack data buffer, as a string.

This is the buffer used when unpacking; it is separate from the pack data returned by get_string(), which is filled during packing. Also see get_unpack_data().

Definition at line 620 of file dcPacker.I.

◆ get_write_pointer()

char * DCPacker::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.

This may only be called between packing sessions.

Definition at line 675 of file dcPacker.I.

◆ had_error()

bool DCPacker::had_error ( ) const
inline

Returns true if there has been any error (either a pack error or a range error) since the most recent call to begin().

If this returns true, then the matching call to end() will indicate an error (false).

Definition at line 563 of file dcPacker.I.

◆ had_pack_error()

bool DCPacker::had_pack_error ( ) const
inline

Returns true if there has been an packing error since the most recent call to begin(); in particular, this may be called after end() has returned false to determine the nature of the failure.

A return value of true indicates there was a push/pop mismatch, or the push/pop structure did not match the data structure, or there were the wrong number of elements in a nested push/pop structure, or on unpack that the data stream was truncated.

Definition at line 539 of file dcPacker.I.

◆ had_parse_error()

bool DCPacker::had_parse_error ( ) const
inline

Returns true if there has been an parse error since the most recent call to begin(); this can only happen if you call parse_and_pack().

Definition at line 524 of file dcPacker.I.

◆ had_range_error()

bool DCPacker::had_range_error ( ) const
inline

Returns true if there has been an range validation error since the most recent call to begin(); in particular, this may be called after end() has returned false to determine the nature of the failure.

A return value of true indicates a value that was packed or unpacked did not fit within the specified legal range for a parameter, or within the limits of the field size.

Definition at line 553 of file dcPacker.I.

◆ has_nested_fields()

bool DCPacker::has_nested_fields ( ) const
inline

Returns true if the current field has any nested fields (and thus expects a push() .

. pop() interface), or false otherwise. If this returns true, get_num_nested_fields() may be called to determine how many nested fields are expected.

Definition at line 37 of file dcPacker.I.

References DCPackerInterface::has_nested_fields().

Referenced by push().

◆ more_nested_fields()

bool DCPacker::more_nested_fields ( ) const
inline

Returns true if there are more nested fields to pack or unpack in the current push sequence, false if it is time to call pop().

Definition at line 67 of file dcPacker.I.

◆ output_hex_string()

void DCPacker::output_hex_string ( std::ostream &  out,
const vector_uchar &  str 
)
static

Outputs the indicated string as a hex constant.

Definition at line 1121 of file dcPacker.cxx.

◆ pack_blob()

void DCPacker::pack_blob ( const vector_uchar &  value)
inline

Packs the indicated numeric or string value into the stream.

Definition at line 223 of file dcPacker.I.

◆ pack_default_value()

void DCPacker::pack_default_value ( )

Adds the default value for the current element into the stream.

If no default has been set for the current element, creates a sensible default.

Definition at line 552 of file dcPacker.cxx.

Referenced by DCSwitch::pack_default_value().

◆ pack_double()

void DCPacker::pack_double ( double  value)
inline

Packs the indicated numeric or string value into the stream.

Definition at line 139 of file dcPacker.I.

◆ pack_int()

void DCPacker::pack_int ( int  value)
inline

Packs the indicated numeric or string value into the stream.

Definition at line 153 of file dcPacker.I.

◆ pack_int64()

void DCPacker::pack_int64 ( int64_t  value)
inline

Packs the indicated numeric or string value into the stream.

Definition at line 181 of file dcPacker.I.

◆ pack_literal_value()

void DCPacker::pack_literal_value ( const vector_uchar &  value)
inline

Adds the indicated string value into the stream, representing a single pre- packed field element, or a whole group of field elements at once.

Definition at line 238 of file dcPacker.I.

Referenced by DCSwitch::pack_default_value().

◆ pack_string()

void DCPacker::pack_string ( const std::string &  value)
inline

Packs the indicated numeric or string value into the stream.

Definition at line 209 of file dcPacker.I.

◆ pack_uint()

void DCPacker::pack_uint ( unsigned int  value)
inline

Packs the indicated numeric or string value into the stream.

Definition at line 167 of file dcPacker.I.

◆ pack_uint64()

void DCPacker::pack_uint64 ( uint64_t  value)
inline

Packs the indicated numeric or string value into the stream.

Definition at line 195 of file dcPacker.I.

◆ parse_and_pack() [1/2]

bool DCPacker::parse_and_pack ( const std::string &  formatted_object)

Parses an object's value according to the DC file syntax (e.g.

as a default value string) and packs it. Returns true on success, false on a parse error.

Definition at line 960 of file dcPacker.cxx.

Referenced by DCField::parse_string().

◆ parse_and_pack() [2/2]

bool DCPacker::parse_and_pack ( std::istream &  in)

Parses an object's value according to the DC file syntax (e.g.

as a default value string) and packs it. Returns true on success, false on a parse error.

Definition at line 971 of file dcPacker.cxx.

◆ pop()

void DCPacker::pop ( )

Marks the end of a nested series of fields.

This must be called to match a previous push() only after all the expected number of nested fields have been packed. It is an error to call it too early, or too late.

Definition at line 495 of file dcPacker.cxx.

References DCPackData::get_length(), DCPackerInterface::get_num_length_bytes(), DCPackerInterface::get_num_nested_fields(), DCPackData::get_rewrite_pointer(), DCPackerInterface::validate_num_nested_fields(), and DCPackerInterface::validate_uint_limits().

◆ push()

void DCPacker::push ( )

Marks the beginning of a nested series of fields.

This must be called before filling the elements of an array or the individual fields in a structure field. It must also be balanced by a matching pop().

It is necessary to use push() / pop() only if has_nested_fields() returns true.

Definition at line 411 of file dcPacker.cxx.

References DCPackData::append_junk(), DCPackerInterface::calc_num_nested_fields(), DCPackData::get_length(), DCPackerInterface::get_nested_field(), DCPackerInterface::get_num_length_bytes(), DCPackerInterface::get_num_nested_fields(), and has_nested_fields().

Referenced by DCArrayParameter::pack_default_value(), and DCSimpleParameter::pack_default_value().

◆ raw_pack_blob()

void DCPacker::raw_pack_blob ( const vector_uchar &  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 795 of file dcPacker.I.

◆ raw_pack_float64()

void DCPacker::raw_pack_float64 ( double  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 776 of file dcPacker.I.

◆ raw_pack_int16()

void DCPacker::raw_pack_int16 ( int  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 713 of file dcPacker.I.

◆ raw_pack_int32()

void DCPacker::raw_pack_int32 ( int  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 722 of file dcPacker.I.

◆ raw_pack_int64()

void DCPacker::raw_pack_int64 ( int64_t  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 731 of file dcPacker.I.

◆ raw_pack_int8()

void DCPacker::raw_pack_int8 ( int  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 704 of file dcPacker.I.

◆ raw_pack_string()

void DCPacker::raw_pack_string ( const std::string &  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 785 of file dcPacker.I.

◆ raw_pack_uint16()

void DCPacker::raw_pack_uint16 ( unsigned int  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 749 of file dcPacker.I.

◆ raw_pack_uint32()

void DCPacker::raw_pack_uint32 ( unsigned int  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 758 of file dcPacker.I.

◆ raw_pack_uint64()

void DCPacker::raw_pack_uint64 ( uint64_t  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 767 of file dcPacker.I.

◆ raw_pack_uint8()

void DCPacker::raw_pack_uint8 ( unsigned int  value)
inline

Packs the data into the buffer between packing sessions.

Definition at line 740 of file dcPacker.I.

◆ raw_unpack_blob() [1/2]

vector_uchar DCPacker::raw_unpack_blob ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 947 of file dcPacker.I.

◆ raw_unpack_blob() [2/2]

void DCPacker::raw_unpack_blob ( vector_uchar &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 1058 of file dcPacker.I.

◆ raw_unpack_float64() [1/2]

double DCPacker::raw_unpack_float64 ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 927 of file dcPacker.I.

◆ raw_unpack_float64() [2/2]

void DCPacker::raw_unpack_float64 ( double &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 1027 of file dcPacker.I.

◆ raw_unpack_int16() [1/2]

int DCPacker::raw_unpack_int16 ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 815 of file dcPacker.I.

◆ raw_unpack_int16() [2/2]

void DCPacker::raw_unpack_int16 ( int &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 859 of file dcPacker.I.

◆ raw_unpack_int32() [1/2]

int DCPacker::raw_unpack_int32 ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 825 of file dcPacker.I.

◆ raw_unpack_int32() [2/2]

void DCPacker::raw_unpack_int32 ( int &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 873 of file dcPacker.I.

◆ raw_unpack_int64() [1/2]

int64_t DCPacker::raw_unpack_int64 ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 835 of file dcPacker.I.

◆ raw_unpack_int64() [2/2]

void DCPacker::raw_unpack_int64 ( int64_t &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 957 of file dcPacker.I.

◆ raw_unpack_int8() [1/2]

int DCPacker::raw_unpack_int8 ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 805 of file dcPacker.I.

◆ raw_unpack_int8() [2/2]

void DCPacker::raw_unpack_int8 ( int &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 845 of file dcPacker.I.

◆ raw_unpack_string() [1/2]

std::string DCPacker::raw_unpack_string ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 937 of file dcPacker.I.

◆ raw_unpack_string() [2/2]

void DCPacker::raw_unpack_string ( std::string &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 1041 of file dcPacker.I.

◆ raw_unpack_uint16() [1/2]

unsigned int DCPacker::raw_unpack_uint16 ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 897 of file dcPacker.I.

◆ raw_unpack_uint16() [2/2]

void DCPacker::raw_unpack_uint16 ( unsigned int &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 985 of file dcPacker.I.

◆ raw_unpack_uint32() [1/2]

unsigned int DCPacker::raw_unpack_uint32 ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 907 of file dcPacker.I.

◆ raw_unpack_uint32() [2/2]

void DCPacker::raw_unpack_uint32 ( unsigned int &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 999 of file dcPacker.I.

◆ raw_unpack_uint64() [1/2]

uint64_t DCPacker::raw_unpack_uint64 ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 917 of file dcPacker.I.

◆ raw_unpack_uint64() [2/2]

void DCPacker::raw_unpack_uint64 ( uint64_t &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 1013 of file dcPacker.I.

◆ raw_unpack_uint8() [1/2]

unsigned int DCPacker::raw_unpack_uint8 ( )
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 887 of file dcPacker.I.

◆ raw_unpack_uint8() [2/2]

void DCPacker::raw_unpack_uint8 ( unsigned int &  value)
inline

Unpacks the data from the buffer between unpacking sessions.

Definition at line 971 of file dcPacker.I.

◆ seek() [1/2]

bool DCPacker::seek ( const std::string &  field_name)

Sets the current unpack (or repack) position to the named field.

In unpack mode, the next call to unpack_*() or push() will begin to read the named field. In repack mode, the next call to pack_*() or push() will modify the named field.

Returns true if successful, false if the field is not known (or if the packer is in an invalid mode).

Definition at line 270 of file dcPacker.cxx.

References DCPackerInterface::get_catalog(), and DCPackerCatalog::get_live_catalog().

◆ seek() [2/2]

bool DCPacker::seek ( int  seek_index)

Seeks to the field indentified by seek_index, which was returned by an earlier call to DCField::find_seek_index() to get the index of some nested field.

Also see the version of seek() that accepts a field name.

Returns true if successful, false if the field is not known (or if the packer is in an invalid mode).

Definition at line 300 of file dcPacker.cxx.

References DCPackerInterface::get_catalog(), and DCPackerCatalog::get_live_catalog().

◆ set_unpack_data() [1/2]

void DCPacker::set_unpack_data ( const vector_uchar &  data)

Sets up the unpack_data pointer.

You may call this before calling the version of begin_unpack() that takes only one parameter.

Definition at line 117 of file dcPacker.cxx.

Referenced by DCField::format_data(), and DCField::validate_ranges().

◆ set_unpack_data() [2/2]

void DCPacker::set_unpack_data ( const char *  unpack_data,
size_t  unpack_length,
bool  owns_unpack_data 
)

Sets up the unpack_data pointer.

You may call this before calling the version of begin_unpack() that takes only one parameter.

Definition at line 130 of file dcPacker.cxx.

◆ take_data()

char * DCPacker::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 655 of file dcPacker.I.

References DCPackData::take_data().

◆ unpack_and_format() [1/2]

string DCPacker::unpack_and_format ( bool  show_field_names = true)

Unpacks an object and formats its value into a syntax suitable for parsing in the dc file (e.g.

as a default value), or as an input to parse_object.

Definition at line 989 of file dcPacker.cxx.

Referenced by DCField::format_data().

◆ unpack_and_format() [2/2]

void DCPacker::unpack_and_format ( std::ostream &  out,
bool  show_field_names = true 
)

Unpacks an object and formats its value into a syntax suitable for parsing in the dc file (e.g.

as a default value), or as an input to parse_object.

Definition at line 1000 of file dcPacker.cxx.

References get_current_field_name(), and get_pack_type().

◆ unpack_blob() [1/2]

vector_uchar DCPacker::unpack_blob ( )
inline

Unpacks the current binary data value from the stream.

Definition at line 366 of file dcPacker.I.

◆ unpack_blob() [2/2]

void DCPacker::unpack_blob ( vector_uchar &  value)
inline

Unpacks the current numeric or string value from the stream.

Definition at line 494 of file dcPacker.I.

◆ unpack_double() [1/2]

double DCPacker::unpack_double ( )
inline

Unpacks the current numeric or string value from the stream.

Definition at line 252 of file dcPacker.I.

◆ unpack_double() [2/2]

void DCPacker::unpack_double ( double &  value)
inline

Unpacks the current numeric or string value from the stream.

Definition at line 398 of file dcPacker.I.

◆ unpack_int() [1/2]

int DCPacker::unpack_int ( )
inline

Unpacks the current numeric or string value from the stream.

Definition at line 271 of file dcPacker.I.

◆ unpack_int() [2/2]

void DCPacker::unpack_int ( int &  value)
inline

Unpacks the current numeric or string value from the stream.

Definition at line 414 of file dcPacker.I.

◆ unpack_int64() [1/2]

int64_t DCPacker::unpack_int64 ( )
inline

Unpacks the current numeric or string value from the stream.

Definition at line 309 of file dcPacker.I.

◆ unpack_int64() [2/2]

void DCPacker::unpack_int64 ( int64_t &  value)
inline

Unpacks the current numeric or string value from the stream.

Definition at line 446 of file dcPacker.I.

◆ unpack_literal_value() [1/2]

vector_uchar DCPacker::unpack_literal_value ( )
inline

Returns the literal string that represents the packed value of the current field, and advances the field pointer.

Definition at line 386 of file dcPacker.I.

References unpack_skip().

◆ unpack_literal_value() [2/2]

void DCPacker::unpack_literal_value ( vector_uchar &  value)
inline

Returns the literal string that represents the packed value of the current field, and advances the field pointer.

Definition at line 511 of file dcPacker.I.

References unpack_skip().

◆ unpack_skip()

void DCPacker::unpack_skip ( )

Skips the current field without unpacking it and advances to the next field.

If the current field contains nested fields, skips all of them.

Definition at line 604 of file dcPacker.cxx.

Referenced by unpack_literal_value().

◆ unpack_string() [1/2]

std::string DCPacker::unpack_string ( )
inline

Unpacks the current numeric or string value from the stream.

Definition at line 347 of file dcPacker.I.

◆ unpack_string() [2/2]

void DCPacker::unpack_string ( std::string &  value)
inline

Unpacks the current numeric or string value from the stream.

Definition at line 478 of file dcPacker.I.

◆ unpack_uint() [1/2]

unsigned int DCPacker::unpack_uint ( )
inline

Unpacks the current numeric or string value from the stream.

Definition at line 290 of file dcPacker.I.

◆ unpack_uint() [2/2]

void DCPacker::unpack_uint ( unsigned int &  value)
inline

Unpacks the current numeric or string value from the stream.

Definition at line 430 of file dcPacker.I.

◆ unpack_uint64() [1/2]

uint64_t DCPacker::unpack_uint64 ( )
inline

Unpacks the current numeric or string value from the stream.

Definition at line 328 of file dcPacker.I.

◆ unpack_uint64() [2/2]

void DCPacker::unpack_uint64 ( uint64_t &  value)
inline

Unpacks the current numeric or string value from the stream.

Definition at line 462 of file dcPacker.I.

◆ unpack_validate()

void DCPacker::unpack_validate ( )

Internally unpacks the current numeric or string value and validates it against the type range limits, but does not return the value.

If the current field contains nested fields, validates all of them.

Definition at line 578 of file dcPacker.cxx.

Referenced by DCField::validate_ranges().


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