18 Datagram(
const void *data,
size_t size) {
26 Datagram(vector_uchar data) :
27 _data(std::move(data)) {
134 if (_stdfloat_double) {
221 nassertv(str.length() <= (uint16_t)0xffff);
249 size_t null_pos = str.find(
'\0');
251 append_data(str.data(), std::min<size_t>(null_pos, str.length()));
264 if (str.length() < size) {
280 nassertv(data.size() <= (uint16_t)0xffff);
316 if (_data.size() == 0) {
317 return std::string();
319 return std::string((
const char *)_data.p(), _data.size());
357 _data.v() = data.v();
373 if (_data ==
nullptr) {
375 _data = PTA_uchar::empty_array(0);
377 }
else if (_data.get_ref_count() != 1) {
379 PTA_uchar new_data = PTA_uchar::empty_array(0);
380 new_data.v() = _data.v();
396 _stdfloat_double = stdfloat_double;
404 return _stdfloat_double;
410 INLINE
bool Datagram::
411 operator == (
const Datagram &other)
const {
412 if (_data == other._data) {
415 if (_data !=
nullptr && other._data !=
nullptr) {
416 return _data.v() == other._data.v();
424 INLINE
bool Datagram::
425 operator != (
const Datagram &other)
const {
426 return !operator == (other);
432 INLINE
bool Datagram::
433 operator < (
const Datagram &other)
const {
434 if (_data == other._data) {
439 if (_data !=
nullptr && other._data !=
nullptr) {
441 return _data.v() < other._data.v();
445 return _data.size() < other._data.size();
449 generic_write_datagram(
Datagram &dest,
bool value) {
454 generic_write_datagram(
Datagram &dest,
int value) {
459 generic_write_datagram(
Datagram &dest,
float value) {
464 generic_write_datagram(
Datagram &dest,
double value) {
469 generic_write_datagram(
Datagram &dest,
const std::string &value) {
474 generic_write_datagram(
Datagram &dest,
const std::wstring &value) {
479 generic_write_datagram(
Datagram &dest,
const vector_uchar &value) {
void add_int16(int16_t value)
Adds a signed 16-bit integer to the datagram.
CPTA_uchar get_array() const
Returns a const pointer to the actual data in the Datagram.
void add_float64(PN_float64 value)
Adds a 64-bit floating-point number to the datagram.
void append_data(const void *data, size_t size)
Appends some more raw data to the end of the datagram.
void add_z_string(const std::string &str)
Adds a variable-length string to the datagram, as a NULL-terminated string.
void add_float32(PN_float32 value)
Adds a 32-bit single-precision floating-point number to the datagram.
bool get_stdfloat_double() const
Returns the stdfloat_double flag.
void add_wstring(const std::wstring &str)
Adds a variable-length wstring to the datagram.
PTA_uchar modify_array()
Returns a modifiable pointer to the actual data in the Datagram.
void set_array(PTA_uchar data)
Replaces the data in the Datagram with the data in the indicated PTA_uchar.
void add_int64(int64_t value)
Adds a signed 64-bit integer to the datagram.
void add_be_int64(int64_t value)
Adds a signed 64-bit big-endian integer to the datagram.
void add_string32(const std::string &str)
Adds a variable-length string to the datagram, using a 32-bit length field to allow very long strings...
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void set_stdfloat_double(bool stdfloat_double)
Changes the stdfloat_double flag, which defines the operation performed by add_stdfloat() and Datagra...
void add_be_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
void add_bool(bool value)
Adds a boolean value to the datagram.
void add_be_float32(PN_float32 value)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
void add_be_uint16(uint16_t value)
Adds an unsigned 16-bit big-endian integer to the datagram.
const void * get_data() const
Returns the pointer to the first byte of the data, either reversed or nonreversed,...
void add_blob(const vector_uchar &)
Adds a variable-length binary blob to the datagram.
NativeNumericData and ReversedNumericData work together to provide a sneaky interface for automatical...
void add_be_int16(int16_t value)
Adds a signed 16-bit big-endian integer to the datagram.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
void add_be_uint32(uint32_t value)
Adds an unsigned 32-bit big-endian integer to the datagram.
NativeNumericData and ReversedNumericData work together to provide a sneaky interface for automatical...
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
void add_be_uint64(uint64_t value)
Adds an unsigned 64-bit big-endian integer to the datagram.
void copy_array(CPTA_uchar data)
Replaces the data in the Datagram with a copy of the data in the indicated CPTA_uchar.
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
std::string get_message() const
Returns the datagram's data as a string.
void add_fixed_string(const std::string &str, size_t size)
Adds a fixed-length string to the datagram.
void add_be_int32(int32_t value)
Adds a signed 32-bit big-endian integer to the datagram.
void add_uint64(uint64_t value)
Adds an unsigned 64-bit integer to the datagram.
const void * get_data() const
Returns the pointer to the first byte of the data, either reversed or nonreversed,...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
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.
void add_blob32(const vector_uchar &)
Adds a variable-length binary blob to the datagram, using a 32-bit length field to allow very long bl...