17 INLINE DatagramIterator::
26 INLINE DatagramIterator::
27 DatagramIterator(
const Datagram &datagram,
size_t offset) :
29 _current_index(offset) {
30 nassertv(_current_index <= _datagram->get_length());
38 _datagram = &datagram;
39 _current_index = offset;
57 nassertr(_datagram !=
nullptr, 0);
59 nassertr(_current_index < _datagram->get_length(), 0);
61 const char *ptr = (
const char *)_datagram->
get_data();
62 int8_t tempvar = (int8_t)ptr[_current_index];
73 nassertr(_datagram !=
nullptr, 0);
75 nassertr(_current_index < _datagram->get_length(), 0);
77 const char *ptr = (
const char *)_datagram->
get_data();
78 uint8_t tempvar = (uint8_t)ptr[_current_index];
89 nassertr(_datagram !=
nullptr, 0);
90 nassertr(_current_index < _datagram->get_length(), 0);
94 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
97 s.store_value(&tempvar,
sizeof(tempvar));
98 _current_index +=
sizeof(tempvar);
108 nassertr(_datagram !=
nullptr, 0);
109 nassertr(_current_index < _datagram->get_length(), 0);
113 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
116 s.store_value(&tempvar,
sizeof(tempvar));
117 _current_index +=
sizeof(tempvar);
127 nassertr(_datagram !=
nullptr, 0);
128 nassertr(_current_index < _datagram->get_length(), 0);
132 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
135 s.store_value(&tempvar,
sizeof(tempvar));
136 _current_index +=
sizeof(tempvar);
146 nassertr(_datagram !=
nullptr, 0);
147 nassertr(_current_index < _datagram->get_length(), 0);
151 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
154 s.store_value(&tempvar,
sizeof(tempvar));
155 _current_index +=
sizeof(tempvar);
165 nassertr(_datagram !=
nullptr, 0);
166 nassertr(_current_index < _datagram->get_length(), 0);
170 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
173 s.store_value(&tempvar,
sizeof(tempvar));
174 _current_index +=
sizeof(tempvar);
184 nassertr(_datagram !=
nullptr, 0);
185 nassertr(_current_index < _datagram->get_length(), 0);
189 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
192 s.store_value(&tempvar,
sizeof(tempvar));
193 _current_index +=
sizeof(tempvar);
203 nassertr(_datagram !=
nullptr, 0.0);
204 nassertr(_current_index < _datagram->get_length(), 0.0);
208 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0.0);
212 _current_index +=
sizeof(tempvar);
222 nassertr(_datagram !=
nullptr, 0.0);
223 nassertr(_current_index < _datagram->get_length(), 0.0);
227 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0.0);
231 _current_index +=
sizeof(tempvar);
243 nassertr(_datagram !=
nullptr, 0.0);
256 nassertr(_datagram !=
nullptr, 0);
257 nassertr(_current_index < _datagram->get_length(), 0);
261 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
264 s.store_value(&tempvar,
sizeof(tempvar));
265 _current_index +=
sizeof(tempvar);
275 nassertr(_datagram !=
nullptr, 0);
276 nassertr(_current_index < _datagram->get_length(), 0);
280 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
283 s.store_value(&tempvar,
sizeof(tempvar));
284 _current_index +=
sizeof(tempvar);
294 nassertr(_datagram !=
nullptr, 0);
295 nassertr(_current_index < _datagram->get_length(), 0);
299 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
302 s.store_value(&tempvar,
sizeof(tempvar));
303 _current_index +=
sizeof(tempvar);
313 nassertr(_datagram !=
nullptr, 0);
314 nassertr(_current_index < _datagram->get_length(), 0);
318 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
321 s.store_value(&tempvar,
sizeof(tempvar));
322 _current_index +=
sizeof(tempvar);
332 nassertr(_datagram !=
nullptr, 0);
333 nassertr(_current_index < _datagram->get_length(), 0);
337 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
340 s.store_value(&tempvar,
sizeof(tempvar));
341 _current_index +=
sizeof(tempvar);
351 nassertr(_datagram !=
nullptr, 0);
352 nassertr(_current_index < _datagram->get_length(), 0);
356 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
359 s.store_value(&tempvar,
sizeof(tempvar));
360 _current_index +=
sizeof(tempvar);
370 nassertr(_datagram !=
nullptr, 0.0);
371 nassertr(_current_index < _datagram->get_length(), 0.0);
375 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0);
378 s.store_value(&tempvar,
sizeof(tempvar));
379 _current_index +=
sizeof(tempvar);
389 nassertr(_datagram !=
nullptr, 0.0);
390 nassertr(_current_index < _datagram->get_length(), 0.0);
394 nassertr(_current_index +
sizeof(tempvar) <= _datagram->
get_length(), 0.0);
398 _current_index +=
sizeof(tempvar);
424 nassertv(_datagram !=
nullptr);
425 nassertv((
int)size >= 0);
427 if (_current_index + size > _datagram->
get_length()) {
428 nout <<
"datagram overflow: current_index = " << _current_index
429 <<
" size = " << size <<
" length = " << _datagram->
get_length() <<
"\n";
433 nassertv(_current_index + size <= _datagram->get_length());
434 _current_index += size;
443 nassertr(_datagram !=
nullptr, vector_uchar());
444 nassertr(_current_index <= _datagram->get_length(), vector_uchar());
446 const unsigned char *ptr = (
const unsigned char *)_datagram->
get_data();
447 return vector_uchar(ptr + _current_index, ptr + _datagram->
get_length());
455 return _datagram->
get_length() - _current_index;
472 return _current_index;
vector_uchar get_remaining_bytes() const
Returns the remaining bytes in the datagram as a string, but does not extract them from the iterator.
void assign(Datagram &datagram, size_t offset=0)
direct Assignment to a Datagram
bool get_bool()
Extracts a boolean value.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
uint64_t get_uint64()
Extracts an unsigned 64-bit integer.
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
PN_float64 get_be_float64()
Extracts a 64-bit big-endian floating-point number.
void dump_hex(std::ostream &out, unsigned int indent=0) const
Writes a representation of the entire datagram contents, as a sequence of hex (and ASCII) values.
const Datagram & get_datagram() const
Return the datagram of this iterator.
uint64_t get_be_uint64()
Extracts an unsigned 64-bit big-endian integer.
int32_t get_be_int32()
Extracts a signed 32-bit big-endian integer.
bool get_stdfloat_double() const
Returns the stdfloat_double flag.
PN_float32 get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
int32_t get_int32()
Extracts a signed 32-bit integer.
size_t get_remaining_size() const
Return the bytes left in the datagram.
int64_t get_int64()
Extracts a signed 64-bit integer.
std::string get_string()
Extracts a variable-length string.
PN_float32 get_float32()
Extracts a 32-bit single-precision floating-point number.
vector_uchar extract_bytes(size_t size)
Extracts the indicated number of bytes in the datagram and returns them as a string.
uint16_t get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
size_t get_current_index() const
Returns the current position within the datagram of the next piece of data to extract.
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
vector_uchar get_blob32()
Extracts a variable-length binary blob with a 32-bit size field.
NativeNumericData and ReversedNumericData work together to provide a sneaky interface for automatical...
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
NativeNumericData and ReversedNumericData work together to provide a sneaky interface for automatical...
void store_value(void *dest, size_t length) const
Copies the data, with byte reversal if appropriate, into the indicated numeric variable,...
PN_float64 get_float64()
Extracts a 64-bit floating-point number.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
vector_uchar get_blob()
Extracts a variable-length binary blob.
int16_t get_int16()
Extracts a signed 16-bit integer.
A class to retrieve the individual data elements previously stored in a Datagram.
int16_t get_be_int16()
Extracts a signed 16-bit big-endian integer.
int8_t get_int8()
Extracts a signed 8-bit integer.
uint32_t get_be_uint32()
Extracts an unsigned 32-bit big-endian integer.
int64_t get_be_int64()
Extracts a signed 64-bit big-endian integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void store_value(void *dest, size_t length) const
Copies the data, with byte reversal if appropriate, into the indicated numeric variable,...
std::wstring get_wstring()
Extracts a variable-length wstring (with a 32-bit length field).
size_t get_length() const
Returns the number of bytes in the datagram.
const void * get_data() const
Returns a pointer to the beginning of the datagram's data.