52 dump_hex(ostream &out,
unsigned int indent)
const {
53 const char *message = (
const char *)
get_data();
55 for (
size_t line = 0; line < num_bytes; line += 16) {
57 sprintf(hex,
"%04x ", ((
unsigned int )line));
58 for (
unsigned int ind = 0; ind < indent; ind++) {
64 for (p = line; p < line + 16; p++) {
67 sprintf(hex,
" %02x", ((
unsigned int)message[p]) & 0xff);
74 for (p = line; p < line + 16 && p < num_bytes; p++) {
76 if (isgraph((
unsigned char)message[p]) || message[p] ==
' ') {
77 out << (char)message[p];
98 wstring::const_iterator ci;
99 for (ci = str.begin(); ci != str.end(); ++ci) {
112 nassertv((
int)size >= 0);
114 if (_data == (uchar *)NULL) {
116 _data = PTA_uchar::empty_array(0);
118 }
else if (_data.get_ref_count() != 1) {
120 PTA_uchar new_data = PTA_uchar::empty_array(0);
121 new_data.v() = _data.v();
132 _data.push_back(
'\0');
145 nassertv((
int)size >= 0);
147 if (_data == (uchar *)NULL) {
149 _data = PTA_uchar::empty_array(0);
151 }
else if (_data.get_ref_count() != 1) {
153 PTA_uchar new_data = PTA_uchar::empty_array(0);
154 new_data.v() = _data.v();
167 _data.v().insert(_data.v().end(), (
const unsigned char *)data,
168 (
const unsigned char *)data + size);
179 nassertv((
int)size >= 0);
181 _data = PTA_uchar::empty_array(0);
182 _data.v().insert(_data.v().end(), (
const unsigned char *)data,
183 (
const unsigned char *)data + size);
206 write(ostream &out,
unsigned int indent)
const {
209 out<<
""<<
"Datagram:\n";
void append_data(const void *data, size_t size)
Appends some more raw data to the end of the datagram.
void add_wstring(const wstring &str)
Adds a variable-length wstring to the datagram.
void dump_hex(ostream &out, unsigned int indent=0) const
Writes a representation of the entire datagram contents, as a sequence of hex (and ASCII) values...
virtual void clear()
Resets the datagram to empty, in preparation for building up a new datagram.
void assign(const void *data, size_t size)
Replaces the datagram's data with the indicated block.
void output(ostream &out) const
Write a string representation of this instance to <out>.
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
void add_uint32(PN_uint32 value)
Adds an unsigned 32-bit integer to the datagram.
TypeHandle is the identifier used to differentiate C++ class types.
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.