1 |
|
|
/** |
2 |
|
|
* \file |
3 |
|
|
* File utilities. |
4 |
|
|
* |
5 |
|
|
* These utilities are not used by generated code and they are provided only for user convenience. |
6 |
|
|
* |
7 |
|
|
* \note Please note that file operations allocate memory as needed and are not designed to use allocators. |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#ifndef ZSERIO_FILE_UTIL_H_INC |
11 |
|
|
#define ZSERIO_FILE_UTIL_H_INC |
12 |
|
|
|
13 |
|
|
#include "zserio/BitBuffer.h" |
14 |
|
|
#include "zserio/BitStreamReader.h" |
15 |
|
|
#include "zserio/BitStreamWriter.h" |
16 |
|
|
|
17 |
|
|
namespace zserio |
18 |
|
|
{ |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* Read file to bit buffer object. |
22 |
|
|
* |
23 |
|
|
* \param fileName File to read. |
24 |
|
|
* |
25 |
|
|
* \return Bit buffer representing the file contents. |
26 |
|
|
* |
27 |
|
|
* \throw CppRuntimeException When reading fails. |
28 |
|
|
*/ |
29 |
|
|
BitBuffer readBufferFromFile(const std::string& fileName); |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* Writes given buffer to file. |
33 |
|
|
* |
34 |
|
|
* \param buffer Buffer to write. |
35 |
|
|
* \param bitSize Buffer bit size. |
36 |
|
|
* \param fileName Name of the file to write. |
37 |
|
|
* |
38 |
|
|
* \throw CppRuntimeException When writing fails. |
39 |
|
|
*/ |
40 |
|
|
void writeBufferToFile(const uint8_t* buffer, size_t bitSize, BitsTag, const std::string& fileName); |
41 |
|
|
|
42 |
|
|
/** |
43 |
|
|
* Writes given buffer to file. |
44 |
|
|
* |
45 |
|
|
* Overloaded function provided for convenience. |
46 |
|
|
* |
47 |
|
|
* \param buffer Buffer to write. |
48 |
|
|
* \param byteSize Buffer byte size. |
49 |
|
|
* \param fileName Name of the file to write. |
50 |
|
|
* |
51 |
|
|
* \throw CppRuntimeException When writing fails. |
52 |
|
|
*/ |
53 |
|
1 |
inline void writeBufferToFile(const uint8_t* buffer, size_t byteSize, const std::string& fileName) |
54 |
|
|
{ |
55 |
✓✗ |
1 |
writeBufferToFile(buffer, byteSize * 8, BitsTag(), fileName); |
56 |
|
1 |
} |
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
* Writes given bit buffer to file. |
60 |
|
|
* |
61 |
|
|
* Overloaded function provided for convenience. |
62 |
|
|
* |
63 |
|
|
* \param bitBuffer Bit buffer to write. |
64 |
|
|
* \param fileName Name of the file to write. |
65 |
|
|
* |
66 |
|
|
* \throw CppRuntimeException When writing fails. |
67 |
|
|
*/ |
68 |
|
|
template <typename ALLOC> |
69 |
|
4 |
inline void writeBufferToFile(const BasicBitBuffer<ALLOC>& bitBuffer, const std::string& fileName) |
70 |
|
|
{ |
71 |
✓✗✗✗
|
4 |
writeBufferToFile(bitBuffer.getBuffer(), bitBuffer.getBitSize(), BitsTag(), fileName); |
72 |
|
4 |
} |
73 |
|
|
|
74 |
|
|
/** |
75 |
|
|
* Writes write-buffer of the given bit stream writer to file. |
76 |
|
|
* |
77 |
|
|
* Overloaded function provided for convenience. |
78 |
|
|
* |
79 |
|
|
* \param writer Bit stream writer to use. |
80 |
|
|
* \param fileName Name of the file to write. |
81 |
|
|
* |
82 |
|
|
* \throw CppRuntimeException When writing fails. |
83 |
|
|
*/ |
84 |
|
1 |
inline void writeBufferToFile(const BitStreamWriter& writer, const std::string& fileName) |
85 |
|
|
{ |
86 |
✓✗✓✗
|
1 |
writeBufferToFile(writer.getWriteBuffer(), writer.getBitPosition(), BitsTag(), fileName); |
87 |
|
1 |
} |
88 |
|
|
|
89 |
|
|
} // namespace zserio |
90 |
|
|
|
91 |
|
|
#endif // ZSERIO_FILE_UTIL_H_INC |