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" #include "commit.h"
#define ANGLE_MAJOR_VERSION 2 #define ANGLE_MAJOR_VERSION 1
#define ANGLE_MINOR_VERSION 1 #define ANGLE_MINOR_VERSION 3
#define ANGLE_STRINGIFY(x) #x #define ANGLE_STRINGIFY(x) #x
#define ANGLE_MACRO_STRINGIFY(x) ANGLE_STRINGIFY(x) #define ANGLE_MACRO_STRINGIFY(x) ANGLE_STRINGIFY(x)
......
...@@ -25,50 +25,39 @@ class BinaryInputStream ...@@ -25,50 +25,39 @@ class BinaryInputStream
mLength = length; mLength = length;
} }
// readInt will generate an error for bool types template <typename T>
template <class IntT> void read(T *v, size_t num)
IntT readInt()
{ {
int value; union
read(&value); {
return static_cast<IntT>(value); T dummy; // Compilation error for non-trivial types
} } dummy;
(void) dummy;
template <class IntT> if (mError)
void readInt(IntT *outValue) {
{ return;
int value; }
read(&value);
*outValue = static_cast<IntT>(value);
}
bool readBool() size_t length = num * sizeof(T);
{
int value;
read(&value);
return (value > 0);
}
void readBool(bool *outValue) if (mOffset + length > mLength)
{ {
int value; mError = true;
read(&value); return;
*outValue = (value > 0); }
}
void readBytes(unsigned char outArray[], size_t count) memcpy(v, mData + mOffset, length);
{ mOffset += length;
read<unsigned char>(outArray, count);
} }
std::string readString() template <typename T>
void read(T * v)
{ {
std::string outString; read(v, 1);
readString(&outString);
return outString;
} }
void readString(std::string *v) void read(std::string *v)
{ {
size_t length; size_t length;
read(&length); read(&length);
...@@ -120,39 +109,6 @@ class BinaryInputStream ...@@ -120,39 +109,6 @@ class BinaryInputStream
size_t mOffset; size_t mOffset;
const char *mData; const char *mData;
size_t mLength; 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 class BinaryOutputStream
...@@ -162,23 +118,31 @@ class BinaryOutputStream ...@@ -162,23 +118,31 @@ class BinaryOutputStream
{ {
} }
// writeInt also handles bool types template <typename T>
template <class IntT> void write(const T *v, size_t num)
void writeInt(IntT v)
{ {
int intValue = static_cast<int>(v); union
write(&v, 1); {
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, 1);
write(v.c_str(), v.length());
} }
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 size_t length() const
...@@ -194,20 +158,6 @@ class BinaryOutputStream ...@@ -194,20 +158,6 @@ class BinaryOutputStream
private: private:
DISALLOW_COPY_AND_ASSIGN(BinaryOutputStream); DISALLOW_COPY_AND_ASSIGN(BinaryOutputStream);
std::vector<char> mData; 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