15 #include "datagramIterator.h"
30 nassertr(_datagram != (
const Datagram *)NULL,
"");
31 nassertr(_current_index + s_len <= _datagram->get_length(),
"");
33 const char *ptr = (
const char *)_datagram->
get_data();
34 int last_index = _current_index;
36 _current_index += s_len;
38 return string(ptr + last_index, s_len);
52 nassertr(_datagram != (
const Datagram *)NULL,
"");
53 nassertr(_current_index + s_len <= _datagram->get_length(),
"");
55 const char *ptr = (
const char *)_datagram->
get_data();
56 int last_index = _current_index;
58 _current_index += s_len;
60 return string(ptr + last_index, s_len);
71 nassertr(_datagram != (
const Datagram *)NULL,
"");
74 const char *ptr = (
const char *)_datagram->
get_data();
76 size_t p = _current_index;
77 while (p < length && ptr[p] !=
'\0') {
80 nassertr(p < length,
"");
82 int last_index = _current_index;
83 _current_index = p + 1;
85 return string(ptr + last_index, p - last_index);
97 nassertr(_datagram != (
const Datagram *)NULL,
"");
98 nassertr(_current_index + size <= _datagram->get_length(),
"");
100 const char *ptr = (
const char *)_datagram->
get_data();
101 string s(ptr + _current_index, size);
103 _current_index += size;
105 size_t zero_byte = s.find(
'\0');
106 return s.substr(0, zero_byte);
120 nassertr(_datagram != (
const Datagram *)NULL, wstring());
121 nassertr(_current_index + s_len * 2 <= _datagram->
get_length(), wstring());
124 result.reserve(s_len);
141 nassertr((
int)size >= 0,
"");
142 nassertr(_datagram != (
const Datagram *)NULL,
"");
143 nassertr(_current_index + size <= _datagram->get_length(),
"");
145 const char *ptr = (
const char *)_datagram->
get_data();
146 int last_index = _current_index;
148 _current_index += size;
150 return string(ptr + last_index, size);
164 nassertr((
int)size >= 0, 0);
165 nassertr(_datagram != (
const Datagram *)NULL, 0);
166 nassertr(_current_index + size <= _datagram->get_length(), 0);
168 const char *ptr = (
const char *)_datagram->
get_data();
169 memcpy(into, ptr + _current_index, size);
171 _current_index += size;
184 out<<
""<<
"DatagramIterator";
195 write(ostream &out,
unsigned int indent)
const {
197 out.width(indent); out<<
""<<
"DatagramIterator:\n";
198 out.width(indent+2); out<<
""<<
"_current_index "<<_current_index;
201 out<<
""<<
" / 0x"<<(
void*)_current_index<<
" (of 0x"
205 out<<
""<<
" (_datagram is null)\n";
void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
PN_uint32 get_uint32()
Extracts an unsigned 32-bit integer.
size_t get_length() const
Returns the number of bytes in the datagram.
string get_string()
Extracts a variable-length string.
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
string extract_bytes(size_t size)
Extracts the indicated number of bytes in the datagram and returns them as a string.
const Datagram & get_datagram() const
Return the datagram of this iterator.
const void * get_data() const
Returns a pointer to the beginning of the datagram's data.
string get_z_string()
Extracts a variable-length string, as a NULL-terminated string.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
wstring get_wstring()
Extracts a variable-length wstring (with a 32-bit length field).
string get_string32()
Extracts a variable-length string with a 32-bit length field.
void output(ostream &out) const
Write a string representation of this instance to <out>.
string get_fixed_string(size_t size)
Extracts a fixed-length string.