From a5349528e903d8dfce8d6d5c796de9be26b6ecf1 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 2 Jul 2004 17:26:02 +0000 Subject: [PATCH] more interfaces to get out the packed data --- direct/src/dcparser/dcPackData.I | 4 ++- direct/src/dcparser/dcPacker.I | 56 +++++++++++++++++++++++++------- direct/src/dcparser/dcPacker.h | 4 ++- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/direct/src/dcparser/dcPackData.I b/direct/src/dcparser/dcPackData.I index 4d5653d05b..781cda2710 100755 --- a/direct/src/dcparser/dcPackData.I +++ b/direct/src/dcparser/dcPackData.I @@ -160,7 +160,9 @@ get_data() const { // non-NULL. This may (or may not) return NULL if the // buffer is empty. // -// This also empties the DCPackData structure. +// This also empties the DCPackData structure, and sets +// its length to zero (so you should call get_length() +// before calling this method). //////////////////////////////////////////////////////////////////// INLINE char *DCPackData:: take_data() { diff --git a/direct/src/dcparser/dcPacker.I b/direct/src/dcparser/dcPacker.I index 28396b029c..c74c72bc78 100755 --- a/direct/src/dcparser/dcPacker.I +++ b/direct/src/dcparser/dcPacker.I @@ -617,17 +617,6 @@ get_num_unpacked_bytes() const { return _unpack_p; } -//////////////////////////////////////////////////////////////////// -// Function: DCPacker::get_string -// Access: Published -// Description: Returns the packed data buffer as a string. Also see -// get_data(). -//////////////////////////////////////////////////////////////////// -INLINE string DCPacker:: -get_string() const { - return _pack_data.get_string(); -} - //////////////////////////////////////////////////////////////////// // Function: DCPacker::get_length // Access: Published @@ -640,6 +629,28 @@ get_length() const { return _pack_data.get_length(); } +//////////////////////////////////////////////////////////////////// +// Function: DCPacker::get_string +// Access: Published +// Description: Returns the packed data buffer as a string. Also see +// get_data(). +//////////////////////////////////////////////////////////////////// +INLINE string DCPacker:: +get_string() const { + return _pack_data.get_string(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCPacker::get_string +// Access: Published +// Description: Copies the packed data into the indicated string. +// Also see get_data(). +//////////////////////////////////////////////////////////////////// +INLINE void DCPacker:: +get_string(string &data) const { + data.assign(_pack_data.get_data(), _pack_data.get_length()); +} + //////////////////////////////////////////////////////////////////// // Function: DCPacker::get_data // Access: Public @@ -647,13 +658,34 @@ get_length() const { // is not null-terminated, but see also get_string(). // // This may be used in conjunction with get_length() to -// copy all of the bytes out of the buffer. +// copy all of the bytes out of the buffer. Also see +// take_data() to get the packed data without a copy +// operation. //////////////////////////////////////////////////////////////////// INLINE const char *DCPacker:: get_data() const { return _pack_data.get_data(); } +//////////////////////////////////////////////////////////////////// +// Function: DCPacker::take_data +// Access: Public +// Description: Returns the pointer to the beginning of the data +// buffer, and transfers ownership of the buffer to the +// caller. The caller is now responsible for ultimately +// freeing the returned pointer with delete[], if it is +// non-NULL. This may (or may not) return NULL if the +// buffer is empty. +// +// This also empties the DCPackData structure, and sets +// its length to zero (so you should call get_length() +// before calling this method). +//////////////////////////////////////////////////////////////////// +INLINE char *DCPacker:: +take_data() { + return _pack_data.take_data(); +} + //////////////////////////////////////////////////////////////////// // Function: DCPacker::append_data // Access: Public diff --git a/direct/src/dcparser/dcPacker.h b/direct/src/dcparser/dcPacker.h index c85acf8270..6907aabcbc 100755 --- a/direct/src/dcparser/dcPacker.h +++ b/direct/src/dcparser/dcPacker.h @@ -122,10 +122,12 @@ PUBLISHED: INLINE bool had_error() const; INLINE size_t get_num_unpacked_bytes() const; - INLINE string get_string() const; INLINE size_t get_length() const; + INLINE string get_string() const; public: + INLINE void get_string(string &data) const; INLINE const char *get_data() const; + INLINE char *take_data(); INLINE void append_data(const char *buffer, size_t size); INLINE char *get_write_pointer(size_t size);