1- ![ bin2cpp logo] ( http://www.end2endzone.com/wp-content/uploads/2015/01/bin2cpp-featured-image.png )
1+ ![ bin2cpp logo] ( http://github.com/end2endzone/bin2cpp/blob/master/docs/bin2cpp-splashscreen.png )] ( http://github.com/end2endzone/bin2cpp/blob/master/docs/bin2cpp-splashscreen.png )
2+
23
34[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
45[ ![ Github Releases] ( https://img.shields.io/github/release/end2endzone/bin2cpp.svg )] ( https://github.com/end2endzone/bin2cpp/releases )
@@ -30,18 +31,34 @@ It is designed to be easy to use by developers and to provide easy call function
3031The generated functions that reads and extracts the embedded content does not rely on external libraries so you don't need to setup your projects to use any third party library to start using bin2cpp. All your embedded data can be accessed right away.
3132
3233# Command Line Usage
34+ ```
35+ bin2cpp v2.0.0 - Convert binary files into C++ source code.
36+ Copyright (C) 2013-2018 end2endzone.com. All rights reserved.
37+ bin2cpp is open source software, see http://github.com/end2endzone/bin2cpp
38+ Usage:
39+ bin2cpp --file=<path> --output=<path> --headerfile=<name> --identifier=<name>
40+ [--generator=<name>] [--encoding=<name>] [--chunksize=<value>] [--namespace=<value>]
41+ [--baseclass=<value>] [--override] [--noheader] [--quiet]
42+ bin2cpp --help
43+ bin2cpp --version
44+ ```
3345
34- ** Usage:** bin2cpp --file=/path/to/file --output=/path/to/output/folder --headerfile=name.h --identifier=value --chunksize=value --override.
35-
36- | Argument | Description |
37- | ---------------------| ------------------------------------------------------------------------------------------------|
38- | --file | Path of the input file used for embedding as a C++ source code. |
39- | --output | Output folder where to create generated code. ie: .\\ generated_file |
40- | --headerfile | File name of the generated C++ Header file. ie: SplashScreen.h |
41- | --identifier | Identifier of the function name that is used to get an instance of the file. ie: SplashScreen |
42- | --chunksize | Size in bytes of each string segments (bytes per row). Defaults to 200. |
43- | --override | Tells bin2cpp to over write the destination files. |
44-
46+ | Argument | Description |
47+ | ----------------------| ------------------------------------------------------------------------------------------------------------|
48+ | --help | Display this help message. |
49+ | --version | Display this application version. |
50+ | --file=\< path> | Path of the input file used for embedding as a C++ source code. |
51+ | --output=\< path> | Output folder where to create generated code. ie: .\generated_files |
52+ | --headerfile=\< name> | File name of the generated C++ Header file. ie: SplashScreen.h |
53+ | --generator=\< name> | Name of the generator to use. Possible values are 'segment', 'string' and 'array'. [ default: segment] . |
54+ | --encoding=\< name> | Name of the binary to string literal encoding to use. Possible values are 'oct' and 'hex'. [ default: oct] . |
55+ | --identifier=\< name> | Identifier of the function name that is used to get an instance of the file. ie: SplashScreen |
56+ | --chunksize=\< value> | Size in bytes of each string segments (bytes per row). [ default: 200] . |
57+ | --baseclass=\< value> | The name of the interface for embedded files. [ default: File] . |
58+ | --namespace=\< value> | The namespace of the generated source code [ default: bin2cpp] . |
59+ | --override | Tells bin2cpp to overwrite the destination files. |
60+ | --noheader | Do not print program header to standard output. |
61+ | --quiet | Do not log any message to standard output. |
4562
4663# Example
4764
@@ -63,42 +80,43 @@ Hello World!
6380
6481### Command:
6582``` batchfile
66- bin2cpp.exe --file=html5skeleton.html --output=.\outdir --headerfile=resourcehtml5skeleton.h --identifier=HtmlSample --chunksize=50 --override
83+ bin2cpp.exe --file=html5skeleton.html --output=.\outdir --headerfile=resourcehtml5skeleton.h
84+ --identifier=HtmlSample --chunksize=50
6785```
6886
6987### Console output
7088
7189``` batchfile
72- bin2cpp v2.0
73- Copyright (C) 2013-2017 end2endzone.com. All rights reserved.
74- Embedding "html5skeleton.html" into "resourcehtml5skeleton.h"...
75- Done.
90+ bin2cpp v2.0.0 - Convert binary files into C++ source code.
91+ Copyright (C) 2013-2018 end2endzone.com. All rights reserved.
92+ bin2cpp is open source software, see http://github.com/end2endzone/bin2cpp
93+ Embedding "html5skeleton.html" using chunks of 50 bytes...
94+ Writing file ".\outdir\resourcehtml5skeleton.h"...
95+ Writing file ".\outdir\resourcehtml5skeleton.cpp"...
7696```
7797
7898### File resourcehtml5skeleton.h
7999
80100``` cpp
81101/* *
82- * This file was generated by bin2cpp v2.0.
83- * Copyright (C) 2013-2017 end2endzone.com. All rights reserved.
102+ * This file was generated by bin2cpp v2.0.0
103+ * Copyright (C) 2013-2018 end2endzone.com. All rights reserved.
104+ * bin2cpp is open source software, see http://github.com/end2endzone/bin2cpp
105+ * Source code for file 'html5skeleton.html', last modified 1513117337.
84106 * Do not modify this file.
85107 */
86108#pragma once
87109#include < stddef.h>
88110namespace bin2cpp
89111{
90- #ifndef BIN2CPP_EMBEDEDFILE_CLASS
91- #define BIN2CPP_EMBEDEDFILE_CLASS
112+ #ifndef BIN2CPP_EMBEDDEDFILE_CLASS
113+ #define BIN2CPP_EMBEDDEDFILE_CLASS
92114 class File
93115 {
94116 public:
95117 virtual size_t getSize() const = 0;
96- virtual size_t getSegmentSize() const = 0;
97- virtual size_t getNumSegments() const = 0;
98118 virtual const char * getFilename() const = 0;
99- virtual const char * getSegment(size_t iIndex, size_t & oLength) const = 0;
100- virtual const char * getMd5() const = 0;
101- virtual char * newBuffer() const = 0;
119+ virtual const char * getBuffer() const = 0;
102120 virtual bool save(const char * iFilename) const = 0;
103121 };
104122 #endif
@@ -110,8 +128,10 @@ namespace bin2cpp
110128
111129``` cpp
112130/* *
113- * This file was generated by bin2cpp v2.0.
114- * Copyright (C) 2013-2017 end2endzone.com. All rights reserved.
131+ * This file was generated by bin2cpp v2.0.0
132+ * Copyright (C) 2013-2018 end2endzone.com. All rights reserved.
133+ * bin2cpp is open source software, see http://github.com/end2endzone/bin2cpp
134+ * Source code for file 'html5skeleton.html', last modified 1513117337.
115135 * Do not modify this file.
116136 */
117137#include " resourcehtml5skeleton.h"
@@ -122,59 +142,33 @@ namespace bin2cpp
122142 class HtmlSampleFile : public virtual bin2cpp::File
123143 {
124144 public:
125- HtmlSampleFile() {}
145+ HtmlSampleFile() { build(); }
126146 ~ HtmlSampleFile() {}
127147 virtual size_t getSize() const { return 238; }
128- virtual size_t getSegmentSize() const { return 200; }
129- virtual size_t getNumSegments() const { return 2; }
130148 virtual const char * getFilename() const { return "html5skeleton.html"; }
131- virtual const char * getSegment(size_t iIndex, size_t & oLength) const
149+ virtual const char * getBuffer() const { return mBuffer.c_str(); }
150+ void build()
132151 {
133- oLength = 0;
134- if (iIndex >= getNumSegments())
135- return NULL;
136- const char * buffer = NULL;
137- size_t index = 0;
138- oLength = getSegmentSize();
139- buffer = "<! DOCTYPE html> \r\n<html lang=\" en\" >\r\n<head >\r\n <meta charset=\" utf-8\" >\r\n <meta name=\" viewport\" content=\" width=device-width, initial-scale=1, user-scalable=yes\" >\r\n <title >Hello World!</title >\r\n</head >\r\n"; if (iIndex == index) return buffer; index++;
140- oLength = 38;
141- buffer = "<body >\r\nHello World!\r\n</body >\r\n</html >"; if (iIndex == index) return buffer; index++;
142- oLength = 0;
143- return NULL;
144- }
145- virtual const char * getMd5() const { return "85f80d7db80c1a4392dc32ecb429a8a9"; }
146- virtual char * newBuffer() const
147- {
148- size_t size = getSize();
149- char * buffer = new char[ size] ;
150- if (buffer == NULL)
151- return NULL;
152- size_t numSegments = getNumSegments();
153- size_t segmentLength = 0;
154- size_t index = 0;
155- for(size_t i=0; i<numSegments; i++)
156- {
157- const char * segmentBuffer = getSegment(i, segmentLength);
158- memcpy(&buffer[ index] , segmentBuffer, segmentLength);
159- index += segmentLength;
160- }
161- return buffer;
152+ mBuffer.clear();
153+ mBuffer.reserve(getSize()); //allocate all required memory at once to prevent reallocations
154+ mBuffer.append("<! DOCTYPE html> \r\n<html lang=\" en\" >\r\n<head >\r\n <meta", 50);
155+ mBuffer.append(" charset=\" utf-8\" >\r\n <meta name=\" viewport\" content", 50);
156+ mBuffer.append("=\" width=device-width, initial-scale=1, user-scalab", 50);
157+ mBuffer.append("le=yes\" >\r\n <title >Hello World!</title >\r\n</head >\r\n", 50);
158+ mBuffer.append("<body >\r\nHello World!\r\n</body >\r\n</html >", 38);
162159 }
163160 virtual bool save(const char * iFilename) const
164161 {
165162 FILE * f = fopen(iFilename, "wb");
166163 if (!f) return false;
167- size_t numSegments = getNumSegments();
168- size_t segmentLength = 0;
169- const char * buffer = NULL;
170- for(size_t i=0; i<numSegments; i++)
171- {
172- buffer = getSegment(i, segmentLength);
173- fwrite(buffer, 1, segmentLength, f);
174- }
164+ size_t fileSize = getSize();
165+ const char * buffer = getBuffer();
166+ fwrite(buffer, 1, fileSize, f);
175167 fclose(f);
176168 return true;
177169 }
170+ private:
171+ std::string mBuffer;
178172 };
179173 const File & getHtmlSampleFile() { static HtmlSampleFile _ instance; return _ instance; }
180174}; // bin2cpp
@@ -184,7 +178,6 @@ namespace bin2cpp
184178``` cpp
185179#include < stdio.h>
186180#include < string>
187- #include " base64.h"
188181#include " resourcehtml5skeleton.h" // a single include file is all you need
189182
190183int main (int argc, char* argv[ ] )
@@ -194,7 +187,6 @@ int main(int argc, char* argv[])
194187
195188 //print information about the file.
196189 printf("Embedded file '%s' is %d bytes long.\n", resource.getFilename(), resource.getSize());
197- printf("The MD5 of the file is %s.\n", resource.getMd5());
198190
199191 //Saving content back to a file.
200192 printf("Saving embedded file to 'html5skeleton_copy.html'...\n");
@@ -204,16 +196,11 @@ int main(int argc, char* argv[])
204196 else
205197 printf("failed\n");
206198
207- //encoding content as base64
208- char * buffer = resource.newBuffer (); //returns a new buffer with a copy of the file. Ownership is transfered to the local function
199+ //Get the internal buffer and do something with the binary data
200+ const char * buffer = resource.getBuffer ();
209201 size_t bufferSize = resource.getSize();
210- std::string encodedFile = toBase64(buffer, bufferSize); //binary to base64 encoder
211- delete buffer; //delete allocatd buffer from newBuffer()
212- buffer = NULL;
213-
214- //do something with the base64 encoded file
215202 //...
216-
203+
217204 return 0;
218205}
219206```
@@ -243,10 +230,9 @@ See also the latest test results at the beginning of the document.
243230
244231# Screenshots
245232
246- bin2cpp v1.3 Sample [](http://www.end2endzone. com/wp-content/uploads/2015/01/ bin2cpp-v1.3-done .png)
233+ [](http://github. com/end2endzone/bin2cpp/blob/master/docs/ bin2cpp-v2.0.0-sample .png)
247234
248- bin2cpp v1.3 Usage
249- [](http://www.end2endzone.com/wp-content/uploads/2015/01/bin2cpp-v1.3-usage.png)
235+ bin2cpp v2.0.0 Sample
250236
251237# Compatible with
252238
0 commit comments