30 nassertr(_datagram !=
nullptr,
"");
31 nassertr(_current_index + s_len <= _datagram->get_length(),
"");
33 const char *ptr = (
const char *)_datagram->
get_data();
34 size_t last_index = _current_index;
36 _current_index += s_len;
38 return string(ptr + last_index, s_len);
49 nassertr(_datagram !=
nullptr,
"");
50 nassertr(_current_index + s_len <= _datagram->get_length(),
"");
52 const char *ptr = (
const char *)_datagram->
get_data();
53 size_t last_index = _current_index;
55 _current_index += s_len;
57 return string(ptr + last_index, s_len);
65 nassertr(_datagram !=
nullptr,
"");
68 const char *ptr = (
const char *)_datagram->
get_data();
70 size_t p = _current_index;
71 while (p < length && ptr[p] !=
'\0') {
74 nassertr(p < length,
"");
76 size_t last_index = _current_index;
77 _current_index = p + 1;
79 return string(ptr + last_index, p - last_index);
88 nassertr(_datagram !=
nullptr,
"");
89 nassertr(_current_index + size <= _datagram->get_length(),
"");
91 const char *ptr = (
const char *)_datagram->
get_data();
92 string s(ptr + _current_index, size);
94 _current_index += size;
96 size_t zero_byte = s.find(
'\0');
97 return s.substr(0, zero_byte);
108 nassertr(_datagram !=
nullptr, wstring());
109 nassertr(_current_index + s_len * 2 <= _datagram->
get_length(), wstring());
112 result.reserve(s_len);
127 nassertr((
int)size >= 0, vector_uchar());
128 nassertr(_datagram !=
nullptr, vector_uchar());
129 nassertr(_current_index + size <= _datagram->get_length(), vector_uchar());
131 const unsigned char *ptr = (
const unsigned char *)_datagram->
get_data();
132 ptr += _current_index;
134 _current_index += size;
136 return vector_uchar(ptr, ptr + size);
147 nassertr((
int)size >= 0, 0);
148 nassertr(_datagram !=
nullptr, 0);
149 nassertr(_current_index + size <= _datagram->get_length(), 0);
151 const char *ptr = (
const char *)_datagram->
get_data();
152 memcpy(into, ptr + _current_index, size);
154 _current_index += size;
164 out<<
""<<
"DatagramIterator";
174 out.width(
indent); out<<
""<<
"DatagramIterator:\n";
175 out.width(
indent+2); out<<
""<<
"_current_index "<<_current_index;
178 out<<
""<<
" / 0x"<<(
void*)_current_index<<
" (of 0x" 182 out<<
""<<
" (_datagram is null)\n";
const Datagram & get_datagram() const
Return the datagram of this iterator.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write(std::ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_string()
Extracts a variable-length string.
vector_uchar extract_bytes(size_t size)
Extracts the indicated number of bytes in the datagram and returns them as a string.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
void write(std::ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
std::string get_z_string()
Extracts a variable-length string, as a NULL-terminated string.
TypeHandle is the identifier used to differentiate C++ class types.
void output(std::ostream &out) const
Write a string representation of this instance to <out>.
std::wstring get_wstring()
Extracts a variable-length wstring (with a 32-bit length field).
std::string get_string32()
Extracts a variable-length string 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.
std::string get_fixed_string(size_t size)
Extracts a fixed-length string.