Panda3D
 All Classes Functions Variables Enumerations
dcPacker.I
1 // Filename: dcPacker.I
2 // Created by: drose (15Jun04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: DCPacker::clear_data
18 // Access: Published
19 // Description: Empties the data in the pack buffer and unpack
20 // buffer. This should be called between calls to
21 // begin_pack(), unless you want to concatenate all of
22 // the pack results together.
23 ////////////////////////////////////////////////////////////////////
24 INLINE void DCPacker::
26  _pack_data.clear();
27 
28  if (_owns_unpack_data) {
29  delete[] _unpack_data;
30  _owns_unpack_data = false;
31  }
32  _unpack_data = NULL;
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: DCPacker::has_nested_fields
37 // Access: Published
38 // Description: Returns true if the current field has any nested
39 // fields (and thus expects a push() .. pop()
40 // interface), or false otherwise. If this returns
41 // true, get_num_nested_fields() may be called to
42 // determine how many nested fields are expected.
43 ////////////////////////////////////////////////////////////////////
44 INLINE bool DCPacker::
46  if (_current_field == NULL) {
47  return false;
48  } else {
49  return _current_field->has_nested_fields();
50  }
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: DCPacker::get_num_nested_fields
55 // Access: Published
56 // Description: Returns the number of nested fields associated with
57 // the current field, if has_nested_fields() returned
58 // true.
59 //
60 // The return value may be -1 to indicate that a
61 // variable number of nested fields are accepted by this
62 // field type (e.g. a variable-length array).
63 //
64 // Note that this method is unreliable to determine how
65 // many fields you must traverse before you can call
66 // pop(), since particularly in the presence of a
67 // DCSwitch, it may change during traversal. Use
68 // more_nested_fields() instead.
69 ////////////////////////////////////////////////////////////////////
70 INLINE int DCPacker::
72  return _num_nested_fields;
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: DCPacker::more_nested_fields
77 // Access: Published
78 // Description: Returns true if there are more nested fields to pack
79 // or unpack in the current push sequence, false if it
80 // is time to call pop().
81 ////////////////////////////////////////////////////////////////////
82 INLINE bool DCPacker::
84  return (_current_field != (DCPackerInterface *)NULL && !_pack_error);
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: DCPacker::get_current_parent
89 // Access: Published
90 // Description: Returns the field that we left in our last call to
91 // push(): the owner of the current level of fields.
92 // This may be NULL at the beginning of the pack
93 // operation.
94 ////////////////////////////////////////////////////////////////////
95 INLINE const DCPackerInterface *DCPacker::
97  return _current_parent;
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: DCPacker::get_current_field
102 // Access: Published
103 // Description: Returns the field that will be referenced by the next
104 // call to pack_*() or unpack_*(). This will be NULL if
105 // we have unpacked (or packed) all fields, or if it is
106 // time to call pop().
107 ////////////////////////////////////////////////////////////////////
108 INLINE const DCPackerInterface *DCPacker::
110  return _current_field;
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: DCPacker::get_last_switch
115 // Access: Published
116 // Description: Returns a pointer to the last DCSwitch instance that
117 // we have passed by and selected one case of during the
118 // pack/unpack process. Each time we encounter a new
119 // DCSwitch and select a case, this will change state.
120 //
121 // This may be used to detect when a DCSwitch has been
122 // selected. At the moment this changes state,
123 // get_current_parent() will contain the particular
124 // SwitchCase that was selected by the switch.
125 ////////////////////////////////////////////////////////////////////
126 INLINE const DCSwitchParameter *DCPacker::
128  return _last_switch;
129 }
130 
131 ////////////////////////////////////////////////////////////////////
132 // Function: DCPacker::get_pack_type
133 // Access: Published
134 // Description: Returns the type of value expected by the current
135 // field. See the enumerated type definition at the top
136 // of DCPackerInterface.h. If this returns one of
137 // PT_double, PT_int, PT_int64, or PT_string, then you
138 // should call the corresponding pack_double(),
139 // pack_int() function (or unpack_double(),
140 // unpack_int(), etc.) to transfer data. Otherwise, you
141 // should call push() and begin packing or unpacking the
142 // nested fields.
143 ////////////////////////////////////////////////////////////////////
144 INLINE DCPackType DCPacker::
145 get_pack_type() const {
146  if (_current_field == NULL) {
147  return PT_invalid;
148  } else {
149  return _current_field->get_pack_type();
150  }
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: DCPacker::get_current_field_name
155 // Access: Published
156 // Description: Returns the name of the current field, if it has a
157 // name, or the empty string if the field does not have
158 // a name or there is no current field.
159 ////////////////////////////////////////////////////////////////////
160 INLINE string DCPacker::
162  if (_current_field == NULL) {
163  return string();
164  } else {
165  return _current_field->get_name();
166  }
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: DCPacker::pack_double
171 // Access: Published
172 // Description: Packs the indicated numeric or string value into the
173 // stream.
174 ////////////////////////////////////////////////////////////////////
175 INLINE void DCPacker::
176 pack_double(double value) {
177  nassertv(_mode == M_pack || _mode == M_repack);
178  if (_current_field == NULL) {
179  _pack_error = true;
180  } else {
181  _current_field->pack_double(_pack_data, value, _pack_error, _range_error);
182  advance();
183  }
184 }
185 
186 ////////////////////////////////////////////////////////////////////
187 // Function: DCPacker::pack_int
188 // Access: Published
189 // Description: Packs the indicated numeric or string value into the
190 // stream.
191 ////////////////////////////////////////////////////////////////////
192 INLINE void DCPacker::
193 pack_int(int value) {
194  nassertv(_mode == M_pack || _mode == M_repack);
195  if (_current_field == NULL) {
196  _pack_error = true;
197  } else {
198  _current_field->pack_int(_pack_data, value, _pack_error, _range_error);
199  advance();
200  }
201 }
202 
203 ////////////////////////////////////////////////////////////////////
204 // Function: DCPacker::pack_uint
205 // Access: Published
206 // Description: Packs the indicated numeric or string value into the
207 // stream.
208 ////////////////////////////////////////////////////////////////////
209 INLINE void DCPacker::
210 pack_uint(unsigned int value) {
211  nassertv(_mode == M_pack || _mode == M_repack);
212  if (_current_field == NULL) {
213  _pack_error = true;
214  } else {
215  _current_field->pack_uint(_pack_data, value, _pack_error, _range_error);
216  advance();
217  }
218 }
219 
220 ////////////////////////////////////////////////////////////////////
221 // Function: DCPacker::pack_int64
222 // Access: Published
223 // Description: Packs the indicated numeric or string value into the
224 // stream.
225 ////////////////////////////////////////////////////////////////////
226 INLINE void DCPacker::
227 pack_int64(PN_int64 value) {
228  nassertv(_mode == M_pack || _mode == M_repack);
229  if (_current_field == NULL) {
230  _pack_error = true;
231  } else {
232  _current_field->pack_int64(_pack_data, value, _pack_error, _range_error);
233  advance();
234  }
235 }
236 
237 ////////////////////////////////////////////////////////////////////
238 // Function: DCPacker::pack_uint64
239 // Access: Published
240 // Description: Packs the indicated numeric or string value into the
241 // stream.
242 ////////////////////////////////////////////////////////////////////
243 INLINE void DCPacker::
244 pack_uint64(PN_uint64 value) {
245  nassertv(_mode == M_pack || _mode == M_repack);
246  if (_current_field == NULL) {
247  _pack_error = true;
248  } else {
249  _current_field->pack_uint64(_pack_data, value, _pack_error, _range_error);
250  advance();
251  }
252 }
253 
254 ////////////////////////////////////////////////////////////////////
255 // Function: DCPacker::pack_string
256 // Access: Published
257 // Description: Packs the indicated numeric or string value into the
258 // stream.
259 ////////////////////////////////////////////////////////////////////
260 INLINE void DCPacker::
261 pack_string(const string &value) {
262  nassertv(_mode == M_pack || _mode == M_repack);
263  if (_current_field == NULL) {
264  _pack_error = true;
265  } else {
266  _current_field->pack_string(_pack_data, value, _pack_error, _range_error);
267  advance();
268  }
269 }
270 
271 ////////////////////////////////////////////////////////////////////
272 // Function: DCPacker::pack_literal_value
273 // Access: Published
274 // Description: Adds the indicated string value into the stream,
275 // representing a single pre-packed field element, or a
276 // whole group of field elements at once.
277 ////////////////////////////////////////////////////////////////////
278 INLINE void DCPacker::
279 pack_literal_value(const string &value) {
280  nassertv(_mode == M_pack || _mode == M_repack);
281  if (_current_field == NULL) {
282  _pack_error = true;
283  } else {
284  _pack_data.append_data(value.data(), value.length());
285  advance();
286  }
287 }
288 
289 ////////////////////////////////////////////////////////////////////
290 // Function: DCPacker::unpack_double
291 // Access: Published
292 // Description: Unpacks the current numeric or string value from the
293 // stream.
294 ////////////////////////////////////////////////////////////////////
295 INLINE double DCPacker::
297  double value = 0.0;
298  nassertr(_mode == M_unpack, value);
299  if (_current_field == NULL) {
300  _pack_error = true;
301 
302  } else {
303  _current_field->unpack_double(_unpack_data, _unpack_length, _unpack_p,
304  value, _pack_error, _range_error);
305  advance();
306  }
307 
308  return value;
309 }
310 
311 ////////////////////////////////////////////////////////////////////
312 // Function: DCPacker::unpack_int
313 // Access: Published
314 // Description: Unpacks the current numeric or string value from the
315 // stream.
316 ////////////////////////////////////////////////////////////////////
317 INLINE int DCPacker::
319  int value = 0;
320  nassertr(_mode == M_unpack, value);
321  if (_current_field == NULL) {
322  _pack_error = true;
323 
324  } else {
325  _current_field->unpack_int(_unpack_data, _unpack_length, _unpack_p,
326  value, _pack_error, _range_error);
327  advance();
328  }
329 
330  return value;
331 }
332 
333 ////////////////////////////////////////////////////////////////////
334 // Function: DCPacker::unpack_uint
335 // Access: Published
336 // Description: Unpacks the current numeric or string value from the
337 // stream.
338 ////////////////////////////////////////////////////////////////////
339 INLINE unsigned int DCPacker::
341  unsigned int value = 0;
342  nassertr(_mode == M_unpack, value);
343  if (_current_field == NULL) {
344  _pack_error = true;
345 
346  } else {
347  _current_field->unpack_uint(_unpack_data, _unpack_length, _unpack_p,
348  value, _pack_error, _range_error);
349  advance();
350  }
351 
352  return value;
353 }
354 
355 ////////////////////////////////////////////////////////////////////
356 // Function: DCPacker::unpack_int64
357 // Access: Published
358 // Description: Unpacks the current numeric or string value from the
359 // stream.
360 ////////////////////////////////////////////////////////////////////
361 INLINE PN_int64 DCPacker::
363  PN_int64 value = 0;
364  nassertr(_mode == M_unpack, value);
365  if (_current_field == NULL) {
366  _pack_error = true;
367 
368  } else {
369  _current_field->unpack_int64(_unpack_data, _unpack_length, _unpack_p,
370  value, _pack_error, _range_error);
371  advance();
372  }
373 
374  return value;
375 }
376 
377 ////////////////////////////////////////////////////////////////////
378 // Function: DCPacker::unpack_uint64
379 // Access: Published
380 // Description: Unpacks the current numeric or string value from the
381 // stream.
382 ////////////////////////////////////////////////////////////////////
383 INLINE PN_uint64 DCPacker::
385  PN_uint64 value = 0;
386  nassertr(_mode == M_unpack, value);
387  if (_current_field == NULL) {
388  _pack_error = true;
389 
390  } else {
391  _current_field->unpack_uint64(_unpack_data, _unpack_length, _unpack_p,
392  value, _pack_error, _range_error);
393  advance();
394  }
395 
396  return value;
397 }
398 
399 ////////////////////////////////////////////////////////////////////
400 // Function: DCPacker::unpack_string
401 // Access: Published
402 // Description: Unpacks the current numeric or string value from the
403 // stream.
404 ////////////////////////////////////////////////////////////////////
405 INLINE string DCPacker::
407  string value;
408  nassertr(_mode == M_unpack, value);
409  if (_current_field == NULL) {
410  _pack_error = true;
411 
412  } else {
413  _current_field->unpack_string(_unpack_data, _unpack_length, _unpack_p,
414  value, _pack_error, _range_error);
415  advance();
416  }
417 
418  return value;
419 }
420 
421 ////////////////////////////////////////////////////////////////////
422 // Function: DCPacker::unpack_literal_value
423 // Access: Published
424 // Description: Returns the literal string that represents the packed
425 // value of the current field, and advances the field
426 // pointer.
427 ////////////////////////////////////////////////////////////////////
428 INLINE string DCPacker::
430  size_t start = _unpack_p;
431  unpack_skip();
432  nassertr(_unpack_p >= start, string());
433  return string(_unpack_data + start, _unpack_p - start);
434 }
435 
436 ////////////////////////////////////////////////////////////////////
437 // Function: DCPacker::unpack_double
438 // Access: Public
439 // Description: Unpacks the current numeric or string value from the
440 // stream.
441 ////////////////////////////////////////////////////////////////////
442 INLINE void DCPacker::
443 unpack_double(double &value) {
444  nassertv(_mode == M_unpack);
445  if (_current_field == NULL) {
446  _pack_error = true;
447 
448  } else {
449  _current_field->unpack_double(_unpack_data, _unpack_length, _unpack_p,
450  value, _pack_error, _range_error);
451  advance();
452  }
453 }
454 
455 ////////////////////////////////////////////////////////////////////
456 // Function: DCPacker::unpack_int
457 // Access: Public
458 // Description: Unpacks the current numeric or string value from the
459 // stream.
460 ////////////////////////////////////////////////////////////////////
461 INLINE void DCPacker::
462 unpack_int(int &value) {
463  nassertv(_mode == M_unpack);
464  if (_current_field == NULL) {
465  _pack_error = true;
466 
467  } else {
468  _current_field->unpack_int(_unpack_data, _unpack_length, _unpack_p,
469  value, _pack_error, _range_error);
470  advance();
471  }
472 }
473 
474 ////////////////////////////////////////////////////////////////////
475 // Function: DCPacker::unpack_uint
476 // Access: Public
477 // Description: Unpacks the current numeric or string value from the
478 // stream.
479 ////////////////////////////////////////////////////////////////////
480 INLINE void DCPacker::
481 unpack_uint(unsigned int &value) {
482  nassertv(_mode == M_unpack);
483  if (_current_field == NULL) {
484  _pack_error = true;
485 
486  } else {
487  _current_field->unpack_uint(_unpack_data, _unpack_length, _unpack_p,
488  value, _pack_error, _range_error);
489  advance();
490  }
491 }
492 
493 ////////////////////////////////////////////////////////////////////
494 // Function: DCPacker::unpack_int64
495 // Access: Public
496 // Description: Unpacks the current numeric or string value from the
497 // stream.
498 ////////////////////////////////////////////////////////////////////
499 INLINE void DCPacker::
500 unpack_int64(PN_int64 &value) {
501  nassertv(_mode == M_unpack);
502  if (_current_field == NULL) {
503  _pack_error = true;
504 
505  } else {
506  _current_field->unpack_int64(_unpack_data, _unpack_length, _unpack_p,
507  value, _pack_error, _range_error);
508  advance();
509  }
510 }
511 
512 ////////////////////////////////////////////////////////////////////
513 // Function: DCPacker::unpack_uint64
514 // Access: Public
515 // Description: Unpacks the current numeric or string value from the
516 // stream.
517 ////////////////////////////////////////////////////////////////////
518 INLINE void DCPacker::
519 unpack_uint64(PN_uint64 &value) {
520  nassertv(_mode == M_unpack);
521  if (_current_field == NULL) {
522  _pack_error = true;
523 
524  } else {
525  _current_field->unpack_uint64(_unpack_data, _unpack_length, _unpack_p,
526  value, _pack_error, _range_error);
527  advance();
528  }
529 }
530 
531 ////////////////////////////////////////////////////////////////////
532 // Function: DCPacker::unpack_string
533 // Access: Public
534 // Description: Unpacks the current numeric or string value from the
535 // stream.
536 ////////////////////////////////////////////////////////////////////
537 INLINE void DCPacker::
538 unpack_string(string &value) {
539  nassertv(_mode == M_unpack);
540  if (_current_field == NULL) {
541  _pack_error = true;
542 
543  } else {
544  _current_field->unpack_string(_unpack_data, _unpack_length, _unpack_p,
545  value, _pack_error, _range_error);
546  advance();
547  }
548 }
549 
550 ////////////////////////////////////////////////////////////////////
551 // Function: DCPacker::unpack_literal_value
552 // Access: Public
553 // Description: Returns the literal string that represents the packed
554 // value of the current field, and advances the field
555 // pointer.
556 ////////////////////////////////////////////////////////////////////
557 INLINE void DCPacker::
558 unpack_literal_value(string &value) {
559  size_t start = _unpack_p;
560  unpack_skip();
561  nassertv(_unpack_p >= start);
562  value.assign(_unpack_data + start, _unpack_p - start);
563 }
564 
565 ////////////////////////////////////////////////////////////////////
566 // Function: DCPacker::had_parse_error
567 // Access: Published
568 // Description: Returns true if there has been an parse error
569 // since the most recent call to begin(); this can only
570 // happen if you call parse_and_pack().
571 ////////////////////////////////////////////////////////////////////
572 INLINE bool DCPacker::
574  return _parse_error;
575 }
576 
577 ////////////////////////////////////////////////////////////////////
578 // Function: DCPacker::had_pack_error
579 // Access: Published
580 // Description: Returns true if there has been an packing error
581 // since the most recent call to begin(); in particular,
582 // this may be called after end() has returned false to
583 // determine the nature of the failure.
584 //
585 // A return value of true indicates there was a push/pop
586 // mismatch, or the push/pop structure did not match the
587 // data structure, or there were the wrong number of
588 // elements in a nested push/pop structure, or on unpack
589 // that the data stream was truncated.
590 ////////////////////////////////////////////////////////////////////
591 INLINE bool DCPacker::
592 had_pack_error() const {
593  return _pack_error;
594 }
595 
596 ////////////////////////////////////////////////////////////////////
597 // Function: DCPacker::had_range_error
598 // Access: Published
599 // Description: Returns true if there has been an range validation
600 // error since the most recent call to begin(); in
601 // particular, this may be called after end() has
602 // returned false to determine the nature of the
603 // failure.
604 //
605 // A return value of true indicates a value that was
606 // packed or unpacked did not fit within the specified
607 // legal range for a parameter, or within the limits of
608 // the field size.
609 ////////////////////////////////////////////////////////////////////
610 INLINE bool DCPacker::
612  return _range_error;
613 }
614 
615 ////////////////////////////////////////////////////////////////////
616 // Function: DCPacker::had_error
617 // Access: Published
618 // Description: Returns true if there has been any error (either a
619 // pack error or a range error) since the most recent
620 // call to begin(). If this returns true, then the
621 // matching call to end() will indicate an error
622 // (false).
623 ////////////////////////////////////////////////////////////////////
624 INLINE bool DCPacker::
625 had_error() const {
626  return _range_error || _pack_error || _parse_error;
627 }
628 
629 ////////////////////////////////////////////////////////////////////
630 // Function: DCPacker::get_num_unpacked_bytes
631 // Access: Published
632 // Description: Returns the number of bytes that have been unpacked
633 // so far, or after unpack_end(), the total number of
634 // bytes that were unpacked at all. This can be used to
635 // validate that all of the bytes in the buffer were
636 // actually unpacked (which is not otherwise considered
637 // an error).
638 ////////////////////////////////////////////////////////////////////
639 INLINE size_t DCPacker::
641  return _unpack_p;
642 }
643 
644 ////////////////////////////////////////////////////////////////////
645 // Function: DCPacker::get_length
646 // Access: Published
647 // Description: Returns the current length of the buffer. This is
648 // the number of useful bytes stored in the buffer, not
649 // the amount of memory it takes up.
650 ////////////////////////////////////////////////////////////////////
651 INLINE size_t DCPacker::
652 get_length() const {
653  return _pack_data.get_length();
654 }
655 
656 ////////////////////////////////////////////////////////////////////
657 // Function: DCPacker::get_string
658 // Access: Published
659 // Description: Returns the packed data buffer as a string. Also see
660 // get_data().
661 ////////////////////////////////////////////////////////////////////
662 INLINE string DCPacker::
663 get_string() const {
664  return _pack_data.get_string();
665 }
666 
667 ////////////////////////////////////////////////////////////////////
668 // Function: DCPacker::get_unpack_length
669 // Access: Published
670 // Description: Returns the total number of bytes in the unpack data
671 // buffer. This is the buffer used when unpacking; it
672 // is separate from the pack data returned by
673 // get_length(), which is filled during packing.
674 ////////////////////////////////////////////////////////////////////
675 INLINE size_t DCPacker::
677  return _unpack_length;
678 }
679 
680 ////////////////////////////////////////////////////////////////////
681 // Function: DCPacker::get_unpack_string
682 // Access: Published
683 // Description: Returns the unpack data buffer, as a string.
684 // This is the buffer used when unpacking; it is
685 // separate from the pack data returned by get_string(),
686 // which is filled during packing. Also see
687 // get_unpack_data().
688 ////////////////////////////////////////////////////////////////////
689 INLINE string DCPacker::
691  return string(_unpack_data, _unpack_length);
692 }
693 
694 ////////////////////////////////////////////////////////////////////
695 // Function: DCPacker::get_string
696 // Access: Published
697 // Description: Copies the packed data into the indicated string.
698 // Also see get_data().
699 ////////////////////////////////////////////////////////////////////
700 INLINE void DCPacker::
701 get_string(string &data) const {
702  data.assign(_pack_data.get_data(), _pack_data.get_length());
703 }
704 
705 ////////////////////////////////////////////////////////////////////
706 // Function: DCPacker::get_data
707 // Access: Public
708 // Description: Returns the beginning of the data buffer. The buffer
709 // is not null-terminated, but see also get_string().
710 //
711 // This may be used in conjunction with get_length() to
712 // copy all of the bytes out of the buffer. Also see
713 // take_data() to get the packed data without a copy
714 // operation.
715 ////////////////////////////////////////////////////////////////////
716 INLINE const char *DCPacker::
717 get_data() const {
718  return _pack_data.get_data();
719 }
720 
721 ////////////////////////////////////////////////////////////////////
722 // Function: DCPacker::take_data
723 // Access: Public
724 // Description: Returns the pointer to the beginning of the data
725 // buffer, and transfers ownership of the buffer to the
726 // caller. The caller is now responsible for ultimately
727 // freeing the returned pointer with delete[], if it is
728 // non-NULL. This may (or may not) return NULL if the
729 // buffer is empty.
730 //
731 // This also empties the DCPackData structure, and sets
732 // its length to zero (so you should call get_length()
733 // before calling this method).
734 ////////////////////////////////////////////////////////////////////
735 INLINE char *DCPacker::
737  return _pack_data.take_data();
738 }
739 
740 ////////////////////////////////////////////////////////////////////
741 // Function: DCPacker::append_data
742 // Access: Public
743 // Description: Adds the indicated bytes to the end of the data.
744 // This may only be called between packing sessions.
745 ////////////////////////////////////////////////////////////////////
746 INLINE void DCPacker::
747 append_data(const char *buffer, size_t size) {
748  nassertv(_mode == M_idle);
749  _pack_data.append_data(buffer, size);
750 }
751 
752 ////////////////////////////////////////////////////////////////////
753 // Function: DCPacker::get_write_pointer
754 // Access: Public
755 // Description: Adds the indicated number of bytes to the end of the
756 // data without initializing them, and returns a pointer
757 // to the beginning of the new data. This may only be
758 // called between packing sessions.
759 ////////////////////////////////////////////////////////////////////
760 INLINE char *DCPacker::
761 get_write_pointer(size_t size) {
762  nassertr(_mode == M_idle, NULL);
763  return _pack_data.get_write_pointer(size);
764 }
765 
766 ////////////////////////////////////////////////////////////////////
767 // Function: DCPacker::get_unpack_data
768 // Access: Public
769 // Description: Returns a read pointer to the unpack data buffer.
770 // This is the buffer used when unpacking; it is
771 // separate from the pack data returned by get_data(),
772 // which is filled during packing.
773 ////////////////////////////////////////////////////////////////////
774 INLINE const char *DCPacker::
776  return _unpack_data;
777 }
778 
779 ////////////////////////////////////////////////////////////////////
780 // Function: DCPacker::StackElement::get_num_stack_elements_ever_allocated
781 // Access: Published, Static
782 // Description: Returns the number of DCPacker::StackElement pointers
783 // ever simultaneously allocated; these are now either
784 // in active use or have been recycled into the deleted
785 // DCPacker::StackElement pool to be used again.
786 ////////////////////////////////////////////////////////////////////
787 INLINE int DCPacker::
789  return StackElement::_num_ever_allocated;
790 }
791 
792 ////////////////////////////////////////////////////////////////////
793 // Function: DCPacker::raw_pack_int8
794 // Access: Published
795 // Description: Packs the data into the buffer between packing
796 // sessions.
797 ////////////////////////////////////////////////////////////////////
798 INLINE void DCPacker::
799 raw_pack_int8(int value) {
800  nassertv(_mode == M_idle);
801  DCPackerInterface::do_pack_int8(_pack_data.get_write_pointer(1), value);
802 }
803 
804 ////////////////////////////////////////////////////////////////////
805 // Function: DCPacker::raw_pack_int16
806 // Access: Published
807 // Description: Packs the data into the buffer between packing
808 // sessions.
809 ////////////////////////////////////////////////////////////////////
810 INLINE void DCPacker::
811 raw_pack_int16(int value) {
812  nassertv(_mode == M_idle);
813  DCPackerInterface::do_pack_int16(_pack_data.get_write_pointer(2), value);
814 }
815 
816 ////////////////////////////////////////////////////////////////////
817 // Function: DCPacker::raw_pack_int32
818 // Access: Published
819 // Description: Packs the data into the buffer between packing
820 // sessions.
821 ////////////////////////////////////////////////////////////////////
822 INLINE void DCPacker::
823 raw_pack_int32(int value) {
824  nassertv(_mode == M_idle);
825  DCPackerInterface::do_pack_int32(_pack_data.get_write_pointer(4), value);
826 }
827 
828 ////////////////////////////////////////////////////////////////////
829 // Function: DCPacker::raw_pack_int64
830 // Access: Published
831 // Description: Packs the data into the buffer between packing
832 // sessions.
833 ////////////////////////////////////////////////////////////////////
834 INLINE void DCPacker::
835 raw_pack_int64(PN_int64 value) {
836  nassertv(_mode == M_idle);
837  DCPackerInterface::do_pack_int64(_pack_data.get_write_pointer(8), value);
838 }
839 
840 ////////////////////////////////////////////////////////////////////
841 // Function: DCPacker::raw_pack_uint8
842 // Access: Published
843 // Description: Packs the data into the buffer between packing
844 // sessions.
845 ////////////////////////////////////////////////////////////////////
846 INLINE void DCPacker::
847 raw_pack_uint8(unsigned int value) {
848  nassertv(_mode == M_idle);
849  DCPackerInterface::do_pack_uint8(_pack_data.get_write_pointer(1), value);
850 }
851 
852 ////////////////////////////////////////////////////////////////////
853 // Function: DCPacker::raw_pack_uint16
854 // Access: Published
855 // Description: Packs the data into the buffer between packing
856 // sessions.
857 ////////////////////////////////////////////////////////////////////
858 INLINE void DCPacker::
859 raw_pack_uint16(unsigned int value) {
860  nassertv(_mode == M_idle);
861  DCPackerInterface::do_pack_uint16(_pack_data.get_write_pointer(2), value);
862 }
863 
864 ////////////////////////////////////////////////////////////////////
865 // Function: DCPacker::raw_pack_uint32
866 // Access: Published
867 // Description: Packs the data into the buffer between packing
868 // sessions.
869 ////////////////////////////////////////////////////////////////////
870 INLINE void DCPacker::
871 raw_pack_uint32(unsigned int value) {
872  nassertv(_mode == M_idle);
873  DCPackerInterface::do_pack_uint32(_pack_data.get_write_pointer(4), value);
874 }
875 
876 ////////////////////////////////////////////////////////////////////
877 // Function: DCPacker::raw_pack_uint64
878 // Access: Published
879 // Description: Packs the data into the buffer between packing
880 // sessions.
881 ////////////////////////////////////////////////////////////////////
882 INLINE void DCPacker::
883 raw_pack_uint64(PN_uint64 value) {
884  nassertv(_mode == M_idle);
885  DCPackerInterface::do_pack_uint64(_pack_data.get_write_pointer(8), value);
886 }
887 
888 ////////////////////////////////////////////////////////////////////
889 // Function: DCPacker::raw_pack_float64
890 // Access: Published
891 // Description: Packs the data into the buffer between packing
892 // sessions.
893 ////////////////////////////////////////////////////////////////////
894 INLINE void DCPacker::
895 raw_pack_float64(double value) {
896  nassertv(_mode == M_idle);
897  DCPackerInterface::do_pack_float64(_pack_data.get_write_pointer(8), value);
898 }
899 
900 ////////////////////////////////////////////////////////////////////
901 // Function: DCPacker::raw_pack_string
902 // Access: Published
903 // Description: Packs the data into the buffer between packing
904 // sessions.
905 ////////////////////////////////////////////////////////////////////
906 INLINE void DCPacker::
907 raw_pack_string(const string &value) {
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());
911 }
912 
913 ////////////////////////////////////////////////////////////////////
914 // Function: DCPacker::raw_unpack_int8
915 // Access: Published
916 // Description: Unpacks the data from the buffer between unpacking
917 // sessions.
918 ////////////////////////////////////////////////////////////////////
919 INLINE int DCPacker::
921  int value = 0;
922  raw_unpack_int8(value);
923  return value;
924 }
925 
926 ////////////////////////////////////////////////////////////////////
927 // Function: DCPacker::raw_unpack_int16
928 // Access: Published
929 // Description: Unpacks the data from the buffer between unpacking
930 // sessions.
931 ////////////////////////////////////////////////////////////////////
932 INLINE int DCPacker::
934  int value = 0;
935  raw_unpack_int16(value);
936  return value;
937 }
938 
939 ////////////////////////////////////////////////////////////////////
940 // Function: DCPacker::raw_unpack_int32
941 // Access: Published
942 // Description: Unpacks the data from the buffer between unpacking
943 // sessions.
944 ////////////////////////////////////////////////////////////////////
945 INLINE int DCPacker::
947  int value = 0;
948  raw_unpack_int32(value);
949  return value;
950 }
951 
952 ////////////////////////////////////////////////////////////////////
953 // Function: DCPacker::raw_unpack_int64
954 // Access: Published
955 // Description: Unpacks the data from the buffer between unpacking
956 // sessions.
957 ////////////////////////////////////////////////////////////////////
958 INLINE PN_int64 DCPacker::
960  PN_int64 value = 0;
961  raw_unpack_int64(value);
962  return value;
963 }
964 
965 ////////////////////////////////////////////////////////////////////
966 // Function: DCPacker::raw_unpack_int8
967 // Access: Public
968 // Description: Unpacks the data from the buffer between unpacking
969 // sessions.
970 ////////////////////////////////////////////////////////////////////
971 INLINE void DCPacker::
972 raw_unpack_int8(int &value) {
973  nassertv(_mode == M_idle && _unpack_data != NULL);
974  if (_unpack_p + 1 > _unpack_length) {
975  _pack_error = true;
976  return;
977  }
978  value = DCPackerInterface::do_unpack_int8(_unpack_data + _unpack_p);
979  _unpack_p++;
980 }
981 
982 ////////////////////////////////////////////////////////////////////
983 // Function: DCPacker::raw_unpack_int16
984 // Access: Public
985 // Description: Unpacks the data from the buffer between unpacking
986 // sessions.
987 ////////////////////////////////////////////////////////////////////
988 INLINE void DCPacker::
989 raw_unpack_int16(int &value) {
990  nassertv(_mode == M_idle && _unpack_data != NULL);
991  if (_unpack_p + 2 > _unpack_length) {
992  _pack_error = true;
993  return;
994  }
995  value = DCPackerInterface::do_unpack_int16(_unpack_data + _unpack_p);
996  _unpack_p += 2;
997 }
998 
999 ////////////////////////////////////////////////////////////////////
1000 // Function: DCPacker::raw_unpack_int32
1001 // Access: Public
1002 // Description: Unpacks the data from the buffer between unpacking
1003 // sessions.
1004 ////////////////////////////////////////////////////////////////////
1005 INLINE void DCPacker::
1006 raw_unpack_int32(int &value) {
1007  nassertv(_mode == M_idle && _unpack_data != NULL);
1008  if (_unpack_p + 4 > _unpack_length) {
1009  _pack_error = true;
1010  return;
1011  }
1012  value = DCPackerInterface::do_unpack_int32(_unpack_data + _unpack_p);
1013  _unpack_p += 4;
1014 }
1015 
1016 ////////////////////////////////////////////////////////////////////
1017 // Function: DCPacker::raw_unpack_uint8
1018 // Access: Published
1019 // Description: Unpacks the data from the buffer between unpacking
1020 // sessions.
1021 ////////////////////////////////////////////////////////////////////
1022 INLINE unsigned int DCPacker::
1024  unsigned int value = 0;
1025  raw_unpack_uint8(value);
1026  return value;
1027 }
1028 
1029 ////////////////////////////////////////////////////////////////////
1030 // Function: DCPacker::raw_unpack_uint16
1031 // Access: Published
1032 // Description: Unpacks the data from the buffer between unpacking
1033 // sessions.
1034 ////////////////////////////////////////////////////////////////////
1035 INLINE unsigned int DCPacker::
1037  unsigned int value = 0;
1038  raw_unpack_uint16(value);
1039  return value;
1040 }
1041 
1042 ////////////////////////////////////////////////////////////////////
1043 // Function: DCPacker::raw_unpack_uint32
1044 // Access: Published
1045 // Description: Unpacks the data from the buffer between unpacking
1046 // sessions.
1047 ////////////////////////////////////////////////////////////////////
1048 INLINE unsigned int DCPacker::
1050  unsigned int value = 0;
1051  raw_unpack_uint32(value);
1052  return value;
1053 }
1054 
1055 ////////////////////////////////////////////////////////////////////
1056 // Function: DCPacker::raw_unpack_uint64
1057 // Access: Published
1058 // Description: Unpacks the data from the buffer between unpacking
1059 // sessions.
1060 ////////////////////////////////////////////////////////////////////
1061 INLINE PN_uint64 DCPacker::
1063  PN_uint64 value = 0;
1064  raw_unpack_uint64(value);
1065  return value;
1066 }
1067 
1068 ////////////////////////////////////////////////////////////////////
1069 // Function: DCPacker::raw_unpack_float64
1070 // Access: Published
1071 // Description: Unpacks the data from the buffer between unpacking
1072 // sessions.
1073 ////////////////////////////////////////////////////////////////////
1074 INLINE double DCPacker::
1076  double value = 0;
1077  raw_unpack_float64(value);
1078  return value;
1079 }
1080 
1081 ////////////////////////////////////////////////////////////////////
1082 // Function: DCPacker::raw_unpack_string
1083 // Access: Published
1084 // Description: Unpacks the data from the buffer between unpacking
1085 // sessions.
1086 ////////////////////////////////////////////////////////////////////
1087 INLINE string DCPacker::
1089  string value;
1090  raw_unpack_string(value);
1091  return value;
1092 }
1093 
1094 ////////////////////////////////////////////////////////////////////
1095 // Function: DCPacker::raw_unpack_int64
1096 // Access: Public
1097 // Description: Unpacks the data from the buffer between unpacking
1098 // sessions.
1099 ////////////////////////////////////////////////////////////////////
1100 INLINE void DCPacker::
1101 raw_unpack_int64(PN_int64 &value) {
1102  nassertv(_mode == M_idle && _unpack_data != NULL);
1103  if (_unpack_p + 8 > _unpack_length) {
1104  _pack_error = true;
1105  return;
1106  }
1107  value = DCPackerInterface::do_unpack_int64(_unpack_data + _unpack_p);
1108  _unpack_p += 8;
1109 }
1110 
1111 ////////////////////////////////////////////////////////////////////
1112 // Function: DCPacker::raw_unpack_uint8
1113 // Access: Public
1114 // Description: Unpacks the data from the buffer between unpacking
1115 // sessions.
1116 ////////////////////////////////////////////////////////////////////
1117 INLINE void DCPacker::
1118 raw_unpack_uint8(unsigned int &value) {
1119  nassertv(_mode == M_idle && _unpack_data != NULL);
1120  if (_unpack_p + 1 > _unpack_length) {
1121  _pack_error = true;
1122  return;
1123  }
1124  value = DCPackerInterface::do_unpack_uint8(_unpack_data + _unpack_p);
1125  _unpack_p++;
1126 }
1127 
1128 ////////////////////////////////////////////////////////////////////
1129 // Function: DCPacker::raw_unpack_uint16
1130 // Access: Public
1131 // Description: Unpacks the data from the buffer between unpacking
1132 // sessions.
1133 ////////////////////////////////////////////////////////////////////
1134 INLINE void DCPacker::
1135 raw_unpack_uint16(unsigned int &value) {
1136  nassertv(_mode == M_idle && _unpack_data != NULL);
1137  if (_unpack_p + 2 > _unpack_length) {
1138  _pack_error = true;
1139  return;
1140  }
1141  value = DCPackerInterface::do_unpack_uint16(_unpack_data + _unpack_p);
1142  _unpack_p += 2;
1143 }
1144 
1145 ////////////////////////////////////////////////////////////////////
1146 // Function: DCPacker::raw_unpack_uint32
1147 // Access: Public
1148 // Description: Unpacks the data from the buffer between unpacking
1149 // sessions.
1150 ////////////////////////////////////////////////////////////////////
1151 INLINE void DCPacker::
1152 raw_unpack_uint32(unsigned int &value) {
1153  nassertv(_mode == M_idle && _unpack_data != NULL);
1154  if (_unpack_p + 4 > _unpack_length) {
1155  _pack_error = true;
1156  return;
1157  }
1158  value = DCPackerInterface::do_unpack_uint32(_unpack_data + _unpack_p);
1159  _unpack_p += 4;
1160 }
1161 
1162 ////////////////////////////////////////////////////////////////////
1163 // Function: DCPacker::raw_unpack_uint64
1164 // Access: Public
1165 // Description: Unpacks the data from the buffer between unpacking
1166 // sessions.
1167 ////////////////////////////////////////////////////////////////////
1168 INLINE void DCPacker::
1169 raw_unpack_uint64(PN_uint64 &value) {
1170  nassertv(_mode == M_idle && _unpack_data != NULL);
1171  if (_unpack_p + 8 > _unpack_length) {
1172  _pack_error = true;
1173  return;
1174  }
1175  value = DCPackerInterface::do_unpack_uint64(_unpack_data + _unpack_p);
1176  _unpack_p += 8;
1177 }
1178 
1179 ////////////////////////////////////////////////////////////////////
1180 // Function: DCPacker::raw_unpack_float64
1181 // Access: Public
1182 // Description: Unpacks the data from the buffer between unpacking
1183 // sessions.
1184 ////////////////////////////////////////////////////////////////////
1185 INLINE void DCPacker::
1186 raw_unpack_float64(double &value) {
1187  nassertv(_mode == M_idle && _unpack_data != NULL);
1188  if (_unpack_p + 8 > _unpack_length) {
1189  _pack_error = true;
1190  return;
1191  }
1192  value = DCPackerInterface::do_unpack_float64(_unpack_data + _unpack_p);
1193  _unpack_p += 8;
1194 }
1195 
1196 ////////////////////////////////////////////////////////////////////
1197 // Function: DCPacker::raw_unpack_string
1198 // Access: Public
1199 // Description: Unpacks the data from the buffer between unpacking
1200 // sessions.
1201 ////////////////////////////////////////////////////////////////////
1202 INLINE void DCPacker::
1203 raw_unpack_string(string &value) {
1204  nassertv(_mode == M_idle && _unpack_data != NULL);
1205  unsigned int string_length = raw_unpack_uint16();
1206 
1207  if (_unpack_p + string_length > _unpack_length) {
1208  _pack_error = true;
1209  return;
1210  }
1211 
1212  value.assign(_unpack_data + _unpack_p, string_length);
1213  _unpack_p += string_length;
1214 }
1215 
1216 ////////////////////////////////////////////////////////////////////
1217 // Function: DCPacker::advance
1218 // Access: Private
1219 // Description: Advances to the next field after a call to
1220 // pack_value() or pop().
1221 ////////////////////////////////////////////////////////////////////
1222 INLINE void DCPacker::
1223 advance() {
1224  _current_field_index++;
1225  if (_num_nested_fields >= 0 &&
1226  _current_field_index >= _num_nested_fields) {
1227  // Done with all the fields on this parent. The caller must now
1228  // call pop().
1229  _current_field = NULL;
1230 
1231  // But if the parent is a switch record, we make a special case so
1232  // we can get the alternate fields.
1233  if (_current_parent != (DCPackerInterface *)NULL) {
1234  const DCSwitchParameter *switch_parameter = ((DCPackerInterface *)_current_parent)->as_switch_parameter();
1235  if (switch_parameter != (DCSwitchParameter *)NULL) {
1236  handle_switch(switch_parameter);
1237  }
1238  }
1239 
1240  } else if (_pop_marker != 0 && _unpack_p >= _pop_marker) {
1241  // Done with all the fields on this parent. The caller must now
1242  // call pop().
1243  _current_field = NULL;
1244 
1245  } else {
1246  // We have another field to advance to.
1247  _current_field = _current_parent->get_nested_field(_current_field_index);
1248  }
1249 }
1250 
1251 ////////////////////////////////////////////////////////////////////
1252 // Function: DCPacker::StackElement::operator new
1253 // Access: Public
1254 // Description: Allocates the memory for a new DCPacker::StackElement.
1255 // This is specialized here to provide for fast
1256 // allocation of these things.
1257 ////////////////////////////////////////////////////////////////////
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;
1263  return obj;
1264  }
1265 #ifndef NDEBUG
1266  _num_ever_allocated++;
1267 #endif // NDEBUG
1268  return ::operator new(size);
1269 }
1270 
1271 ////////////////////////////////////////////////////////////////////
1272 // Function: DCPacker::StackElement::operator delete
1273 // Access: Public
1274 // Description: Frees the memory for a deleted DCPacker::StackElement.
1275 // This is specialized here to provide for fast
1276 // allocation of these things.
1277 ////////////////////////////////////////////////////////////////////
1278 INLINE void DCPacker::StackElement::
1279 operator delete(void *ptr) {
1280  StackElement *obj = (StackElement *)ptr;
1281  obj->_next = _deleted_chain;
1282  _deleted_chain = obj;
1283 }
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.
Definition: dcPackData.I:70
const DCPackerInterface * get_current_field() const
Returns the field that will be referenced by the next call to pack_*() or unpack_*().
Definition: dcPacker.I:109
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...
Definition: dcPacker.I:788
bool had_error() const
Returns true if there has been any error (either a pack error or a range error) since the most recent...
Definition: dcPacker.I:625
void append_data(const char *buffer, size_t size)
Adds the indicated bytes to the end of the data.
Definition: dcPackData.I:57
void pack_int(int value)
Packs the indicated numeric or string value into the stream.
Definition: dcPacker.I:193
void raw_pack_int16(int value)
Packs the data into the buffer between packing sessions.
Definition: dcPacker.I:811
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.
Definition: dcPacker.I:747
void pack_int64(PN_int64 value)
Packs the indicated numeric or string value into the stream.
Definition: dcPacker.I:227
bool has_nested_fields() const
Returns true if the current field has any nested fields (and thus expects a push() ...
Definition: dcPacker.I:45
void raw_pack_string(const string &value)
Packs the data into the buffer between packing sessions.
Definition: dcPacker.I:907
void clear()
Empties the contents of the data (without necessarily freeing its allocated memory).
Definition: dcPackData.I:47
int raw_unpack_int16()
Unpacks the data from the buffer between unpacking sessions.
Definition: dcPacker.I:933
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...
Definition: dcPacker.I:161
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.
Definition: dcPacker.I:1036
int raw_unpack_int8()
Unpacks the data from the buffer between unpacking sessions.
Definition: dcPacker.I:920
void raw_pack_uint8(unsigned int value)
Packs the data into the buffer between packing sessions.
Definition: dcPacker.I:847
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.
Definition: dcPacker.I:340
PN_uint64 raw_unpack_uint64()
Unpacks the data from the buffer between unpacking sessions.
Definition: dcPacker.I:1062
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.
Definition: dcPacker.I:210
void raw_pack_uint64(PN_uint64 value)
Packs the data into the buffer between packing sessions.
Definition: dcPacker.I:883
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.
Definition: dcPacker.I:296
size_t get_length() const
Returns the current length of the buffer.
Definition: dcPacker.I:652
void raw_pack_uint32(unsigned int value)
Packs the data into the buffer between packing sessions.
Definition: dcPacker.I:871
void raw_pack_float64(double value)
Packs the data into the buffer between packing sessions.
Definition: dcPacker.I:895
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...
Definition: dcPacker.I:127
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.
Definition: dcPacker.I:761
char * take_data()
Returns the pointer to the beginning of the data buffer, and transfers ownership of the buffer to the...
Definition: dcPacker.I:736
unsigned int raw_unpack_uint8()
Unpacks the data from the buffer between unpacking sessions.
Definition: dcPacker.I:1023
size_t get_unpack_length() const
Returns the total number of bytes in the unpack data buffer.
Definition: dcPacker.I:676
void raw_pack_int64(PN_int64 value)
Packs the data into the buffer between packing sessions.
Definition: dcPacker.I:835
unsigned int raw_unpack_uint32()
Unpacks the data from the buffer between unpacking sessions.
Definition: dcPacker.I:1049
int raw_unpack_int32()
Unpacks the data from the buffer between unpacking sessions.
Definition: dcPacker.I:946
void raw_pack_int8(int value)
Packs the data into the buffer between packing sessions.
Definition: dcPacker.I:799
void raw_pack_uint16(unsigned int value)
Packs the data into the buffer between packing sessions.
Definition: dcPacker.I:859
string unpack_literal_value()
Returns the literal string that represents the packed value of the current field, and advances the fi...
Definition: dcPacker.I:429
void pack_string(const string &value)
Packs the indicated numeric or string value into the stream.
Definition: dcPacker.I:261
size_t get_length() const
Returns the current length of the buffer.
Definition: dcPackData.I:129
char * take_data()
Returns the pointer to the beginning of the data buffer, and transfers ownership of the buffer to the...
Definition: dcPackData.I:164
string get_string() const
Returns the packed data buffer as a string.
Definition: dcPacker.I:663
string raw_unpack_string()
Unpacks the data from the buffer between unpacking sessions.
Definition: dcPacker.I:1088
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...
Definition: dcPacker.I:611
void pack_literal_value(const string &value)
Adds the indicated string value into the stream, representing a single pre-packed field element...
Definition: dcPacker.I:279
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.
Definition: dcPacker.I:145
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.
Definition: dcPacker.I:318
PN_uint64 unpack_uint64()
Unpacks the current numeric or string value from the stream.
Definition: dcPacker.I:384
const char * get_data() const
Returns the beginning of the data buffer.
Definition: dcPacker.I:717
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.
Definition: dcPacker.I:823
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...
Definition: dcPacker.I:573
void unpack_skip()
Skips the current field without unpacking it and advances to the next field.
Definition: dcPacker.cxx:655
double raw_unpack_float64()
Unpacks the data from the buffer between unpacking sessions.
Definition: dcPacker.I:1075
int get_num_nested_fields() const
Returns the number of nested fields associated with the current field, if has_nested_fields() returne...
Definition: dcPacker.I:71
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...
Definition: dcPacker.I:83
string unpack_string()
Unpacks the current numeric or string value from the stream.
Definition: dcPacker.I:406
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.
Definition: dcPackData.I:145
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.
Definition: dcPacker.I:640
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...
Definition: dcPacker.I:96
string get_string() const
Returns the data buffer as a string.
Definition: dcPackData.I:117
PN_int64 unpack_int64()
Unpacks the current numeric or string value from the stream.
Definition: dcPacker.I:362
void pack_double(double value)
Packs the indicated numeric or string value into the stream.
Definition: dcPacker.I:176
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.
Definition: dcPacker.I:690
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.
Definition: dcPacker.I:775
bool had_pack_error() const
Returns true if there has been an packing error since the most recent call to begin(); in particular...
Definition: dcPacker.I:592
void clear_data()
Empties the data in the pack buffer and unpack buffer.
Definition: dcPacker.I:25
PN_int64 raw_unpack_int64()
Unpacks the data from the buffer between unpacking sessions.
Definition: dcPacker.I:959
void pack_uint64(PN_uint64 value)
Packs the indicated numeric or string value into the stream.
Definition: dcPacker.I:244