Commit 11c3b30f by Geoff Lang

Revert "Fix binary serialization to use explicit size and type."

This reverts commit 26198851. Change-Id: I959ca14fcbb257f12005f7f0b64a600e906a118c Reviewed-on: https://chromium-review.googlesource.com/199630Tested-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent c8f7232e
#include "commit.h"
#define ANGLE_MAJOR_VERSION 2
#define ANGLE_MINOR_VERSION 1
#define ANGLE_MAJOR_VERSION 1
#define ANGLE_MINOR_VERSION 3
#define ANGLE_STRINGIFY(x) #x
#define ANGLE_MACRO_STRINGIFY(x) ANGLE_STRINGIFY(x)
......
......@@ -25,50 +25,39 @@ class BinaryInputStream
mLength = length;
}
// readInt will generate an error for bool types
template <class IntT>
IntT readInt()
template <typename T>
void read(T *v, size_t num)
{
int value;
read(&value);
return static_cast<IntT>(value);
}
union
{
T dummy; // Compilation error for non-trivial types
} dummy;
(void) dummy;
template <class IntT>
void readInt(IntT *outValue)
{
int value;
read(&value);
*outValue = static_cast<IntT>(value);
}
if (mError)
{
return;
}
bool readBool()
{
int value;
read(&value);
return (value > 0);
}
size_t length = num * sizeof(T);
void readBool(bool *outValue)
{
int value;
read(&value);
*outValue = (value > 0);
}
if (mOffset + length > mLength)
{
mError = true;
return;
}
void readBytes(unsigned char outArray[], size_t count)
{
read<unsigned char>(outArray, count);
memcpy(v, mData + mOffset, length);
mOffset += length;
}
std::string readString()
template <typename T>
void read(T * v)
{
std::string outString;
readString(&outString);
return outString;
read(v, 1);
}
void readString(std::string *v)
void read(std::string *v)
{
size_t length;
read(&length);
......@@ -120,39 +109,6 @@ class BinaryInputStream
size_t mOffset;
const char *mData;
size_t mLength;
template <typename T>
void read(T *v, size_t num)
{
union
{
T dummy; // Compilation error for non-POD types
} dummy;
(void)dummy;
if (mError)
{
return;
}
size_t length = num * sizeof(T);
if (mOffset + length > mLength)
{
mError = true;
return;
}
memcpy(v, mData + mOffset, length);
mOffset += length;
}
template <typename T>
void read(T * v)
{
read(v, 1);
}
};
class BinaryOutputStream
......@@ -162,23 +118,31 @@ class BinaryOutputStream
{
}
// writeInt also handles bool types
template <class IntT>
void writeInt(IntT v)
template <typename T>
void write(const T *v, size_t num)
{
int intValue = static_cast<int>(v);
write(&v, 1);
union
{
T dummy; // Compilation error for non-trivial types
} dummy;
(void) dummy;
const char *asBytes = reinterpret_cast<const char*>(v);
mData.insert(mData.end(), asBytes, asBytes + num * sizeof(T));
}
void writeString(const std::string &v)
template <typename T>
void write(const T &v)
{
writeInt(v.length());
write(v.c_str(), v.length());
write(&v, 1);
}
void writeBytes(unsigned char *bytes, size_t count)
void write(const std::string &v)
{
write(bytes, count);
size_t length = v.length();
write(length);
write(v.c_str(), length);
}
size_t length() const
......@@ -194,20 +158,6 @@ class BinaryOutputStream
private:
DISALLOW_COPY_AND_ASSIGN(BinaryOutputStream);
std::vector<char> mData;
template <typename T>
void write(const T *v, size_t num)
{
union
{
T dummy; // Compilation error for non-POD types
} dummy;
(void) dummy;
const char *asBytes = reinterpret_cast<const char*>(v);
mData.insert(mData.end(), asBytes, asBytes + num * sizeof(T));
}
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment