STREAM: add read/write functions for double LE/BE

This commit is contained in:
Le Philousophe 2019-03-05 19:27:52 +01:00 committed by Eugene Sandulenko
parent 438a6223cb
commit 97397bdaff

View file

@ -203,6 +203,31 @@ public:
writeUint32BE(n);
}
/**
* Write the given 64-bit floating point value stored
* in little endian(LSB first) order into the stream.
*/
FORCEINLINE void writeDoubleLE(double value) {
uint64 n;
memcpy(&n, &value, 8);
writeUint64LE(n);
}
/**
* Write the given 64-bit floating point value stored
* in big endian order into the stream.
*/
FORCEINLINE void writeDoubleBE(double value) {
uint64 n;
memcpy(&n, &value, 8);
writeUint64BE(n);
}
/**
* Write the given string to the stream.
* This writes str.size() characters, but no terminating zero byte.
@ -474,6 +499,39 @@ public:
return f;
}
/**
* Read a 64-bit floating point value stored in little endian (LSB first)
* order from the stream and return it.
* Performs no error checking. The return value is undefined
* if a read error occurred (for which client code can check by
* calling err() and eos() ).
*/
FORCEINLINE double readDoubleLE() {
uint64 n = readUint64LE();
double d;
memcpy(&d, &n, 8);
return d;
}
/**
* Read a 64-bit floating point value stored in big endian
* order from the stream and return it.
* Performs no error checking. The return value is undefined
* if a read error occurred (for which client code can check by
* calling err() and eos() ).
*/
FORCEINLINE double readDoubleBE() {
uint64 n = readUint64BE();
double d;
memcpy(&d, &n, 8);
return d;
}
/**
* Read the specified amount of data into a malloc'ed buffer
* which then is wrapped into a MemoryReadStream.