# DCPacker

from pandac.PandaModules import DCPacker

Class : DCPacker
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.

## Inheritance:

DCPacker:

## Methods of DCPacker:

beginPack
beginRepack
beginUnpack
clearData
endPack
endRepack
endUnpack
getCurrentField
getCurrentFieldName
getCurrentParent
getLastSwitch
getLength
getNumNestedFields
getNumStackElementsEverAllocated
getNumUnpackedBytes
getPackType
getString
hadError
hadPackError
hadParseError
hadRangeError
hasNestedFields
moreNestedFields
packDefaultValue
packDouble
packInt
packInt64
packLiteralValue
packObject
packString
packUint
packUint64
parseAndPack
pop
push
rawPackFloat64
rawPackInt16
rawPackInt32
rawPackInt64
rawPackInt8
rawPackString
rawPackUint16
rawPackUint32
rawPackUint64
rawPackUint8
rawUnpackFloat64
rawUnpackInt16
rawUnpackInt32
rawUnpackInt64
rawUnpackInt8
rawUnpackString
rawUnpackUint16
rawUnpackUint32
rawUnpackUint64
rawUnpackUint8
seek
setUnpackData
unpackAndFormat
unpackDouble
unpackInt
unpackInt64
unpackLiteralValue
unpackObject
unpackSkip
unpackString
unpackUint
unpackUint64
unpackValidate

beginPack void DCPacker::begin_pack(DCPackerInterface const *root); Description: 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().

beginRepack void DCPacker::begin_repack(DCPackerInterface const *root); Description: 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.

beginUnpack void DCPacker::begin_unpack(DCPackerInterface const *root); Description: 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.

clearData void DCPacker::clear_data(void); Filename: dcPacker.I Created by: drose (15Jun04) PANDA 3D SOFTWARE Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved All use of this software is subject to the terms of the Panda 3d Software license. You should have received a copy of this license along with this source code; you will also find a current copy of the license at http://etc.cmu.edu/panda3d/docs/license/ . To contact the maintainers of this program write to panda3d-general@lists.sourceforge.net . Description: 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.

endPack bool DCPacker::end_pack(void); Description: Finishes a packing session. The return value is true on success, or false if there has been some error during packing.

endRepack bool DCPacker::end_repack(void); Description: 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).

endUnpack bool DCPacker::end_unpack(void); Description: 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).

getCurrentField DCPackerInterface const *DCPacker::get_current_field(void) const; Description: 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().

getCurrentFieldName string DCPacker::get_current_field_name(void) const; Description: 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.

getCurrentParent DCPackerInterface const *DCPacker::get_current_parent(void) const; Description: 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.

getLastSwitch DCSwitchParameter const *DCPacker::get_last_switch(void) const; Description: 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.

getLength unsigned int DCPacker::get_length(void) const; Description: 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.

getNumNestedFields int DCPacker::get_num_nested_fields(void) const; Description: 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.

getNumStackElementsEverAllocated static int DCPacker::get_num_stack_elements_ever_allocated(void); Description: 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.

getNumUnpackedBytes unsigned int DCPacker::get_num_unpacked_bytes(void) const; Description: 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).

getPackType DCPackType DCPacker::get_pack_type(void) const; Description: 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.

getString string DCPacker::get_string(void) const; Description: Returns the packed data buffer as a string. Also see get_data(). Description: Copies the packed data into the indicated string. Also see get_data().

hadError bool DCPacker::had_error(void) const; Description: 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).

hadPackError bool DCPacker::had_pack_error(void) const; Description: 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.

hadParseError bool DCPacker::had_parse_error(void) const; Description: 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().

hadRangeError bool DCPacker::had_range_error(void) const; Description: 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.

hasNestedFields bool DCPacker::has_nested_fields(void) const; Description: 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.

moreNestedFields bool DCPacker::more_nested_fields(void) const; Description: 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().

packDefaultValue void DCPacker::pack_default_value(void); Description: 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.

packDouble void DCPacker::pack_double(double value); Description: Packs the indicated numeric or string value into the stream.

packInt void DCPacker::pack_int(int value); Description: Packs the indicated numeric or string value into the stream.

packInt64 void DCPacker::pack_int64(__int64 value); Description: Packs the indicated numeric or string value into the stream.

packLiteralValue void DCPacker::pack_literal_value(string const &value); Description: Adds the indicated string value into the stream, representing a single pre-packed field element, or a whole group of field elements at once.

packObject void DCPacker::pack_object(PyObject *object); Description: Packs the Python object of whatever type into the packer. Each numeric object and string object maps to the corresponding pack_value() call; a tuple or sequence maps to a push() followed by all of the tuple's contents followed by a pop().

packString void DCPacker::pack_string(string const &value); Description: Packs the indicated numeric or string value into the stream.

packUint void DCPacker::pack_uint(unsigned int value); Description: Packs the indicated numeric or string value into the stream.

