4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
19 //! Makes a local copy of the \a data argument.
21 Blob::Blob(const uint8_t * data, unsigned length)
25 m_data = reinterpret_cast<uint8_t*>(malloc(length));
26 memcpy(m_data, data, length);
29 //! Makes a local copy of the data owned by \a other.
31 Blob::Blob(const Blob & other)
33 m_length(other.m_length)
35 m_data = reinterpret_cast<uint8_t *>(malloc(m_length));
36 memcpy(m_data, other.m_data, m_length);
39 //! Disposes of the binary data associated with this object.
48 //! Copies \a data onto the blob's data. The blob does not assume ownership
51 //! \param data Pointer to a buffer containing the data which will be copied
53 //! \param length Number of bytes pointed to by \a data.
54 void Blob::setData(const uint8_t * data, unsigned length)
57 memcpy(m_data, data, length);
60 //! Sets the #m_length member variable to \a length and resizes #m_data to
61 //! the new length. The contents of #m_data past any previous contents are undefined.
62 //! If the new \a length is 0 then the data will be freed and a subsequent call
63 //! to getData() will return NULL.
65 //! \param length New length of the blob's data in bytes.
66 void Blob::setLength(unsigned length)
74 // Allocate new block.
77 m_data = reinterpret_cast<uint8_t*>(malloc(length));
80 throw std::runtime_error("failed to allocate memory");
83 // Reallocate previous block.
86 void * newBlob = realloc(m_data, length);
89 throw std::runtime_error("failed to reallocate memory");
91 m_data = reinterpret_cast<uint8_t*>(newBlob);
98 void Blob::append(const uint8_t * newData, unsigned newDataLength)
100 unsigned oldLength = m_length;
102 setLength(m_length + newDataLength);
104 memcpy(m_data + oldLength, newData, newDataLength);
118 void Blob::relinquish()