more interfaces to get out the packed data

This commit is contained in:
David Rose 2004-07-02 17:26:02 +00:00
parent 3ac771804b
commit a5349528e9
3 changed files with 50 additions and 14 deletions

View File

@ -160,7 +160,9 @@ get_data() const {
// non-NULL. This may (or may not) return NULL if the // non-NULL. This may (or may not) return NULL if the
// buffer is empty. // 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:: INLINE char *DCPackData::
take_data() { take_data() {

View File

@ -617,17 +617,6 @@ get_num_unpacked_bytes() const {
return _unpack_p; 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 // Function: DCPacker::get_length
// Access: Published // Access: Published
@ -640,6 +629,28 @@ get_length() const {
return _pack_data.get_length(); 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 // Function: DCPacker::get_data
// Access: Public // Access: Public
@ -647,13 +658,34 @@ get_length() const {
// is not null-terminated, but see also get_string(). // is not null-terminated, but see also get_string().
// //
// This may be used in conjunction with get_length() to // 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:: INLINE const char *DCPacker::
get_data() const { get_data() const {
return _pack_data.get_data(); 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 // Function: DCPacker::append_data
// Access: Public // Access: Public

View File

@ -122,10 +122,12 @@ PUBLISHED:
INLINE bool had_error() const; INLINE bool had_error() const;
INLINE size_t get_num_unpacked_bytes() const; INLINE size_t get_num_unpacked_bytes() const;
INLINE string get_string() const;
INLINE size_t get_length() const; INLINE size_t get_length() const;
INLINE string get_string() const;
public: public:
INLINE void get_string(string &data) const;
INLINE const char *get_data() const; INLINE const char *get_data() const;
INLINE char *take_data();
INLINE void append_data(const char *buffer, size_t size); INLINE void append_data(const char *buffer, size_t size);
INLINE char *get_write_pointer(size_t size); INLINE char *get_write_pointer(size_t size);