12 std::ofstream os(fileName.c_str(), std::ofstream::binary | std::ofstream::trunc);
14 throw CppRuntimeException(
"writeBufferToFile: Failed to open '") << fileName <<
"' for writing!";
16 const size_t byteSize = (bitSize + 7) / 8;
17 os.write(reinterpret_cast<const char*>(buffer), static_cast<std::streamsize>(byteSize));
24 std::ifstream is(fileName.c_str(), std::ifstream::binary);
26 throw CppRuntimeException(
"readBufferFromFile: Cannot open '") << fileName <<
"' for reading!";
29 const std::streampos fileSize = is.tellg();
32 if (static_cast<int>(fileSize) == -1)
33 throw CppRuntimeException(
"readBufferFromFile: Failed to get file size of '") << fileName <<
"'!";
35 const size_t sizeLimit = std::numeric_limits<size_t>::max() / 8;
36 if (static_cast<uint64_t>(fileSize) > sizeLimit)
38 throw CppRuntimeException(
"readBufferFromFile: File size exceeds limit '") << sizeLimit <<
"'!";
42 is.read(reinterpret_cast<char*>(bitBuffer.
getBuffer()),
43 static_cast<std::streamsize>(bitBuffer.
getByteSize()));
void writeBufferToFile(const uint8_t *buffer, size_t bitSize, BitsTag, const std::string &fileName)
const uint8_t * getBuffer() const
zserio::string< PropagatingPolymorphicAllocator< char >> string
size_t getByteSize() const
BitBuffer readBufferFromFile(const std::string &fileName)