1*993229b6Sjkunz /* 2*993229b6Sjkunz * File: Blob.h 3*993229b6Sjkunz * 4*993229b6Sjkunz * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. 5*993229b6Sjkunz * See included license file for license details. 6*993229b6Sjkunz */ 7*993229b6Sjkunz #if !defined(_Blob_h_) 8*993229b6Sjkunz #define _Blob_h_ 9*993229b6Sjkunz 10*993229b6Sjkunz #include "stdafx.h" 11*993229b6Sjkunz 12*993229b6Sjkunz /*! 13*993229b6Sjkunz * \brief Manages a binary object of arbitrary length. 14*993229b6Sjkunz * 15*993229b6Sjkunz * The data block is allocated with malloc() instead of the new 16*993229b6Sjkunz * operator so that we can use realloc() to resize it. 17*993229b6Sjkunz */ 18*993229b6Sjkunz class Blob 19*993229b6Sjkunz { 20*993229b6Sjkunz public: 21*993229b6Sjkunz //! \brief Default constructor. 22*993229b6Sjkunz Blob(); 23*993229b6Sjkunz 24*993229b6Sjkunz //! \brief Constructor. 25*993229b6Sjkunz Blob(const uint8_t * data, unsigned length); 26*993229b6Sjkunz 27*993229b6Sjkunz //! \brief Copy constructor. 28*993229b6Sjkunz Blob(const Blob & other); 29*993229b6Sjkunz 30*993229b6Sjkunz //! \brief Destructor. 31*993229b6Sjkunz virtual ~Blob(); 32*993229b6Sjkunz 33*993229b6Sjkunz //! \name Operations 34*993229b6Sjkunz //@{ 35*993229b6Sjkunz //! \brief Replaces the blob's data. 36*993229b6Sjkunz void setData(const uint8_t * data, unsigned length); 37*993229b6Sjkunz 38*993229b6Sjkunz //! \brief Change the size of the blob's data. 39*993229b6Sjkunz void setLength(unsigned length); 40*993229b6Sjkunz 41*993229b6Sjkunz //! \brief Adds data to the end of the blob. 42*993229b6Sjkunz void append(const uint8_t * newData, unsigned newDataLength); 43*993229b6Sjkunz 44*993229b6Sjkunz //! \brief Disposes of the data. 45*993229b6Sjkunz void clear(); 46*993229b6Sjkunz 47*993229b6Sjkunz //! \brief Tell the blob that it no longer owns its data. 48*993229b6Sjkunz void relinquish(); 49*993229b6Sjkunz //@} 50*993229b6Sjkunz 51*993229b6Sjkunz //! \name Accessors 52*993229b6Sjkunz //@{ getData()53*993229b6Sjkunz uint8_t * getData() { return m_data; } getData()54*993229b6Sjkunz const uint8_t * getData() const { return m_data; } getLength()55*993229b6Sjkunz unsigned getLength() const { return m_length; } 56*993229b6Sjkunz //@} 57*993229b6Sjkunz 58*993229b6Sjkunz //! \name Operators 59*993229b6Sjkunz //@{ 60*993229b6Sjkunz operator uint8_t * () { return m_data; } 61*993229b6Sjkunz operator const uint8_t * () const { return m_data; } 62*993229b6Sjkunz //@} 63*993229b6Sjkunz 64*993229b6Sjkunz protected: 65*993229b6Sjkunz uint8_t * m_data; //!< The binary data held by this object. 66*993229b6Sjkunz unsigned m_length; //!< Number of bytes pointed to by #m_data. 67*993229b6Sjkunz }; 68*993229b6Sjkunz 69*993229b6Sjkunz #endif // _Blob_h_ 70*993229b6Sjkunz 71