mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
add unpack-by-reference
This commit is contained in:
parent
d86367d609
commit
3a10107f80
@ -402,6 +402,135 @@ unpack_literal_value() {
|
||||
return string(_unpack_data + start, _unpack_p - start);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DCPacker::unpack_double
|
||||
// Access: Public
|
||||
// Description: Unpacks the current numeric or string value from the
|
||||
// stream.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void DCPacker::
|
||||
unpack_double(double &value) {
|
||||
nassertv(_mode == M_unpack);
|
||||
if (_current_field == NULL) {
|
||||
_pack_error = true;
|
||||
|
||||
} else {
|
||||
_current_field->unpack_double(_unpack_data, _unpack_length, _unpack_p,
|
||||
value, _pack_error, _range_error);
|
||||
advance();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DCPacker::unpack_int
|
||||
// Access: Public
|
||||
// Description: Unpacks the current numeric or string value from the
|
||||
// stream.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void DCPacker::
|
||||
unpack_int(int &value) {
|
||||
nassertv(_mode == M_unpack);
|
||||
if (_current_field == NULL) {
|
||||
_pack_error = true;
|
||||
|
||||
} else {
|
||||
_current_field->unpack_int(_unpack_data, _unpack_length, _unpack_p,
|
||||
value, _pack_error, _range_error);
|
||||
advance();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DCPacker::unpack_uint
|
||||
// Access: Public
|
||||
// Description: Unpacks the current numeric or string value from the
|
||||
// stream.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void DCPacker::
|
||||
unpack_uint(unsigned int &value) {
|
||||
nassertv(_mode == M_unpack);
|
||||
if (_current_field == NULL) {
|
||||
_pack_error = true;
|
||||
|
||||
} else {
|
||||
_current_field->unpack_uint(_unpack_data, _unpack_length, _unpack_p,
|
||||
value, _pack_error, _range_error);
|
||||
advance();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DCPacker::unpack_int64
|
||||
// Access: Public
|
||||
// Description: Unpacks the current numeric or string value from the
|
||||
// stream.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void DCPacker::
|
||||
unpack_int64(PN_int64 &value) {
|
||||
nassertv(_mode == M_unpack);
|
||||
if (_current_field == NULL) {
|
||||
_pack_error = true;
|
||||
|
||||
} else {
|
||||
_current_field->unpack_int64(_unpack_data, _unpack_length, _unpack_p,
|
||||
value, _pack_error, _range_error);
|
||||
advance();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DCPacker::unpack_uint64
|
||||
// Access: Public
|
||||
// Description: Unpacks the current numeric or string value from the
|
||||
// stream.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void DCPacker::
|
||||
unpack_uint64(PN_uint64 &value) {
|
||||
nassertv(_mode == M_unpack);
|
||||
if (_current_field == NULL) {
|
||||
_pack_error = true;
|
||||
|
||||
} else {
|
||||
_current_field->unpack_uint64(_unpack_data, _unpack_length, _unpack_p,
|
||||
value, _pack_error, _range_error);
|
||||
advance();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DCPacker::unpack_string
|
||||
// Access: Public
|
||||
// Description: Unpacks the current numeric or string value from the
|
||||
// stream.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void DCPacker::
|
||||
unpack_string(string &value) {
|
||||
nassertv(_mode == M_unpack);
|
||||
if (_current_field == NULL) {
|
||||
_pack_error = true;
|
||||
|
||||
} else {
|
||||
_current_field->unpack_string(_unpack_data, _unpack_length, _unpack_p,
|
||||
value, _pack_error, _range_error);
|
||||
advance();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DCPacker::unpack_literal_value
|
||||
// Access: Public
|
||||
// Description: Returns the literal string that represents the packed
|
||||
// value of the current field, and advances the field
|
||||
// pointer.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void DCPacker::
|
||||
unpack_literal_value(string &value) {
|
||||
size_t start = _unpack_p;
|
||||
unpack_skip();
|
||||
nassertv(_unpack_p >= start);
|
||||
value.assign(_unpack_data + start, _unpack_p - start);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DCPacker::had_pack_error
|
||||
// Access: Published
|
||||
|
@ -689,7 +689,8 @@ unpack_object() {
|
||||
|
||||
case PT_string:
|
||||
{
|
||||
string str = unpack_string();
|
||||
string str;
|
||||
unpack_string(str);
|
||||
object = PyString_FromStringAndSize(str.data(), str.size());
|
||||
}
|
||||
break;
|
||||
|
@ -92,6 +92,19 @@ PUBLISHED:
|
||||
void unpack_validate();
|
||||
void unpack_skip();
|
||||
|
||||
public:
|
||||
// The following are variants on the above unpack() calls that pass
|
||||
// the result back by reference instead of as a return value.
|
||||
INLINE void unpack_double(double &value);
|
||||
INLINE void unpack_int(int &value);
|
||||
INLINE void unpack_uint(unsigned int &value);
|
||||
INLINE void unpack_int64(PN_int64 &value);
|
||||
INLINE void unpack_uint64(PN_uint64 &value);
|
||||
INLINE void unpack_string(string &value);
|
||||
INLINE void unpack_literal_value(string &value);
|
||||
|
||||
PUBLISHED:
|
||||
|
||||
#ifdef HAVE_PYTHON
|
||||
void pack_object(PyObject *object);
|
||||
PyObject *unpack_object();
|
||||
|
@ -1620,7 +1620,7 @@ unpack_string(const char *data, size_t length, size_t &p, string &value,
|
||||
pack_error = true;
|
||||
return;
|
||||
}
|
||||
value = string(data + p, string_length);
|
||||
value.assign(data + p, string_length);
|
||||
p += string_length;
|
||||
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user