Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
src/blfwk/Blob.h
1 /*
2  * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #if !defined(_Blob_h_)
31 #define _Blob_h_
32 
33 #include "stdafx.h"
34 
42 class Blob
43 {
44 public:
46  Blob();
47 
49  Blob(const uint8_t *data, unsigned length);
50 
52  Blob(const Blob &other);
53 
55  virtual ~Blob();
56 
58 
59  void setData(const uint8_t *data, unsigned length);
61 
63  void setLength(unsigned length);
64 
66  void append(const uint8_t *newData, unsigned newDataLength);
67 
69  void clear();
70 
72  void relinquish();
74 
76 
77  uint8_t *getData() { return m_data; }
78  const uint8_t *getData() const { return m_data; }
79  unsigned getLength() const { return m_length; }
81 
83 
84  operator uint8_t *() { return m_data; }
85  operator const uint8_t *() const { return m_data; }
87 
88 protected:
89  uint8_t *m_data;
90  unsigned m_length;
91 };
92 
93 #endif // _Blob_h_
Blob()
Default constructor.
Definition: apps/elftosb/common/Blob.cpp:13
unsigned m_length
Number of bytes pointed to by m_data.
Definition: apps/elftosb/common/Blob.h:66
uint8_t * m_data
The binary data held by this object.
Definition: apps/elftosb/common/Blob.h:65
virtual ~Blob()
Destructor.
Definition: apps/elftosb/common/Blob.cpp:40
void setData(const uint8_t *data, unsigned length)
Replaces the blob's data.
Definition: apps/elftosb/common/Blob.cpp:54
void relinquish()
Tell the blob that it no longer owns its data.
Definition: apps/elftosb/common/Blob.cpp:118
void setLength(unsigned length)
Change the size of the blob's data.
Definition: apps/elftosb/common/Blob.cpp:66
void append(const uint8_t *newData, unsigned newDataLength)
Adds data to the end of the blob.
Definition: apps/elftosb/common/Blob.cpp:98
void clear()
Disposes of the data.
Definition: apps/elftosb/common/Blob.cpp:107
Manages a binary object of arbitrary length.
Definition: apps/elftosb/common/Blob.h:18