STREAM: add read/write functions for double LE/BE
This commit is contained in:
parent
438a6223cb
commit
97397bdaff
1 changed files with 58 additions and 0 deletions
|
@ -203,6 +203,31 @@ public:
|
||||||
writeUint32BE(n);
|
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.
|
* Write the given string to the stream.
|
||||||
* This writes str.size() characters, but no terminating zero byte.
|
* This writes str.size() characters, but no terminating zero byte.
|
||||||
|
@ -474,6 +499,39 @@ public:
|
||||||
return f;
|
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
|
* Read the specified amount of data into a malloc'ed buffer
|
||||||
* which then is wrapped into a MemoryReadStream.
|
* which then is wrapped into a MemoryReadStream.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue