1 #ifndef IOUTILITIES_BINERYREADER_H 2 #define IOUTILITIES_BINERYREADER_H 4 #include "../conversion/binaryconversion.h" 19 const std::istream *stream()
const;
20 std::istream *stream();
21 void setStream(std::istream *stream,
bool giveOwnership =
false);
22 bool hasOwnership()
const;
24 void detatchOwnership();
28 std::istream::pos_type readStreamsize();
29 void read(
char *buffer, std::streamsize length);
30 void read(
byte *buffer, std::streamsize length);
31 void read(std::vector<char> &buffer, std::streamsize length);
44 uint64 readVariableLengthUIntBE();
45 float32 readFloat32BE();
46 float64 readFloat64BE();
59 uint64 readVariableLengthUIntLE();
60 float32 readFloat32LE();
61 float64 readFloat64LE();
65 std::string readLengthPrefixedString();
66 std::string readString(std::size_t length);
67 std::string readTerminatedString(
byte termination = 0);
68 std::string readTerminatedString(
size_t maxBytesToRead,
byte termination = 0);
69 std::string readMultibyteTerminatedStringBE(
uint16 termination = 0);
70 std::string readMultibyteTerminatedStringLE(
uint16 termination = 0);
71 std::string readMultibyteTerminatedStringBE(std::size_t maxBytesToRead,
uint16 termination = 0);
72 std::string readMultibyteTerminatedStringLE(std::size_t maxBytesToRead,
uint16 termination = 0);
73 uint32 readSynchsafeUInt32BE();
74 float32 readFixed8BE();
75 float32 readFixed16BE();
76 uint32 readSynchsafeUInt32LE();
77 float32 readFixed8LE();
78 float32 readFixed16LE();
79 uint32 readCrc32(std::size_t length);
80 static uint32 computeCrc32(
const char *buffer, std::size_t length);
84 void read(
char &oneCharacter);
85 void read(
byte &oneByte);
86 void read(
bool &oneBool);
87 void read(std::string &lengthPrefixedString);
88 void read(
int16 &one16BitInt);
89 void read(
uint16 &one16BitUInt);
90 void read(
int32 &one32BitInt);
91 void read(
uint32 &one32BitUInt);
92 void read(
int64 &one64BitInt);
93 void read(
uint64 &one64BitUInt);
94 void read(float32 &one32BitFloat);
95 void read(float64 &one64BitFloat);
98 void bufferVariableLengthInteger();
100 std::istream *m_stream;
168 return m_stream ? m_stream->fail() :
false;
176 return m_stream && m_stream->eof();
184 return m_stream && m_stream->good();
192 m_stream->read(buffer, length);
200 m_stream->read(reinterpret_cast<char *>(buffer), length);
208 buffer.resize(
static_cast<std::vector<char>::size_type
>(length));
209 m_stream->read(buffer.data(), length);
217 m_stream->read(m_buffer,
sizeof(
int16));
226 m_stream->read(m_buffer,
sizeof(
uint16));
236 m_stream->read(m_buffer + 1, 3);
238 if (val >= 0x800000) {
239 val = -(0x1000000 - val);
250 m_stream->read(m_buffer + 1, 3);
259 m_stream->read(m_buffer,
sizeof(
int32));
268 m_stream->read(m_buffer,
sizeof(
uint32));
277 *m_buffer = *(m_buffer + 1) = *(m_buffer + 2) = 0;
278 m_stream->read(m_buffer + 3, 5);
280 if (val >= 0x8000000000) {
281 val = -(0x10000000000 - val);
291 *m_buffer = *(m_buffer + 1) = *(m_buffer + 2) = 0;
292 m_stream->read(m_buffer + 3, 5);
302 m_stream->read(m_buffer + 1, 7);
304 if (val >= 0x80000000000000) {
305 val = -(0x100000000000000 - val);
316 m_stream->read(m_buffer + 1, 7);
325 m_stream->read(m_buffer,
sizeof(
int64));
334 m_stream->read(m_buffer,
sizeof(
uint64));
344 bufferVariableLengthInteger();
353 m_stream->read(m_buffer,
sizeof(float32));
362 m_stream->read(m_buffer,
sizeof(float64));
371 m_stream->read(m_buffer,
sizeof(
int16));
380 m_stream->read(m_buffer,
sizeof(
uint16));
390 m_stream->read(m_buffer, 3);
392 if (val >= 0x800000) {
393 val = -(0x1000000 - val);
404 m_stream->read(m_buffer, 3);
413 m_stream->read(m_buffer,
sizeof(
int32));
422 m_stream->read(m_buffer,
sizeof(
uint32));
431 *(m_buffer + 5) = *(m_buffer + 6) = *(m_buffer + 7) = 0;
432 m_stream->read(m_buffer, 5);
434 if (val >= 0x8000000000) {
435 val = -(0x10000000000 - val);
445 *(m_buffer + 5) = *(m_buffer + 6) = *(m_buffer + 7) = 0;
446 m_stream->read(m_buffer, 5);
456 m_stream->read(m_buffer, 7);
458 if (val >= 0x80000000000000) {
459 val = -(0x100000000000000 - val);
470 m_stream->read(m_buffer, 7);
479 m_stream->read(m_buffer,
sizeof(
int64));
488 m_stream->read(m_buffer,
sizeof(
uint64));
498 bufferVariableLengthInteger();
507 m_stream->read(m_buffer,
sizeof(float32));
516 m_stream->read(m_buffer,
sizeof(float64));
525 m_stream->read(m_buffer,
sizeof(
char));
534 m_stream->read(m_buffer,
sizeof(
char));
535 return static_cast<byte>(m_buffer[0]);
700 #endif // IOUTILITIES_BINERYREADER_H int64 readInt64LE()
Reads a 64-bit little endian signed integer from the current stream and advances the current position...
CPP_UTILITIES_EXPORT constexpr uint16 toUInt16(const char *value)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a char array.
bool fail() const
Returns an indication whether the fail bit of the assigned stream is set.
bool readBool()
Reads a boolean value from the current stream and advances the current position of the stream by one ...
CPP_UTILITIES_EXPORT constexpr uint32 toUInt32(const char *value)
Returns a 32-bit unsigned integer converted from four bytes at a specified position in a char array.
float32 readFloat32BE()
Reads a 32-bit big endian floating point value from the current stream and advances the current posit...
int64 readInt40BE()
Reads a 40-bit big endian signed integer from the current stream and advances the current position of...
std::int64_t int64
signed 64-bit integer
int16 readInt16LE()
Reads a 16-bit little endian signed integer from the current stream and advances the current position...
Reads primitive data types from a std::istream.
float64 readFloat64LE()
Reads a 64-bit little endian floating point value from the current stream and advances the current po...
CPP_UTILITIES_EXPORT constexpr int64 toInt64(const char *value)
Returns a 64-bit signed integer converted from eight bytes at a specified position in a char array.
int32 readInt32LE()
Reads a 32-bit little endian signed integer from the current stream and advances the current position...
float32 readFloat32LE()
Reads a 32-bit little endian floating point value from the current stream and advances the current po...
#define CPP_UTILITIES_EXPORT
uint32 readUInt24BE()
Reads a 24-bit big endian unsigned integer from the current stream and advances the current position ...
int16 readInt16BE()
Reads a 16-bit big endian signed integer from the current stream and advances the current position of...
void read(char *buffer, std::streamsize length)
Reads the specified number of characters from the stream in the character array.
CPP_UTILITIES_EXPORT constexpr int32 toInt32(const char *value)
Returns a 32-bit signed integer converted from four bytes at a specified position in a char array.
int64 readInt64BE()
Reads a 64-bit big endian signed integer from the current stream and advances the current position of...
std::uint64_t uint64
unsigned 64-bit integer
CPP_UTILITIES_EXPORT constexpr int16 toInt16(const char *value)
Returns a 16-bit signed integer converted from two bytes at a specified position in a char array.
CPP_UTILITIES_EXPORT constexpr int16 toInt16(const char *value)
Returns a 16-bit signed integer converted from two bytes at a specified position in a char array.
CPP_UTILITIES_EXPORT float32 toFloat32(const char *value)
Returns a 32-bit floating point number converted from four bytes at a specified position in a char ar...
float64 readFloat64BE()
Reads a 64-bit big endian floating point value from the current stream and advances the current posit...
int64 readInt56BE()
Reads a 56-bit big endian signed integer from the current stream and advances the current position of...
uint64 readUInt56LE()
Reads a 56-bit little endian unsigned integer from the current stream and advances the current positi...
bool hasOwnership() const
Returns whether the reader takes ownership over the assigned stream.
uint32 readUInt32LE()
Reads a 32-bit little endian unsigned integer from the current stream and advances the current positi...
float32 readFixed16BE()
Reads a 16.16 fixed point big endian representation from the current stream and returns it as 32-bit ...
uint32 readUInt32BE()
Reads a 32-bit big endian unsigned integer from the current stream and advances the current position ...
Contains utility classes helping to read and write streams.
CPP_UTILITIES_EXPORT constexpr uint16 toUInt16(const char *value)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a char array.
uint64 readVariableLengthUIntLE()
Reads an up to 8 byte long little endian unsigned integer from the current stream and advances the cu...
uint64 readUInt40BE()
Reads a 40-bit big endian unsigned integer from the current stream and advances the current position ...
CPP_UTILITIES_EXPORT float64 toFloat64(const char *value)
Returns a 64-bit floating point number converted from eight bytes at a specified position in a char a...
uint64 readUInt64BE()
Reads a 64-bit big endian unsigned integer from the current stream and advances the current position ...
std::uint32_t uint32
unsigned 32-bit integer
uint16 readUInt16LE()
Reads a 16-bit little endian unsigned integer from the current stream and advances the current positi...
void giveOwnership()
The reader will take ownership over the assigned stream.
uint16 readUInt16BE()
Reads a 16-bit big endian unsigned integer from the current stream and advances the current position ...
void detatchOwnership()
The reader will not take ownership over the assigned stream.
CPP_UTILITIES_EXPORT float64 toFloat64(const char *value)
Returns a 64-bit floating point number converted from eight bytes at a specified position in a char a...
CPP_UTILITIES_EXPORT constexpr uint64 toUInt64(const char *value)
Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a char array.
int32 readInt24LE()
Reads a 24-bit little endian signed integer from the current stream and advances the current position...
CPP_UTILITIES_EXPORT constexpr int64 toInt64(const char *value)
Returns a 64-bit signed integer converted from eight bytes at a specified position in a char array.
std::int32_t int32
signed 32-bit integer
CPP_UTILITIES_EXPORT constexpr int32 toInt32(const char *value)
Returns a 32-bit signed integer converted from four bytes at a specified position in a char array.
const std::istream * stream() const
Returns a pointer to the stream the reader will read from when calling one of the read-methods.
int32 readInt32BE()
Reads a 32-bit big endian signed integer from the current stream and advances the current position of...
int32 readInt24BE()
Reads a 24-bit big endian signed integer from the current stream and advances the current position of...
uint32 readSynchsafeUInt32LE()
Reads a 32-bit little endian synchsafe integer from the current stream and advances the current posit...
bool canRead() const
Returns an indication whether a stream is assigned the reader can read from.
uint64 readVariableLengthUIntBE()
Reads an up to 8 byte long big endian unsigned integer from the current stream and advances the curre...
uint32 readUInt24LE()
Reads a 24-bit little endian unsigned integer from the current stream and advances the current positi...
int64 readInt56LE()
Reads a 56-bit little endian signed integer from the current stream and advances the current position...
byte readByte()
Reads a single byte/unsigned character from the current stream and advances the current position of t...
CPP_UTILITIES_EXPORT constexpr float32 toFloat32(uint16 fixed8value)
Returns a 32-bit floating point number converted from the specified 8.8 fixed point representation.
char readChar()
Reads a single character from the current stream and advances the current position of the stream by o...
float32 readFixed8BE()
Reads a 8.8 fixed point big endian representation from the current stream and returns it as 32-bit fl...
CPP_UTILITIES_EXPORT constexpr uint64 toUInt64(const char *value)
Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a char array.
std::int16_t int16
signed 16-bit integer
CPP_UTILITIES_EXPORT float32 toFloat32(const char *value)
Returns a 32-bit floating point number converted from four bytes at a specified position in a char ar...
CPP_UTILITIES_EXPORT constexpr uint32 toNormalInt(uint32 synchsafeInt)
Returns a normal 32-bit integer converted from a 32-bit synchsafe integer.
uint64 readUInt64LE()
Reads a 64-bit little endian unsigned integer from the current stream and advances the current positi...
float32 readFixed16LE()
Reads a 16.16 fixed point little endian representation from the current stream and returns it as 32-b...
bool eof() const
Returns an indication whether the end-of-stream bit of the assigned stream is set.
std::string readLengthPrefixedString()
Reads a length prefixed string from the current stream.
float32 readFixed8LE()
Reads a 8.8 fixed point little endian representation from the current stream and returns it as 32-bit...
uint64 readUInt56BE()
Reads a 56-bit big endian unsigned integer from the current stream and advances the current position ...
int64 readInt40LE()
Reads a 40-bit little endian signed integer from the current stream and advances the current position...
uint32 readSynchsafeUInt32BE()
Reads a 32-bit big endian synchsafe integer from the current stream and advances the current position...
std::uint16_t uint16
unsigned 16-bit integer
CPP_UTILITIES_EXPORT constexpr uint32 toUInt32(const char *value)
Returns a 32-bit unsigned integer converted from four bytes at a specified position in a char array.
uint64 readUInt40LE()
Reads a 40-bit little endian unsigned integer from the current stream and advances the current positi...