add string32 (for dc blob32 field)
This commit is contained in:
parent
a65b6110bb
commit
4a276d04cb
|
|
@ -311,6 +311,21 @@ add_string(const string &str) {
|
|||
append_data(str);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Datagram::add_string32
|
||||
// Access: Public
|
||||
// Description: Adds a variable-length string to the datagram, using
|
||||
// a 32-bit length field to allow very long strings.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void Datagram::
|
||||
add_string32(const string &str) {
|
||||
// Strings always are preceded by their length
|
||||
add_uint32(str.length());
|
||||
|
||||
// Add the string
|
||||
append_data(str);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Datagram::add_z_string
|
||||
// Access: Public
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ PUBLISHED:
|
|||
INLINE void add_be_float64(PN_float64 value);
|
||||
|
||||
INLINE void add_string(const string &str);
|
||||
INLINE void add_string32(const string &str);
|
||||
INLINE void add_z_string(string str);
|
||||
INLINE void add_fixed_string(const string &str, size_t size);
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,28 @@ get_string() {
|
|||
return string(ptr + last_index, s_len);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DatagramIterator::get_string32
|
||||
// Access: Public
|
||||
// Description: Extracts a variable-length string with a 32-bit
|
||||
// length field.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
string DatagramIterator::
|
||||
get_string32() {
|
||||
// First, get the length of the string
|
||||
PN_uint32 s_len = get_uint32();
|
||||
|
||||
nassertr(_datagram != (const Datagram *)NULL &&
|
||||
_current_index + s_len <= _datagram->get_length(), "");
|
||||
|
||||
const char *ptr = (const char *)_datagram->get_data();
|
||||
int last_index = _current_index;
|
||||
|
||||
_current_index += s_len;
|
||||
|
||||
return string(ptr + last_index, s_len);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DatagramIterator::get_z_string
|
||||
// Access: Public
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ PUBLISHED:
|
|||
INLINE PN_float64 get_be_float64();
|
||||
|
||||
string get_string();
|
||||
string get_string32();
|
||||
string get_z_string();
|
||||
string get_fixed_string(size_t size);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,27 @@ get_string() {
|
|||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: StreamReader::get_string32
|
||||
// Access: Published
|
||||
// Description: Extracts a variable-length string with a 32-bit
|
||||
// length field.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
string StreamReader::
|
||||
get_string32() {
|
||||
nassertr(!_in->eof() && !_in->fail(), string());
|
||||
|
||||
// First, get the length of the string
|
||||
size_t s_len = get_uint32();
|
||||
|
||||
string result;
|
||||
result.reserve(s_len);
|
||||
for (size_t p = 0; !_in->eof() && !_in->fail() && p < s_len; p++) {
|
||||
result += _in->get();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: StreamReader::get_z_string
|
||||
// Access: Published
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ PUBLISHED:
|
|||
INLINE PN_float64 get_be_float64();
|
||||
|
||||
string get_string();
|
||||
string get_string32();
|
||||
string get_z_string();
|
||||
string get_fixed_string(size_t size);
|
||||
|
||||
|
|
|
|||
|
|
@ -324,6 +324,21 @@ add_string(const string &str) {
|
|||
append_data(str);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: StreamWriter::add_string32
|
||||
// Access: Public
|
||||
// Description: Adds a variable-length string to the stream, using a
|
||||
// 32-bit length field.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void StreamWriter::
|
||||
add_string32(const string &str) {
|
||||
// Strings always are preceded by their length
|
||||
add_uint32(str.length());
|
||||
|
||||
// Add the string
|
||||
append_data(str);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: StreamWriter::add_z_string
|
||||
// Access: Public
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ PUBLISHED:
|
|||
INLINE void add_be_float64(PN_float64 value);
|
||||
|
||||
INLINE void add_string(const string &str);
|
||||
INLINE void add_string32(const string &str);
|
||||
INLINE void add_z_string(string str);
|
||||
INLINE void add_fixed_string(const string &str, size_t size);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue