Merge pull request #945 from aaron0x/RefactoryBinaryReaderWriter

Refactory BinaryReader and BinaryWriter
This commit is contained in:
Aleksandar Fabijanic
2016-03-13 23:08:44 -07:00
6 changed files with 190 additions and 258 deletions

View File

@@ -23,6 +23,7 @@
#include "Poco/Foundation.h"
#include "Poco/Buffer.h"
#include "Poco/MemoryStream.h"
#include "Poco/ByteOrder.h"
#include <vector>
#include <istream>
@@ -151,6 +152,32 @@ public:
/// Returns the number of available bytes in the stream.
private:
template<typename T>
BinaryReader& read(T& value, bool flipBytes)
{
_istr.read((char*) &value, sizeof(value));
if (flipBytes) value = ByteOrder::flipBytes(value);
return *this;
}
template<typename T>
void read7BitEncoded(T& value)
{
char c;
value = 0;
int s = 0;
do
{
c = 0;
_istr.read(&c, 1);
T x = (c & 0x7F);
x <<= s;
value += x;
s += 7;
}
while (c & 0x80);
}
std::istream& _istr;
bool _flipBytes;
TextConverter* _pTextConverter;