12 std::ofstream stream(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 stream.write(
reinterpret_cast<const char*
>(buffer),
static_cast<std::streamsize
>(byteSize));
24 std::ifstream stream(fileName.c_str(), std::ifstream::binary);
26 throw CppRuntimeException(
"readBufferFromFile: Cannot open '") << fileName <<
"' for reading!";
28 stream.seekg(0, stream.end);
29 const std::streampos fileSize = stream.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 stream.read(
reinterpret_cast<char*
>(bitBuffer.
getBuffer()),
43 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)