12 std::ofstream stream(fileName.c_str(), std::ofstream::binary | std::ofstream::trunc);
15 throw CppRuntimeException(
"writeBufferToFile: Failed to open '") << fileName <<
"' for writing!";
18 const size_t byteSize = (bitSize + 7) / 8;
19 if (!stream.write(
reinterpret_cast<const char*
>(buffer),
static_cast<std::streamsize
>(byteSize)))
27 std::ifstream stream(fileName.c_str(), std::ifstream::binary);
30 throw CppRuntimeException(
"readBufferFromFile: Cannot open '") << fileName <<
"' for reading!";
33 (void)stream.seekg(0, stream.end);
34 const std::streampos fileSize = stream.tellg();
35 (void)stream.seekg(0);
37 if (
static_cast<int>(fileSize) == -1)
39 throw CppRuntimeException(
"readBufferFromFile: Failed to get file size of '") << fileName <<
"'!";
42 const size_t sizeLimit = std::numeric_limits<size_t>::max() / 8;
43 if (
static_cast<uint64_t
>(fileSize) > sizeLimit)
45 throw CppRuntimeException(
"readBufferFromFile: File size exceeds limit '") << sizeLimit <<
"'!";
49 if (!stream.read(
reinterpret_cast<char*
>(bitBuffer.
getBuffer()),
50 static_cast<std::streamsize
>(bitBuffer.
getByteSize())))
size_t getByteSize() const
const uint8_t * getBuffer() const
zserio::string< PropagatingPolymorphicAllocator< char > > string
void writeBufferToFile(const uint8_t *buffer, size_t bitSize, BitsTag, const std::string &fileName)
BitBuffer readBufferFromFile(const std::string &fileName)