mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
express: Add peek_int16 and peek_uint16 to DatagramIterator
This commit is contained in:
parent
27e54ffd75
commit
d6ebd62034
@ -82,10 +82,10 @@ get_uint8() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts a signed 16-bit integer.
|
* Extracts a signed 16-bit integer without advancing the iterator.
|
||||||
*/
|
*/
|
||||||
INLINE int16_t DatagramIterator::
|
INLINE int16_t DatagramIterator::
|
||||||
get_int16() {
|
peek_int16() {
|
||||||
nassertr(_datagram != nullptr, 0);
|
nassertr(_datagram != nullptr, 0);
|
||||||
nassertr(_current_index < _datagram->get_length(), 0);
|
nassertr(_current_index < _datagram->get_length(), 0);
|
||||||
|
|
||||||
@ -95,11 +95,38 @@ get_int16() {
|
|||||||
// Get the Data:
|
// Get the Data:
|
||||||
LittleEndian s(_datagram->get_data(), _current_index, sizeof(tempvar));
|
LittleEndian s(_datagram->get_data(), _current_index, sizeof(tempvar));
|
||||||
s.store_value(&tempvar, sizeof(tempvar));
|
s.store_value(&tempvar, sizeof(tempvar));
|
||||||
_current_index += sizeof(tempvar);
|
|
||||||
|
|
||||||
return tempvar;
|
return tempvar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts an unsigned 16-bit integer without advancing the iterator.
|
||||||
|
*/
|
||||||
|
INLINE uint16_t DatagramIterator::
|
||||||
|
peek_uint16() {
|
||||||
|
nassertr(_datagram != nullptr, 0);
|
||||||
|
nassertr(_current_index < _datagram->get_length(), 0);
|
||||||
|
|
||||||
|
uint16_t tempvar;
|
||||||
|
// Avoid reading junk data off the end of the datagram:
|
||||||
|
nassertr(_current_index + sizeof(tempvar) <= _datagram->get_length(), 0);
|
||||||
|
// Get the Data:
|
||||||
|
LittleEndian s(_datagram->get_data(), _current_index, sizeof(tempvar));
|
||||||
|
s.store_value(&tempvar, sizeof(tempvar));
|
||||||
|
|
||||||
|
return tempvar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts a signed 16-bit integer.
|
||||||
|
*/
|
||||||
|
INLINE int16_t DatagramIterator::
|
||||||
|
get_int16() {
|
||||||
|
int16_t tempvar = peek_int16();
|
||||||
|
_current_index += sizeof(tempvar);
|
||||||
|
return tempvar;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts a signed 32-bit integer.
|
* Extracts a signed 32-bit integer.
|
||||||
*/
|
*/
|
||||||
@ -143,17 +170,8 @@ get_int64() {
|
|||||||
*/
|
*/
|
||||||
INLINE uint16_t DatagramIterator::
|
INLINE uint16_t DatagramIterator::
|
||||||
get_uint16() {
|
get_uint16() {
|
||||||
nassertr(_datagram != nullptr, 0);
|
uint16_t tempvar = peek_uint16();
|
||||||
nassertr(_current_index < _datagram->get_length(), 0);
|
|
||||||
|
|
||||||
uint16_t tempvar;
|
|
||||||
// Avoid reading junk data off the end of the datagram:
|
|
||||||
nassertr(_current_index + sizeof(tempvar) <= _datagram->get_length(), 0);
|
|
||||||
// Get the Data:
|
|
||||||
LittleEndian s(_datagram->get_data(), _current_index, sizeof(tempvar));
|
|
||||||
s.store_value(&tempvar, sizeof(tempvar));
|
|
||||||
_current_index += sizeof(tempvar);
|
_current_index += sizeof(tempvar);
|
||||||
|
|
||||||
return tempvar;
|
return tempvar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ PUBLISHED:
|
|||||||
INLINE int8_t get_int8();
|
INLINE int8_t get_int8();
|
||||||
INLINE uint8_t get_uint8();
|
INLINE uint8_t get_uint8();
|
||||||
|
|
||||||
|
INLINE int16_t peek_int16();
|
||||||
|
INLINE uint16_t peek_uint16();
|
||||||
|
|
||||||
INLINE int16_t get_int16();
|
INLINE int16_t get_int16();
|
||||||
INLINE int32_t get_int32();
|
INLINE int32_t get_int32();
|
||||||
INLINE int64_t get_int64();
|
INLINE int64_t get_int64();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user