28 if (_owns_unpack_data) {
29 delete[] _unpack_data;
30 _owns_unpack_data =
false;
46 if (_current_field == NULL) {
72 return _num_nested_fields;
97 return _current_parent;
110 return _current_field;
146 if (_current_field == NULL) {
162 if (_current_field == NULL) {
177 nassertv(_mode == M_pack || _mode == M_repack);
178 if (_current_field == NULL) {
181 _current_field->
pack_double(_pack_data, value, _pack_error, _range_error);
194 nassertv(_mode == M_pack || _mode == M_repack);
195 if (_current_field == NULL) {
198 _current_field->
pack_int(_pack_data, value, _pack_error, _range_error);
211 nassertv(_mode == M_pack || _mode == M_repack);
212 if (_current_field == NULL) {
215 _current_field->
pack_uint(_pack_data, value, _pack_error, _range_error);
228 nassertv(_mode == M_pack || _mode == M_repack);
229 if (_current_field == NULL) {
232 _current_field->
pack_int64(_pack_data, value, _pack_error, _range_error);
245 nassertv(_mode == M_pack || _mode == M_repack);
246 if (_current_field == NULL) {
249 _current_field->
pack_uint64(_pack_data, value, _pack_error, _range_error);
262 nassertv(_mode == M_pack || _mode == M_repack);
263 if (_current_field == NULL) {
266 _current_field->
pack_string(_pack_data, value, _pack_error, _range_error);
280 nassertv(_mode == M_pack || _mode == M_repack);
281 if (_current_field == NULL) {
284 _pack_data.
append_data(value.data(), value.length());
298 nassertr(_mode == M_unpack, value);
299 if (_current_field == NULL) {
303 _current_field->
unpack_double(_unpack_data, _unpack_length, _unpack_p,
304 value, _pack_error, _range_error);
320 nassertr(_mode == M_unpack, value);
321 if (_current_field == NULL) {
325 _current_field->
unpack_int(_unpack_data, _unpack_length, _unpack_p,
326 value, _pack_error, _range_error);
341 unsigned int value = 0;
342 nassertr(_mode == M_unpack, value);
343 if (_current_field == NULL) {
347 _current_field->
unpack_uint(_unpack_data, _unpack_length, _unpack_p,
348 value, _pack_error, _range_error);
364 nassertr(_mode == M_unpack, value);
365 if (_current_field == NULL) {
369 _current_field->
unpack_int64(_unpack_data, _unpack_length, _unpack_p,
370 value, _pack_error, _range_error);
386 nassertr(_mode == M_unpack, value);
387 if (_current_field == NULL) {
391 _current_field->
unpack_uint64(_unpack_data, _unpack_length, _unpack_p,
392 value, _pack_error, _range_error);
408 nassertr(_mode == M_unpack, value);
409 if (_current_field == NULL) {
413 _current_field->
unpack_string(_unpack_data, _unpack_length, _unpack_p,
414 value, _pack_error, _range_error);
430 size_t start = _unpack_p;
432 nassertr(_unpack_p >= start,
string());
433 return string(_unpack_data + start, _unpack_p - start);
444 nassertv(_mode == M_unpack);
445 if (_current_field == NULL) {
449 _current_field->
unpack_double(_unpack_data, _unpack_length, _unpack_p,
450 value, _pack_error, _range_error);
463 nassertv(_mode == M_unpack);
464 if (_current_field == NULL) {
468 _current_field->
unpack_int(_unpack_data, _unpack_length, _unpack_p,
469 value, _pack_error, _range_error);
482 nassertv(_mode == M_unpack);
483 if (_current_field == NULL) {
487 _current_field->
unpack_uint(_unpack_data, _unpack_length, _unpack_p,
488 value, _pack_error, _range_error);
501 nassertv(_mode == M_unpack);
502 if (_current_field == NULL) {
506 _current_field->
unpack_int64(_unpack_data, _unpack_length, _unpack_p,
507 value, _pack_error, _range_error);
520 nassertv(_mode == M_unpack);
521 if (_current_field == NULL) {
525 _current_field->
unpack_uint64(_unpack_data, _unpack_length, _unpack_p,
526 value, _pack_error, _range_error);
539 nassertv(_mode == M_unpack);
540 if (_current_field == NULL) {
544 _current_field->
unpack_string(_unpack_data, _unpack_length, _unpack_p,
545 value, _pack_error, _range_error);
559 size_t start = _unpack_p;
561 nassertv(_unpack_p >= start);
562 value.assign(_unpack_data + start, _unpack_p - start);
626 return _range_error || _pack_error || _parse_error;
677 return _unpack_length;
691 return string(_unpack_data, _unpack_length);
748 nassertv(_mode == M_idle);
762 nassertr(_mode == M_idle, NULL);
789 return StackElement::_num_ever_allocated;
800 nassertv(_mode == M_idle);
812 nassertv(_mode == M_idle);
824 nassertv(_mode == M_idle);
836 nassertv(_mode == M_idle);
848 nassertv(_mode == M_idle);
860 nassertv(_mode == M_idle);
872 nassertv(_mode == M_idle);
884 nassertv(_mode == M_idle);
896 nassertv(_mode == M_idle);
908 nassertv(_mode == M_idle);
909 DCPackerInterface::do_pack_uint16(_pack_data.
get_write_pointer(2), value.length());
910 _pack_data.
append_data(value.data(), value.length());
973 nassertv(_mode == M_idle && _unpack_data != NULL);
974 if (_unpack_p + 1 > _unpack_length) {
978 value = DCPackerInterface::do_unpack_int8(_unpack_data + _unpack_p);
990 nassertv(_mode == M_idle && _unpack_data != NULL);
991 if (_unpack_p + 2 > _unpack_length) {
995 value = DCPackerInterface::do_unpack_int16(_unpack_data + _unpack_p);
1007 nassertv(_mode == M_idle && _unpack_data != NULL);
1008 if (_unpack_p + 4 > _unpack_length) {
1012 value = DCPackerInterface::do_unpack_int32(_unpack_data + _unpack_p);
1024 unsigned int value = 0;
1037 unsigned int value = 0;
1050 unsigned int value = 0;
1063 PN_uint64 value = 0;
1102 nassertv(_mode == M_idle && _unpack_data != NULL);
1103 if (_unpack_p + 8 > _unpack_length) {
1107 value = DCPackerInterface::do_unpack_int64(_unpack_data + _unpack_p);
1119 nassertv(_mode == M_idle && _unpack_data != NULL);
1120 if (_unpack_p + 1 > _unpack_length) {
1124 value = DCPackerInterface::do_unpack_uint8(_unpack_data + _unpack_p);
1136 nassertv(_mode == M_idle && _unpack_data != NULL);
1137 if (_unpack_p + 2 > _unpack_length) {
1141 value = DCPackerInterface::do_unpack_uint16(_unpack_data + _unpack_p);
1153 nassertv(_mode == M_idle && _unpack_data != NULL);
1154 if (_unpack_p + 4 > _unpack_length) {
1158 value = DCPackerInterface::do_unpack_uint32(_unpack_data + _unpack_p);
1170 nassertv(_mode == M_idle && _unpack_data != NULL);
1171 if (_unpack_p + 8 > _unpack_length) {
1175 value = DCPackerInterface::do_unpack_uint64(_unpack_data + _unpack_p);
1187 nassertv(_mode == M_idle && _unpack_data != NULL);
1188 if (_unpack_p + 8 > _unpack_length) {
1192 value = DCPackerInterface::do_unpack_float64(_unpack_data + _unpack_p);
1204 nassertv(_mode == M_idle && _unpack_data != NULL);
1207 if (_unpack_p + string_length > _unpack_length) {
1212 value.assign(_unpack_data + _unpack_p, string_length);
1213 _unpack_p += string_length;
1222 INLINE
void DCPacker::
1224 _current_field_index++;
1225 if (_num_nested_fields >= 0 &&
1226 _current_field_index >= _num_nested_fields) {
1229 _current_field = NULL;
1236 handle_switch(switch_parameter);
1240 }
else if (_pop_marker != 0 && _unpack_p >= _pop_marker) {
1243 _current_field = NULL;
1258 INLINE
void *DCPacker::StackElement::
1259 operator
new(
size_t size) {
1260 if (_deleted_chain != (DCPacker::StackElement *)NULL) {
1261 StackElement *obj = _deleted_chain;
1262 _deleted_chain = _deleted_chain->_next;
1266 _num_ever_allocated++;
1268 return ::operator
new(size);
1278 INLINE
void DCPacker::StackElement::
1279 operator
delete(
void *ptr) {
1280 StackElement *obj = (StackElement *)ptr;
1281 obj->_next = _deleted_chain;
1282 _deleted_chain = obj;
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.
const DCPackerInterface * get_current_field() const
Returns the field that will be referenced by the next call to pack_*() or unpack_*().
const string & get_name() const
Returns the name of this field, or empty string if the field is unnamed.
static int get_num_stack_elements_ever_allocated()
Returns the number of DCPacker::StackElement pointers ever simultaneously allocated; these are now ei...
bool had_error() const
Returns true if there has been any error (either a pack error or a range error) since the most recent...
void append_data(const char *buffer, size_t size)
Adds the indicated bytes to the end of the data.
void pack_int(int value)
Packs the indicated numeric or string value into the stream.
void raw_pack_int16(int value)
Packs the data into the buffer between packing sessions.
virtual DCPackerInterface * get_nested_field(int n) const
Returns the DCPackerInterface object that represents the nth nested field.
void append_data(const char *buffer, size_t size)
Adds the indicated bytes to the end of the data.
void pack_int64(PN_int64 value)
Packs the indicated numeric or string value into the stream.
bool has_nested_fields() const
Returns true if the current field has any nested fields (and thus expects a push() ...
void raw_pack_string(const string &value)
Packs the data into the buffer between packing sessions.
void clear()
Empties the contents of the data (without necessarily freeing its allocated memory).
int raw_unpack_int16()
Unpacks the data from the buffer between unpacking sessions.
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 ha...
virtual void pack_uint(DCPackData &pack_data, unsigned int value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
unsigned int raw_unpack_uint16()
Unpacks the data from the buffer between unpacking sessions.
int raw_unpack_int8()
Unpacks the data from the buffer between unpacking sessions.
void raw_pack_uint8(unsigned int value)
Packs the data into the buffer between packing sessions.
virtual void unpack_uint(const char *data, size_t length, size_t &p, unsigned int &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
This represents a switch object used as a parameter itself, which packs the appropriate fields of the...
unsigned int unpack_uint()
Unpacks the current numeric or string value from the stream.
PN_uint64 raw_unpack_uint64()
Unpacks the data from the buffer between unpacking sessions.
virtual void pack_double(DCPackData &pack_data, double value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
void pack_uint(unsigned int value)
Packs the indicated numeric or string value into the stream.
void raw_pack_uint64(PN_uint64 value)
Packs the data into the buffer between packing sessions.
virtual void pack_uint64(DCPackData &pack_data, PN_uint64 value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
double unpack_double()
Unpacks the current numeric or string value from the stream.
size_t get_length() const
Returns the current length of the buffer.
void raw_pack_uint32(unsigned int value)
Packs the data into the buffer between packing sessions.
void raw_pack_float64(double value)
Packs the data into the buffer between packing sessions.
virtual void unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
const DCSwitchParameter * get_last_switch() const
Returns a pointer to the last DCSwitch instance that we have passed by and selected one case of durin...
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.
char * take_data()
Returns the pointer to the beginning of the data buffer, and transfers ownership of the buffer to the...
unsigned int raw_unpack_uint8()
Unpacks the data from the buffer between unpacking sessions.
size_t get_unpack_length() const
Returns the total number of bytes in the unpack data buffer.
void raw_pack_int64(PN_int64 value)
Packs the data into the buffer between packing sessions.
unsigned int raw_unpack_uint32()
Unpacks the data from the buffer between unpacking sessions.
int raw_unpack_int32()
Unpacks the data from the buffer between unpacking sessions.
void raw_pack_int8(int value)
Packs the data into the buffer between packing sessions.
void raw_pack_uint16(unsigned int value)
Packs the data into the buffer between packing sessions.
string unpack_literal_value()
Returns the literal string that represents the packed value of the current field, and advances the fi...
void pack_string(const string &value)
Packs the indicated numeric or string value into the stream.
size_t get_length() const
Returns the current length of the buffer.
char * take_data()
Returns the pointer to the beginning of the data buffer, and transfers ownership of the buffer to the...
string get_string() const
Returns the packed data buffer as a string.
string raw_unpack_string()
Unpacks the data from the buffer between unpacking sessions.
virtual void unpack_uint64(const char *data, size_t length, size_t &p, PN_uint64 &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
bool had_range_error() const
Returns true if there has been an range validation error since the most recent call to begin(); in pa...
void pack_literal_value(const string &value)
Adds the indicated string value into the stream, representing a single pre-packed field element...
virtual void pack_string(DCPackData &pack_data, const string &value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
DCPackType get_pack_type() const
Returns the type of value expected by the current field.
virtual void pack_int(DCPackData &pack_data, int value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
int unpack_int()
Unpacks the current numeric or string value from the stream.
PN_uint64 unpack_uint64()
Unpacks the current numeric or string value from the stream.
const char * get_data() const
Returns the beginning of the data buffer.
DCPackType get_pack_type() const
Returns the type of value expected by this field.
void raw_pack_int32(int value)
Packs the data into the buffer between packing sessions.
virtual void unpack_int(const char *data, size_t length, size_t &p, int &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
bool had_parse_error() const
Returns true if there has been an parse error since the most recent call to begin(); this can only ha...
void unpack_skip()
Skips the current field without unpacking it and advances to the next field.
double raw_unpack_float64()
Unpacks the data from the buffer between unpacking sessions.
int get_num_nested_fields() const
Returns the number of nested fields associated with the current field, if has_nested_fields() returne...
virtual void unpack_double(const char *data, size_t length, size_t &p, double &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
bool more_nested_fields() const
Returns true if there are more nested fields to pack or unpack in the current push sequence...
string unpack_string()
Unpacks the current numeric or string value from the stream.
virtual void unpack_string(const char *data, size_t length, size_t &p, string &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
const char * get_data() const
Returns the beginning of the data buffer.
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.
const DCPackerInterface * get_current_parent() const
Returns the field that we left in our last call to push(): the owner of the current level of fields...
string get_string() const
Returns the data buffer as a string.
PN_int64 unpack_int64()
Unpacks the current numeric or string value from the stream.
void pack_double(double value)
Packs the indicated numeric or string value into the stream.
bool has_nested_fields() const
Returns true if this field type has any nested fields (and thus expects a push() .
string get_unpack_string() const
Returns the unpack data buffer, as a string.
virtual void pack_int64(DCPackData &pack_data, PN_int64 value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
This defines the internal interface for packing values into a DCField.
const char * get_unpack_data() const
Returns a read pointer to the unpack data buffer.
bool had_pack_error() const
Returns true if there has been an packing error since the most recent call to begin(); in particular...
void clear_data()
Empties the data in the pack buffer and unpack buffer.
PN_int64 raw_unpack_int64()
Unpacks the data from the buffer between unpacking sessions.
void pack_uint64(PN_uint64 value)
Packs the indicated numeric or string value into the stream.