packUint64 void DCPacker::pack_uint64(unsigned __int64 value); Description: Packs the indicated numeric or string value into the stream.

parseAndPack bool DCPacker::parse_and_pack(string const &formatted_object); HAVE_PYTHON Description: 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.

pop void DCPacker::pop(void); Description: 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.

push void DCPacker::push(void); Description: 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.

rawPackFloat64 void DCPacker::raw_pack_float64(double value); Description: Packs the data into the buffer between packing sessions.

rawPackInt16 void DCPacker::raw_pack_int16(int value); Description: Packs the data into the buffer between packing sessions.

rawPackInt32 void DCPacker::raw_pack_int32(int value); Description: Packs the data into the buffer between packing sessions.

rawPackInt64 void DCPacker::raw_pack_int64(__int64 value); Description: Packs the data into the buffer between packing sessions.

rawPackInt8 void DCPacker::raw_pack_int8(int value); The following methods are used only for packing (or unpacking) raw data into the buffer between packing sessions (e.g. between calls to end_pack() and the next begin_pack()). Description: Packs the data into the buffer between packing sessions.

rawPackString void DCPacker::raw_pack_string(string const &value); Description: Packs the data into the buffer between packing sessions.

rawPackUint16 void DCPacker::raw_pack_uint16(unsigned int value); Description: Packs the data into the buffer between packing sessions.

rawPackUint32 void DCPacker::raw_pack_uint32(unsigned int value); Description: Packs the data into the buffer between packing sessions.

rawPackUint64 void DCPacker::raw_pack_uint64(unsigned __int64 value); Description: Packs the data into the buffer between packing sessions.

rawPackUint8 void DCPacker::raw_pack_uint8(unsigned int value); Description: Packs the data into the buffer between packing sessions.

rawUnpackFloat64 double DCPacker::raw_unpack_float64(void); Description: Unpacks the data from the buffer between unpacking sessions.

rawUnpackInt16 int DCPacker::raw_unpack_int16(void); Description: Unpacks the data from the buffer between unpacking sessions.

rawUnpackInt32 int DCPacker::raw_unpack_int32(void); Description: Unpacks the data from the buffer between unpacking sessions.

rawUnpackInt64 __int64 DCPacker::raw_unpack_int64(void); Description: Unpacks the data from the buffer between unpacking sessions.

rawUnpackInt8 int DCPacker::raw_unpack_int8(void); Description: Unpacks the data from the buffer between unpacking sessions.

rawUnpackString string DCPacker::raw_unpack_string(void); Description: Unpacks the data from the buffer between unpacking sessions.

rawUnpackUint16 unsigned int DCPacker::raw_unpack_uint16(void); Description: Unpacks the data from the buffer between unpacking sessions.

rawUnpackUint32 unsigned int DCPacker::raw_unpack_uint32(void); Description: Unpacks the data from the buffer between unpacking sessions.

rawUnpackUint64 unsigned __int64 DCPacker::raw_unpack_uint64(void); Description: Unpacks the data from the buffer between unpacking sessions.

rawUnpackUint8 unsigned int DCPacker::raw_unpack_uint8(void); Description: Unpacks the data from the buffer between unpacking sessions.

seek bool DCPacker::seek(string const &field_name); Description: 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). Description: 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.

setUnpackData void DCPacker::set_unpack_data(string const &data); Description: Sets up the unpack_data pointer. You may call this before calling the version of begin_unpack() that takes only one parameter.

unpackAndFormat string DCPacker::unpack_and_format(bool show_field_names = (1)); Description: 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.

unpackDouble double DCPacker::unpack_double(void); Description: Unpacks the current numeric or string value from the stream.

unpackInt int DCPacker::unpack_int(void); Description: Unpacks the current numeric or string value from the stream.

unpackInt64 __int64 DCPacker::unpack_int64(void); Description: Unpacks the current numeric or string value from the stream.

unpackLiteralValue string DCPacker::unpack_literal_value(void); Description: Returns the literal string that represents the packed value of the current field, and advances the field pointer.

unpackObject PyObject *DCPacker::unpack_object(void); Description: Unpacks a Python object of the appropriate type from the stream for the current field. This may be an integer or a string for a simple field object; if the current field represents a list of fields it will be a tuple.

unpackSkip void DCPacker::unpack_skip(void); Description: Skips the current field without unpacking it and advances to the next field. If the current field contains nested fields, skips all of them.

unpackString string DCPacker::unpack_string(void); Description: Unpacks the current numeric or string value from the stream.

unpackUint unsigned int DCPacker::unpack_uint(void); Description: Unpacks the current numeric or string value from the stream.

unpackUint64 unsigned __int64 DCPacker::unpack_uint64(void); Description: Unpacks the current numeric or string value from the stream.

unpackValidate void DCPacker::unpack_validate(void); Description: 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.