NDEVR
API Documentation
BinaryFile.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: BinaryFile
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/File.h>
35#include <NDEVR/String.h>
36#include <NDEVR/Dictionary.h>
37#include <NDEVR/Bounds.h>
38#include <NDEVR/Compressor.h>
39#include <fstream>
40#include <cstddef>
41#include <type_traits>
42namespace NDEVR
43{
44#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__)
45#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
46 static constexpr bool kNativeLittleEndian = true;
47#elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
48 static constexpr bool kNativeLittleEndian = false;
49#else
50#error Unsupported native endianness
51#endif
52
53#elif defined(_WIN32) || defined(_WIN64)
54 static constexpr bool kNativeLittleEndian = true;
55
56#elif defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__x86_64__)
57 static constexpr bool kNativeLittleEndian = true;
58
59#elif defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM) || defined(_M_ARM64)
60 static constexpr bool kNativeLittleEndian = true;
61
62#elif defined(__ARMEB__) || defined(__AARCH64EB__)
63 static constexpr bool kNativeLittleEndian = false;
64
65#else
66#error Cannot determine endianness at compile time on this platform (C++17)
67#endif
68
74 template <class T>
75 constexpr T ByteSwap(T v) noexcept
76 {
77 static_assert(std::is_integral<T>::value, "T must be an integral type");
78 static_assert(!std::is_same<T, bool>::value, "bool is not supported");
79
80 using U = typename std::make_unsigned<T>::type;
81 U x = static_cast<U>(v);
82 U y = 0;
83
84 for (std::size_t i = 0; i < sizeof(T); ++i)
85 {
86 y = (y << 8) | (x & static_cast<U>(0xFF));
87 x >>= 8;
88 }
89
90 return static_cast<T>(y);
91 }
92
98 template <class T>
99 constexpr T _LE(T v) noexcept
100 {
101 static_assert(std::is_integral<T>::value, "T must be an integral type");
102 static_assert(!std::is_same<T, bool>::value, "bool is not supported");
103
104 return kNativeLittleEndian ? v : ByteSwap(v);
105 }
106
112 template <class T>
113 constexpr T _BE(T v) noexcept
114 {
115 static_assert(std::is_integral<T>::value, "T must be an integral type");
116 static_assert(!std::is_same<T, bool>::value, "bool is not supported");
117
118 return kNativeLittleEndian ? ByteSwap(v) : v;
119 }
120
124 template <class t_type>
125 constexpr t_type ChangeEndian(t_type in)
126 {
127 return ByteSwap(in);
128 }
129
135 class NDEVR_BASE_API BinaryFile
136 {
137 public:
138
143 explicit BinaryFile(const File& file)
144 : m_file(file)
145 {}
146
149 explicit BinaryFile()
150 : m_file()
151 , m_cache_location(0U)
152 , m_using_cache(true)
153 , m_is_read(false)
154 {}
155
159 explicit BinaryFile(const HighCapacityBuffer<uint01>& data)
160 : m_cached_data(data)
161 , m_cache_location(0U)
162 , m_using_cache(true)
163 , m_is_read(false)
164 {}
165
169 explicit BinaryFile(HighCapacityBuffer<uint01>&& data)
170 : m_cached_data(std::move(data))
171 , m_cache_location(0U)
172 , m_using_cache(true)
173 , m_is_read(false)
174 {
175 }
176
181 explicit BinaryFile(const uint01* data, uint08 size)
182 : m_cache_location(0U)
183 , m_using_cache(true)
184 , m_is_read(false)
185 {
186 m_cached_data.addAll(data, size);
187 }
188
192 explicit BinaryFile(const Buffer<uint01>& data)
193 : m_cache_location(0U)
194 , m_using_cache(true)
195 , m_is_read(false)
196 {
197 m_cached_data.addAll(data);
198 }
199
203 BinaryFile(BinaryFile&& bf) noexcept;
214 {
215 close();
216 }
217
222 void open(bool read, bool safe);
227 void cachedOpen(bool read);
231 void close();
236 const HighCapacityBuffer<uint01>& cachedData() const
237 {
238 return m_cached_data;
239 }
240
244 HighCapacityBuffer<uint01>& cachedData()
245 {
246 return m_cached_data;
247 }
248
252 //Data writing
253 template<class t_type>
254 typename std::enable_if<!ObjectInfo<t_type>::Buffer>::type write(const t_type& data)
255 {
256 writeDirect((uint01*)&data, sizeof(t_type));
257 }
258
264 template<class t_type, class t_memory_manager>
265 typename std::enable_if<!ObjectInfo<t_type>::Buffer>::type write(const Buffer<t_type, t_memory_manager>& data, CompressionMode compression_mode = CompressionMode::e_no_compression)
266 {
267 if (data.size() != 0)
268 {
270 binary.buffer_size = data.size();
273 binary.uncompressed_data = (uint01*)data.ptr();
274 binary.uncompressed_size = data.memSize();
276 {
277 m_compressed_data.setSize(sizeof(Bounds<1, uint04>));
278 binary.compressed_size = sizeof(Bounds<1, uint04>);
279 }
280 else if (binary.compression_mode == e_string_reference)
281 {
282 m_compressed_data.clear();
283 binary.compressed_size = 0;
284 }
285 else
286 {
287 m_compressed_data.setSize(data.memSize());
288 binary.compressed_size = data.memSize();
289 }
290 binary.compressed_data = m_compressed_data.begin();
292 writeCompression(binary);
293 }
294 else
295 {
296 //lib_assert(m_large_compression || cast<uint08>(data.size()) < cast<uint08>(cast<uint04>::Max), "Bad Data write");
298 write(cast<uint08>(data.size()));
299 else
300 write(cast<uint04>(data.size()));
301 }
302 }
303
308 template<class t_type, class t_memory_manager>
309 typename std::enable_if<ObjectInfo<t_type>::Buffer>::type write(const Buffer<t_type, t_memory_manager>& data, CompressionMode compression_mode)
310 {
311 uint04 total_size = 0;
312 Buffer<uint04> sizes;
313 sizes.setSize(data.size());
314 for (uint04 i = 0; i < data.size(); i++)
315 {
316 uint04 size = data[i].size();;
317 sizes[i] = size;
318 total_size += size;
319 }
320 Buffer<decltype(t_type::Type())> combined_data(total_size);
321 for (uint04 i = 0; i < data.size(); i++)
322 {
323 combined_data.addAll(data[i]);
324 }
325 write(sizes, compression_mode);
326 write(combined_data, compression_mode);
327 }
328
333 void write(const StringView& data, CompressionMode compression_mode)
334 {
335 if (data.size() != 0)
336 {
338 binary.buffer_size = data.size();
341 binary.uncompressed_data = (uint01*)data.begin();
342 binary.uncompressed_size = data.size();
344 {
345 m_compressed_data.setSize(sizeof(Bounds<1, uint04>));
346 binary.compressed_size = sizeof(Bounds<1, uint04>);
347 }
348 else if (binary.compression_mode == e_string_reference)
349 {
350 m_compressed_data.clear();
351 binary.compressed_size = 0;
352 }
353 else
354 {
355 m_compressed_data.setSize(data.size());
356 binary.compressed_size = data.size();
357 }
358 binary.compressed_data = m_compressed_data.begin();
360 writeCompression(binary);
361 }
362 else
363 {
364 //lib_assert(m_large_compression || cast<uint08>(data.size()) < cast<uint08>(cast<uint04>::Max), "Bad Data write");
366 write(cast<uint08>(data.size()));
367 else
368 write(cast<uint04>(data.size()));
369 }
370 }
371
376 void writeDirect(const uint01* ptr, uint08 size);
390 void writeRawData(const StringView& data, uint04 size, char fill_space = '\0')
391 {
392 if (m_using_cache)
393 {
394
395 if (m_cache_location == m_cached_data.size())
396 m_cached_data.addAll((uint01*)data.begin(), getMin(data.size(), size));
397 else
398 m_cached_data.setAll((uint01*)data.begin(), m_cache_location, getMin(data.size(), size));
399 m_cache_location += getMin(data.size(), size);
400 if (size > data.size())
401 {
402 uint04 add_size = size - data.size();
403 if (m_cache_location == m_cached_data.size())
404 m_cached_data.setAllToValue(fill_space, m_cache_location, add_size);
405 else
406 m_cached_data.addAndFillSpace(add_size, fill_space);
407 m_cache_location += add_size;
408 }
409
410 }
411 else
412 {
413 fwrite(data.begin(), data.size(), 1, m_file.filePtr());
414 if (size > data.size())
415 {
416 uint04 add_size = size - data.size();
417 for(uint04 i = 0; i < add_size; i++)
418 fwrite(&fill_space, add_size, 1, m_file.filePtr());
419 }
420 }
421 }
422
426 template<class t_type>
427 [[nodiscard]] bool canRead() const
428 {
429 if (m_using_cache)
430 return m_cache_location + sizeof(t_type) <= m_cached_data.size();
431 else
432 return position() + sizeof(t_type) <= m_file.size();
433
434 }
435
439 //data reading
440 template<class t_type>
441 [[nodiscard]] t_type read()
442 {
443 t_type data;
444 if (m_using_cache)
445 {
446 data = *((t_type*)(&m_cached_data[m_cache_location]));
447 m_cache_location += cast<uint08>(sizeof(t_type));
448 }
449 else
450 {
451 fread(&data, sizeof(t_type), 1, m_file.filePtr());
452 }
453 return data;
454 }
455
458 template<class t_type>
459 void skip()
460 {
461 if (m_using_cache)
462 m_cache_location += cast<uint08>(sizeof(t_type));
463 else
464 fseek(m_file.filePtr(), sizeof(t_type), SEEK_CUR);
465 }
466
471 void writeTerminatingString(const StringView& string, char terminator = '\0');
477 void readString(String& string, char terminator = '\0');
484 void switchToFile(File file, bool is_write, bool is_safe);
491 uint04 readString(char* string, char terminator = '\0');
504 uint04 readData(char* string, uint04 max_size);
509 template<class t_type, class t_memory_manager>
511 {
512 bool allow_multithread = m_multithreaded_compression;
513 read(data, allow_multithread);
514 }
515
519 template<class t_type, class t_memory_manager>
521 {
522 bool allow_multithread = false;
523 read(data, allow_multithread);
524 }
525
530 template<class t_type, class t_memory_manager>
531 typename std::enable_if<ObjectInfo<t_type>::Buffer>::type read(Buffer<t_type, t_memory_manager>& data, bool& allow_multithread)
532 {
533 Buffer<uint04> sizes;
534 Buffer<decltype(t_type::Type())> combined_data;
535 //if (ObjectInfo<t_type>::String)
536 allow_multithread = false;
537 read(sizes, allow_multithread);
538 read(combined_data, allow_multithread);
539 data.setSize(sizes.size());
540 uint04 current_offset = 0;
541 for (uint04 i = 0; i < sizes.size(); i++)
542 {
543 data[i].clear();
544 if (sizes[i] > 0)
545 data[i].addAll(&combined_data[0] + current_offset, sizes[i]);
546 current_offset += sizes[i];
547 }
548 }
549
555 template<class t_memory_manager>
556 void readStringBuffer(Buffer<String, t_memory_manager>& data, bool& allow_multithread)
557 {
558 Buffer<uint04> indices;
559 //if (ObjectInfo<t_type>::String)
560 allow_multithread = false;
561 read(indices, allow_multithread);
562 data.setSize(indices.size());
563 for (uint04 i = 0; i < indices.size(); i++)
564 {
565 Bounds<1, uint04> bounds = m_string_size_info[indices[i]];
566 if (bounds.span() > 0U)
567 data[i] = m_strings.substr(bounds[MIN], bounds[MAX]);
568 else
569 data[i].clear();
570 }
571 }
572
577 template<class t_type, class t_memory_manager>
578 typename std::enable_if<!ObjectInfo<t_type>::Buffer>::type read(Buffer<t_type, t_memory_manager>& data, bool& allow_multithread)
579 {
583 else
585 using t_index_type = typename t_memory_manager::index_type;
586 //lib_assert(binary.uncompressed_size < Constant<sint04>::Max, "Large number read");
587 data.setSize(cast<t_index_type>(binary.uncompressed_size));
588 binary.uncompressed_size = data.memSize();
589 if (data.size() != 0)
590 {
591 binary.uncompressed_data = (uint01*)data.ptr();
593 binary.compressed_size = read<uint08>();
594 else
595 binary.compressed_size = read<uint04>();
596 if (m_using_cache)
597 {
599 binary.compressed_size -= 1;
601 {
603
604 allow_multithread &= binary.compression_mode != CompressionMode::e_string_compression;
605 allow_multithread &= binary.compression_mode != CompressionMode::e_no_compression;
606 if (m_multithreaded_compression && allow_multithread)
607 m_compressions.add(binary);
608 else
610 m_cache_location += binary.compressed_size + 1;
611 }
612 else
613 {
616 }
617 }
618 else
619 {
621 {
622 m_compressed_data.setSize(binary.compressed_size);
623#ifdef USE_ASSERTIONS
624 size_t fsize = fread(&m_compressed_data[0], 1, m_compressed_data.size(), m_file.filePtr());
625 lib_assert(m_compressed_data.size() == cast<uint08>(fsize), "Bad read size");
626#else
627 fread(&m_compressed_data[0], 1, m_compressed_data.size(), m_file.filePtr());
628#endif
631 binary.compressed_size -= 1;
633 m_cache_location += binary.compressed_size + 1;
634 }
635 else
636 {
639 }
640 }
641 }
642 }
643
657 void seek(uint08 location);
667 void setUseLargeCompression(bool use_large_compression) { m_large_compression = use_large_compression; }
677 void writeCompression(BinaryCompressionObject& compression_object);
682 void writeStringData(CompressionMode compression_mode);
687 void readStringData(bool has_reference_table);
697 void uncompressSections(uint04 start, uint04 count);
714 const File& file() const { return m_file; }
719 File& file() { return m_file; }
729 void setMaxBufferSize(uint08 max_buffer_size)
730 {
731 m_max_buffer_size = max_buffer_size;
732 }
733 protected:
736 uint08 m_max_buffer_size = Constant<uint04>::Max;
739 fltp08 fltp_error = Constant<fltp08>::Invalid;
740 HighCapacityBuffer<uint01> m_compressed_data;
741 HighCapacityBuffer<uint01> m_cached_data;
743 uint08 m_cache_location = Constant<uint08>::Invalid;
744 mutable uint08 m_file_size = Constant<uint08>::Invalid;
745 bool m_using_cache = false;
746 bool m_is_read = false;
747 bool m_large_compression = false;
749
750 };
751 template class NDEVR_BASE_API StringStream<CompressionMode>;
752}
std::enable_if<!ObjectInfo< t_type >::Buffer >::type write(const t_type &data)
Writes a non-buffer type as raw bytes to the file.
Definition BinaryFile.h:254
BinaryFile(const Buffer< uint01 > &data)
Constructs a BinaryFile from a Buffer of bytes.
Definition BinaryFile.h:192
BinaryFile(BinaryFile &&bf) noexcept
Move constructor.
String m_strings
Accumulated string data for the string reference table.
Definition BinaryFile.h:735
void switchToFile(File file, bool is_write, bool is_safe)
Switches the underlying file to a different file and reopens it.
void open(bool read, bool safe)
Opens the file for reading or writing.
uint08 m_cache_location
Current read/write position within the cached data.
Definition BinaryFile.h:743
File m_file
The underlying file handle for disk-based I/O.
Definition BinaryFile.h:734
bool canRead() const
Checks whether enough data remains to read a value of the given type.
Definition BinaryFile.h:427
void readString(String &string, char terminator='\0')
Reads a string up to a terminating character.
void skip()
Advances the read position by the size of the given type without reading.
Definition BinaryFile.h:459
void setUseLargeCompression(bool use_large_compression)
Enables or disables large (64-bit) compression size headers.
Definition BinaryFile.h:667
Dictionary< String, uint04 > m_string_reference
Maps strings to their index in the string reference table.
Definition BinaryFile.h:737
const HighCapacityBuffer< uint01 > & cachedData() const
Returns a const reference to the in-memory cached data.
Definition BinaryFile.h:236
BinaryFile()
Constructs an empty BinaryFile backed by an in-memory cache.
Definition BinaryFile.h:149
bool m_is_read
Whether the file was opened for reading.
Definition BinaryFile.h:746
void writeStringData(CompressionMode compression_mode)
Writes the accumulated string reference table to the file.
uint04 readData(char *string, uint04 max_size)
Reads raw data into a character buffer up to a maximum size.
void writeDirect(const uint01 *ptr, uint08 size)
Writes raw bytes directly to the file or cache.
void seek(uint08 location)
Seeks to an absolute byte position in the file or cache.
uint08 m_file_size
Cached file size to avoid repeated filesystem queries.
Definition BinaryFile.h:744
bool isFinished()
Checks whether the file has been fully read.
BinaryCompressionObject createCompressionObject()
Creates a BinaryCompressionObject initialized with this file's compression settings.
void readStringBuffer(Buffer< String, t_memory_manager > &data, bool &allow_multithread)
Reads a buffer of strings using the string reference table for decompression.
Definition BinaryFile.h:556
uint08 position() const
Returns the current read or write position in the file or cache.
BinaryFile & operator=(BinaryFile &&bf) noexcept
Move assignment operator.
uint04 readString(char *string, char terminator='\0')
Reads a string into a character buffer up to a terminating character.
const File & file() const
Returns a const reference to the underlying File object.
Definition BinaryFile.h:714
fltp08 fltp_error
Floating-point error tolerance used during compression.
Definition BinaryFile.h:739
std::enable_if<!ObjectInfo< t_type >::Buffer >::type read(Buffer< t_type, t_memory_manager > &data, bool &allow_multithread)
Reads a buffer of non-buffer elements with decompression.
Definition BinaryFile.h:578
void uncompressAll()
Decompresses all pending multithreaded compression objects.
fltp04 percent() const
Returns the current read progress as a percentage of the total file size.
uint08 readDirect(uint01 *ptr, uint08 size)
Reads raw bytes directly from the file or cache.
~BinaryFile()
Destructor.
Definition BinaryFile.h:213
bool m_large_compression
Whether to use 64-bit size fields for compression headers.
Definition BinaryFile.h:747
bool m_using_cache
Whether the file is operating in cached (in-memory) mode.
Definition BinaryFile.h:745
std::enable_if< ObjectInfo< t_type >::Buffer >::type read(Buffer< t_type, t_memory_manager > &data, bool &allow_multithread)
Reads a buffer of buffer elements (nested buffers) with decompression.
Definition BinaryFile.h:531
void writeRawData(const StringView &data, uint04 size, char fill_space='\0')
Writes a string as raw data padded or truncated to a fixed size.
Definition BinaryFile.h:390
std::enable_if<!ObjectInfo< t_type >::Buffer >::type write(const Buffer< t_type, t_memory_manager > &data, CompressionMode compression_mode=CompressionMode::e_no_compression)
Writes a buffer of non-buffer elements with optional compression.
Definition BinaryFile.h:265
BinaryFile(const HighCapacityBuffer< uint01 > &data)
Constructs a BinaryFile from an existing data buffer (copy).
Definition BinaryFile.h:159
HighCapacityBuffer< uint01 > m_compressed_data
Temporary buffer for compressed data during read/write operations.
Definition BinaryFile.h:740
uint08 m_max_buffer_size
Maximum buffer size for cached read/write operations.
Definition BinaryFile.h:736
void writeTerminatingString(const StringView &string, char terminator='\0')
Writes a string followed by a terminating character.
HighCapacityBuffer< uint01 > & cachedData()
Returns a mutable reference to the in-memory cached data.
Definition BinaryFile.h:244
void writeCompression(BinaryCompressionObject &compression_object)
Writes a compression object's data to the file.
File & file()
Returns a mutable reference to the underlying File object.
Definition BinaryFile.h:719
t_type read()
Reads a single value of the given type from the file or cache.
Definition BinaryFile.h:441
void readStringData(bool has_reference_table)
Reads the string reference table from the file.
void write(const StringView &data, CompressionMode compression_mode)
Writes a string view with optional compression.
Definition BinaryFile.h:333
bool writeDirectlyFrom(File file)
Writes data from a file on disk directly into the cache.
bool m_multithreaded_compression
Whether multithreaded decompression is enabled.
Definition BinaryFile.h:748
bool readDirectlyTo(File file)
Reads the cached data directly to a file on disk.
void read(Buffer< t_type, t_memory_manager > &data)
Reads a compressed buffer using the file's multithreading setting.
Definition BinaryFile.h:510
void readNow(Buffer< t_type, t_memory_manager > &data)
Reads a compressed buffer synchronously, disabling multithreaded decompression.
Definition BinaryFile.h:520
HighCapacityBuffer< uint01 > m_cached_data
In-memory cache of the file's raw byte contents.
Definition BinaryFile.h:741
void cachedOpen(bool read)
Opens the file and reads its entire contents into an in-memory cache.
BinaryFile(HighCapacityBuffer< uint01 > &&data)
Constructs a BinaryFile from an existing data buffer (move).
Definition BinaryFile.h:169
Buffer< Bounds< 1, uint04 > > m_string_size_info
Stores the start and end bounds of each string in m_strings.
Definition BinaryFile.h:738
void close()
Closes the file and flushes any pending data.
uint08 fileSize() const
Returns the size of the underlying file in bytes.
void uncompressSections(uint04 start, uint04 count)
Decompresses a range of pending multithreaded compression objects.
Buffer< BinaryCompressionObject > m_compressions
Pending compression objects for multithreaded decompression.
Definition BinaryFile.h:742
BinaryFile(const File &file)
Constructs a BinaryFile associated with the given file on disk.
Definition BinaryFile.h:143
String readData(uint04 max_size)
Reads raw data up to a maximum size and returns it as a String.
BinaryFile(const uint01 *data, uint08 size)
Constructs a BinaryFile from a raw pointer and size.
Definition BinaryFile.h:181
void setMaxBufferSize(uint08 max_buffer_size)
Sets the maximum buffer size for cached operations.
Definition BinaryFile.h:729
std::enable_if< ObjectInfo< t_type >::Buffer >::type write(const Buffer< t_type, t_memory_manager > &data, CompressionMode compression_mode)
Writes a buffer of buffer elements (nested buffers) with optional compression.
Definition BinaryFile.h:309
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:54
constexpr Ray< t_dims, t_type > span() const
The side lengths of these bounds.
Definition Bounds.hpp:113
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
static CompressionMode PickCompressionMode(CompressionMode compression_mode=e_default_compression)
Selects the most appropriate compression mode for the given type.
Definition Compressor.h:147
static void DecompressData(BinaryCompressionObject &data)
Decompresses the BinaryCompressionObject.
static void CompressData(BinaryCompressionObject &data)
Compresses the BinaryCompressionObject.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
Logic for reading or writing to a string or a user friendly, TranslatedString.
The core String View class for the NDEVR API.
Definition StringView.h:58
constexpr const char * begin() const
Returns a pointer to the beginning of the string data.
Definition StringView.h:640
constexpr uint04 size() const
Returns the byte size of this string view.
Definition StringView.h:435
The core String class for the NDEVR API.
Definition String.h:95
The primary namespace for the NDEVR SDK.
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
constexpr std::enable_if<!ObjectInfo< t_type >::Buffer, TypeInfo >::type GetTypeInfo()
Constructs a TypeInfo for a non-buffer type at compile time using ObjectInfo traits.
Definition TypeInfo.h:125
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
CompressionMode
Forward declaration of the Module struct for module metadata.
Definition Compressor.h:17
@ e_string_compression
Compression mode tailored for string data.
Definition Compressor.h:21
@ e_no_compression
No compression is applied; data is stored raw.
Definition Compressor.h:18
@ e_string_reference
Stores strings by reference index into a shared table.
Definition Compressor.h:32
constexpr T _LE(T v) noexcept
Converts a value from little-endian to native byte order.
Definition BinaryFile.h:99
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr T ByteSwap(T v) noexcept
Reverses the byte order of an integral value.
Definition BinaryFile.h:75
constexpr T _BE(T v) noexcept
Converts a value from big-endian to native byte order.
Definition BinaryFile.h:113
constexpr t_type ChangeEndian(t_type in)
Definition BinaryFile.h:125
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
STL namespace.
A container for storing compressed data, typically used for File IO operations.
Definition Compressor.h:53
uint08 uncompressed_size
Size in bytes of the uncompressed data.
Definition Compressor.h:56
uint08 buffer_size
Number of logical elements in the buffer.
Definition Compressor.h:59
TypeInfo object_type
Type information describing the elements being compressed.
Definition Compressor.h:60
CompressionMode compression_mode
The compression algorithm to apply.
Definition Compressor.h:54
uint01 * compressed_data
Pointer to the compressed data buffer.
Definition Compressor.h:57
uint01 * uncompressed_data
Pointer to the raw uncompressed data buffer.
Definition Compressor.h:55
uint08 compressed_size
Size in bytes of the compressed data.
Definition Compressor.h:58