Fix binary serialization to use explicit size and type.

Loading program binaries across different architectures would cause
runtime errors due to use of size_t.

Also fix the ANGLE major and minor version that were clobbered in an
earlier commit.

BUG=angle:647
BUG=371435

Change-Id: I9473cc7e119592fce336aa47881839543e337b69
Reviewed-on: https://chromium-review.googlesource.com/199633
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index 2aa3719..62576a5 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -31,7 +31,7 @@
 namespace gl
 {
 
-namespace 
+namespace
 {
 
 unsigned int ParseAndStripArrayIndex(std::string* name)
@@ -78,7 +78,7 @@
 
 }
 
-VariableLocation::VariableLocation(const std::string &name, unsigned int element, unsigned int index) 
+VariableLocation::VariableLocation(const std::string &name, unsigned int element, unsigned int index)
     : name(name), element(element), index(index)
 {
 }
@@ -275,7 +275,7 @@
 int ProgramBinary::getSemanticIndex(int attributeIndex)
 {
     ASSERT(attributeIndex >= 0 && attributeIndex < MAX_VERTEX_ATTRIBS);
-    
+
     return mSemanticIndex[attributeIndex];
 }
 
@@ -376,7 +376,7 @@
             const int index = mUniformIndex[location].index;
             const bool isArray = mUniforms[index]->isArray();
 
-            if ((isArray && mUniformIndex[location].element == subscript) || 
+            if ((isArray && mUniformIndex[location].element == subscript) ||
                 (subscript == GL_INVALID_INDEX))
             {
                 return location;
@@ -636,7 +636,7 @@
 }
 
 template <int cols, int rows>
-bool ProgramBinary::setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType) 
+bool ProgramBinary::setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType)
 {
     if (location < 0 || location >= (int)mUniformIndex.size())
     {
@@ -878,7 +878,7 @@
                 }
             }
             break;
-       
+
           case GL_UNSIGNED_INT:
             {
                 GLuint *uintParams = (GLuint*)targetUniform->data + mUniformIndex[location].element * 4;
@@ -889,7 +889,7 @@
                 }
             }
             break;
-          
+
           default: UNREACHABLE();
         }
     }
@@ -1065,18 +1065,15 @@
 {
     BinaryInputStream stream(binary, length);
 
-    int format = 0;
-    stream.read(&format);
+    int format = stream.readInt<int>();
     if (format != GL_PROGRAM_BINARY_ANGLE)
     {
         infoLog.append("Invalid program binary format.");
         return false;
     }
 
-    int majorVersion = 0;
-    int minorVersion = 0;
-    stream.read(&majorVersion);
-    stream.read(&minorVersion);
+    int majorVersion = stream.readInt<int>();
+    int minorVersion = stream.readInt<int>();
     if (majorVersion != ANGLE_MAJOR_VERSION || minorVersion != ANGLE_MINOR_VERSION)
     {
         infoLog.append("Invalid program binary version.");
@@ -1084,15 +1081,14 @@
     }
 
     unsigned char commitString[ANGLE_COMMIT_HASH_SIZE];
-    stream.read(commitString, ANGLE_COMMIT_HASH_SIZE);
+    stream.readBytes(commitString, ANGLE_COMMIT_HASH_SIZE);
     if (memcmp(commitString, ANGLE_COMMIT_HASH, sizeof(unsigned char) * ANGLE_COMMIT_HASH_SIZE) != 0)
     {
         infoLog.append("Invalid program binary version.");
         return false;
     }
 
-    int compileFlags = 0;
-    stream.read(&compileFlags);
+    int compileFlags = stream.readInt<int>();
     if (compileFlags != ANGLE_COMPILE_OPTIMIZATION_LEVEL)
     {
         infoLog.append("Mismatched compilation flags.");
@@ -1101,153 +1097,131 @@
 
     for (int i = 0; i < MAX_VERTEX_ATTRIBS; ++i)
     {
-        stream.read(&mLinkedAttribute[i].type);
-        std::string name;
-        stream.read(&name);
-        mLinkedAttribute[i].name = name;
-        stream.read(&mShaderAttributes[i].type);
-        stream.read(&mShaderAttributes[i].name);
-        stream.read(&mSemanticIndex[i]);
+        stream.readInt(&mLinkedAttribute[i].type);
+        stream.readString(&mLinkedAttribute[i].name);
+        stream.readInt(&mShaderAttributes[i].type);
+        stream.readString(&mShaderAttributes[i].name);
+        stream.readInt(&mSemanticIndex[i]);
     }
 
     initAttributesByLayout();
 
     for (unsigned int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; ++i)
     {
-        stream.read(&mSamplersPS[i].active);
-        stream.read(&mSamplersPS[i].logicalTextureUnit);
-        
-        int textureType;
-        stream.read(&textureType);
-        mSamplersPS[i].textureType = (TextureType) textureType;
+        stream.readBool(&mSamplersPS[i].active);
+        stream.readInt(&mSamplersPS[i].logicalTextureUnit);
+        stream.readInt(&mSamplersPS[i].textureType);
     }
 
     for (unsigned int i = 0; i < IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; ++i)
     {
-        stream.read(&mSamplersVS[i].active);
-        stream.read(&mSamplersVS[i].logicalTextureUnit);
-        
-        int textureType;
-        stream.read(&textureType);
-        mSamplersVS[i].textureType = (TextureType) textureType;
+        stream.readBool(&mSamplersVS[i].active);
+        stream.readInt(&mSamplersVS[i].logicalTextureUnit);
+        stream.readInt(&mSamplersVS[i].textureType);
     }
 
-    stream.read(&mUsedVertexSamplerRange);
-    stream.read(&mUsedPixelSamplerRange);
-    stream.read(&mUsesPointSize);
-    stream.read(&mShaderVersion);
+    stream.readInt(&mUsedVertexSamplerRange);
+    stream.readInt(&mUsedPixelSamplerRange);
+    stream.readBool(&mUsesPointSize);
+    stream.readInt(&mShaderVersion);
 
-    size_t size;
-    stream.read(&size);
+    const unsigned int uniformCount = stream.readInt<unsigned int>();
     if (stream.error())
     {
         infoLog.append("Invalid program binary.");
         return false;
     }
 
-    mUniforms.resize(size);
-    for (unsigned int i = 0; i < size; ++i)
+    mUniforms.resize(uniformCount);
+    for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; uniformIndex++)
     {
-        GLenum type;
-        GLenum precision;
-        std::string name;
-        unsigned int arraySize;
-        int blockIndex;
+        GLenum type = stream.readInt<GLenum>();
+        GLenum precision = stream.readInt<GLenum>();
+        std::string name = stream.readString();
+        unsigned int arraySize = stream.readInt<unsigned int>();
+        int blockIndex = stream.readInt<int>();
 
-        stream.read(&type);
-        stream.read(&precision);
-        stream.read(&name);
-        stream.read(&arraySize);
-        stream.read(&blockIndex);
-
-        int offset;
-        int arrayStride;
-        int matrixStride;
-        bool isRowMajorMatrix;
-
-        stream.read(&offset);
-        stream.read(&arrayStride);
-        stream.read(&matrixStride);
-        stream.read(&isRowMajorMatrix);
+        int offset = stream.readInt<int>();
+        int arrayStride = stream.readInt<int>();
+        int matrixStride = stream.readInt<int>();
+        bool isRowMajorMatrix = stream.readBool();
 
         const gl::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix);
 
-        mUniforms[i] = new LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo);
-        
-        stream.read(&mUniforms[i]->psRegisterIndex);
-        stream.read(&mUniforms[i]->vsRegisterIndex);
-        stream.read(&mUniforms[i]->registerCount);
-        stream.read(&mUniforms[i]->registerElement);
+        LinkedUniform *uniform = new LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo);
+
+        stream.readInt(&uniform->psRegisterIndex);
+        stream.readInt(&uniform->vsRegisterIndex);
+        stream.readInt(&uniform->registerCount);
+        stream.readInt(&uniform->registerElement);
+
+        mUniforms[uniformIndex] = uniform;
     }
 
-    stream.read(&size);
+    unsigned int uniformBlockCount = stream.readInt<unsigned int>();
     if (stream.error())
     {
         infoLog.append("Invalid program binary.");
         return false;
     }
 
-    mUniformBlocks.resize(size);
-    for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < size; ++uniformBlockIndex)
+    mUniformBlocks.resize(uniformBlockCount);
+    for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < uniformBlockCount; ++uniformBlockIndex)
     {
-        std::string name;
-        unsigned int elementIndex;
-        unsigned int dataSize;
+        std::string name = stream.readString();
+        unsigned int elementIndex = stream.readInt<unsigned int>();
+        unsigned int dataSize = stream.readInt<unsigned int>();
 
-        stream.read(&name);
-        stream.read(&elementIndex);
-        stream.read(&dataSize);
+        UniformBlock *uniformBlock = new UniformBlock(name, elementIndex, dataSize);
 
-        mUniformBlocks[uniformBlockIndex] = new UniformBlock(name, elementIndex, dataSize);
+        stream.readInt(&uniformBlock->psRegisterIndex);
+        stream.readInt(&uniformBlock->vsRegisterIndex);
 
-        UniformBlock& uniformBlock = *mUniformBlocks[uniformBlockIndex];
-        stream.read(&uniformBlock.psRegisterIndex);
-        stream.read(&uniformBlock.vsRegisterIndex);
-
-        size_t numMembers;
-        stream.read(&numMembers);
-        uniformBlock.memberUniformIndexes.resize(numMembers);
+        unsigned int numMembers = stream.readInt<unsigned int>();
+        uniformBlock->memberUniformIndexes.resize(numMembers);
         for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++)
         {
-            stream.read(&uniformBlock.memberUniformIndexes[blockMemberIndex]);
+            stream.readInt(&uniformBlock->memberUniformIndexes[blockMemberIndex]);
         }
+
+        mUniformBlocks[uniformBlockIndex] = uniformBlock;
     }
 
-    stream.read(&size);
+    const unsigned int uniformIndexCount = stream.readInt<unsigned int>();
     if (stream.error())
     {
         infoLog.append("Invalid program binary.");
         return false;
     }
 
-    mUniformIndex.resize(size);
-    for (unsigned int i = 0; i < size; ++i)
+    mUniformIndex.resize(uniformIndexCount);
+    for (unsigned int uniformIndexIndex = 0; uniformIndexIndex < uniformIndexCount; uniformIndexIndex++)
     {
-        stream.read(&mUniformIndex[i].name);
-        stream.read(&mUniformIndex[i].element);
-        stream.read(&mUniformIndex[i].index);
+        stream.readString(&mUniformIndex[uniformIndexIndex].name);
+        stream.readInt(&mUniformIndex[uniformIndexIndex].element);
+        stream.readInt(&mUniformIndex[uniformIndexIndex].index);
     }
 
-    stream.read(&mTransformFeedbackBufferMode);
-    stream.read(&size);
-    mTransformFeedbackLinkedVaryings.resize(size);
-    for (size_t i = 0; i < mTransformFeedbackLinkedVaryings.size(); i++)
+    stream.readInt(&mTransformFeedbackBufferMode);
+    const unsigned int transformFeedbackVaryingCount = stream.readInt<unsigned int>();
+    mTransformFeedbackLinkedVaryings.resize(transformFeedbackVaryingCount);
+    for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount; varyingIndex++)
     {
-        LinkedVarying &varying = mTransformFeedbackLinkedVaryings[i];
+        LinkedVarying &varying = mTransformFeedbackLinkedVaryings[varyingIndex];
 
-        stream.read(&varying.name);
-        stream.read(&varying.type);
-        stream.read(&varying.size);
-        stream.read(&varying.semanticName);
-        stream.read(&varying.semanticIndex);
-        stream.read(&varying.semanticIndexCount);
+        stream.readString(&varying.name);
+        stream.readInt(&varying.type);
+        stream.readInt(&varying.size);
+        stream.readString(&varying.semanticName);
+        stream.readInt(&varying.semanticIndex);
+        stream.readInt(&varying.semanticIndexCount);
     }
 
-    stream.read(&mVertexHLSL);
-    stream.read(&mVertexWorkarounds);
+    stream.readString(&mVertexHLSL);
 
-    unsigned int vertexShaderCount;
-    stream.read(&vertexShaderCount);
+    stream.readInt(&mVertexWorkarounds);
+
+    const unsigned int vertexShaderCount = stream.readInt<unsigned int>();
 
     for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++)
     {
@@ -1256,14 +1230,13 @@
         for (size_t inputIndex = 0; inputIndex < MAX_VERTEX_ATTRIBS; inputIndex++)
         {
             VertexFormat *vertexInput = &inputLayout[inputIndex];
-            stream.read(&vertexInput->mType);
-            stream.read(&vertexInput->mNormalized);
-            stream.read(&vertexInput->mComponents);
-            stream.read(&vertexInput->mPureInteger);
+            stream.readInt(&vertexInput->mType);
+            stream.readInt(&vertexInput->mNormalized);
+            stream.readInt(&vertexInput->mComponents);
+            stream.readBool(&vertexInput->mPureInteger);
         }
 
-        unsigned int vertexShaderSize;
-        stream.read(&vertexShaderSize);
+        unsigned int vertexShaderSize = stream.readInt<unsigned int>();
 
         const char *vertexShaderFunction = (const char*) binary + stream.offset();
 
@@ -1287,8 +1260,7 @@
         stream.skip(vertexShaderSize);
     }
 
-    unsigned int pixelShaderSize;
-    stream.read(&pixelShaderSize);
+    unsigned int pixelShaderSize = stream.readInt<unsigned int>();
 
     const char *pixelShaderFunction = (const char*) binary + stream.offset();
     mPixelExecutable = mRenderer->loadExecutable(reinterpret_cast<const DWORD*>(pixelShaderFunction),
@@ -1301,8 +1273,7 @@
     }
     stream.skip(pixelShaderSize);
 
-    unsigned int geometryShaderSize;
-    stream.read(&geometryShaderSize);
+    unsigned int geometryShaderSize = stream.readInt<unsigned int>();
 
     if (geometryShaderSize > 0)
     {
@@ -1340,107 +1311,107 @@
 {
     BinaryOutputStream stream;
 
-    stream.write(GL_PROGRAM_BINARY_ANGLE);
-    stream.write(ANGLE_MAJOR_VERSION);
-    stream.write(ANGLE_MINOR_VERSION);
-    stream.write(ANGLE_COMMIT_HASH, ANGLE_COMMIT_HASH_SIZE);
-    stream.write(ANGLE_COMPILE_OPTIMIZATION_LEVEL);
+    stream.writeInt(GL_PROGRAM_BINARY_ANGLE);
+    stream.writeInt(ANGLE_MAJOR_VERSION);
+    stream.writeInt(ANGLE_MINOR_VERSION);
+    stream.writeBytes(reinterpret_cast<unsigned char*>(ANGLE_COMMIT_HASH), ANGLE_COMMIT_HASH_SIZE);
+    stream.writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL);
 
     for (unsigned int i = 0; i < MAX_VERTEX_ATTRIBS; ++i)
     {
-        stream.write(mLinkedAttribute[i].type);
-        stream.write(mLinkedAttribute[i].name);
-        stream.write(mShaderAttributes[i].type);
-        stream.write(mShaderAttributes[i].name);
-        stream.write(mSemanticIndex[i]);
+        stream.writeInt(mLinkedAttribute[i].type);
+        stream.writeString(mLinkedAttribute[i].name);
+        stream.writeInt(mShaderAttributes[i].type);
+        stream.writeString(mShaderAttributes[i].name);
+        stream.writeInt(mSemanticIndex[i]);
     }
 
     for (unsigned int i = 0; i < MAX_TEXTURE_IMAGE_UNITS; ++i)
     {
-        stream.write(mSamplersPS[i].active);
-        stream.write(mSamplersPS[i].logicalTextureUnit);
-        stream.write((int) mSamplersPS[i].textureType);
+        stream.writeInt(mSamplersPS[i].active);
+        stream.writeInt(mSamplersPS[i].logicalTextureUnit);
+        stream.writeInt(mSamplersPS[i].textureType);
     }
 
     for (unsigned int i = 0; i < IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; ++i)
     {
-        stream.write(mSamplersVS[i].active);
-        stream.write(mSamplersVS[i].logicalTextureUnit);
-        stream.write((int) mSamplersVS[i].textureType);
+        stream.writeInt(mSamplersVS[i].active);
+        stream.writeInt(mSamplersVS[i].logicalTextureUnit);
+        stream.writeInt(mSamplersVS[i].textureType);
     }
 
-    stream.write(mUsedVertexSamplerRange);
-    stream.write(mUsedPixelSamplerRange);
-    stream.write(mUsesPointSize);
-    stream.write(mShaderVersion);
+    stream.writeInt(mUsedVertexSamplerRange);
+    stream.writeInt(mUsedPixelSamplerRange);
+    stream.writeInt(mUsesPointSize);
+    stream.writeInt(mShaderVersion);
 
-    stream.write(mUniforms.size());
+    stream.writeInt(mUniforms.size());
     for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); ++uniformIndex)
     {
         const LinkedUniform &uniform = *mUniforms[uniformIndex];
 
-        stream.write(uniform.type);
-        stream.write(uniform.precision);
-        stream.write(uniform.name);
-        stream.write(uniform.arraySize);
-        stream.write(uniform.blockIndex);
+        stream.writeInt(uniform.type);
+        stream.writeInt(uniform.precision);
+        stream.writeString(uniform.name);
+        stream.writeInt(uniform.arraySize);
+        stream.writeInt(uniform.blockIndex);
 
-        stream.write(uniform.blockInfo.offset);
-        stream.write(uniform.blockInfo.arrayStride);
-        stream.write(uniform.blockInfo.matrixStride);
-        stream.write(uniform.blockInfo.isRowMajorMatrix);
+        stream.writeInt(uniform.blockInfo.offset);
+        stream.writeInt(uniform.blockInfo.arrayStride);
+        stream.writeInt(uniform.blockInfo.matrixStride);
+        stream.writeInt(uniform.blockInfo.isRowMajorMatrix);
 
-        stream.write(uniform.psRegisterIndex);
-        stream.write(uniform.vsRegisterIndex);
-        stream.write(uniform.registerCount);
-        stream.write(uniform.registerElement);
+        stream.writeInt(uniform.psRegisterIndex);
+        stream.writeInt(uniform.vsRegisterIndex);
+        stream.writeInt(uniform.registerCount);
+        stream.writeInt(uniform.registerElement);
     }
 
-    stream.write(mUniformBlocks.size());
+    stream.writeInt(mUniformBlocks.size());
     for (size_t uniformBlockIndex = 0; uniformBlockIndex < mUniformBlocks.size(); ++uniformBlockIndex)
     {
         const UniformBlock& uniformBlock = *mUniformBlocks[uniformBlockIndex];
 
-        stream.write(uniformBlock.name);
-        stream.write(uniformBlock.elementIndex);
-        stream.write(uniformBlock.dataSize);
+        stream.writeString(uniformBlock.name);
+        stream.writeInt(uniformBlock.elementIndex);
+        stream.writeInt(uniformBlock.dataSize);
 
-        stream.write(uniformBlock.memberUniformIndexes.size());
+        stream.writeInt(uniformBlock.memberUniformIndexes.size());
         for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++)
         {
-            stream.write(uniformBlock.memberUniformIndexes[blockMemberIndex]);
+            stream.writeInt(uniformBlock.memberUniformIndexes[blockMemberIndex]);
         }
 
-        stream.write(uniformBlock.psRegisterIndex);
-        stream.write(uniformBlock.vsRegisterIndex);
+        stream.writeInt(uniformBlock.psRegisterIndex);
+        stream.writeInt(uniformBlock.vsRegisterIndex);
     }
 
-    stream.write(mUniformIndex.size());
+    stream.writeInt(mUniformIndex.size());
     for (size_t i = 0; i < mUniformIndex.size(); ++i)
     {
-        stream.write(mUniformIndex[i].name);
-        stream.write(mUniformIndex[i].element);
-        stream.write(mUniformIndex[i].index);
+        stream.writeString(mUniformIndex[i].name);
+        stream.writeInt(mUniformIndex[i].element);
+        stream.writeInt(mUniformIndex[i].index);
     }
 
-    stream.write(mTransformFeedbackBufferMode);
-    stream.write(mTransformFeedbackLinkedVaryings.size());
+    stream.writeInt(mTransformFeedbackBufferMode);
+    stream.writeInt(mTransformFeedbackLinkedVaryings.size());
     for (size_t i = 0; i < mTransformFeedbackLinkedVaryings.size(); i++)
     {
         const LinkedVarying &varying = mTransformFeedbackLinkedVaryings[i];
 
-        stream.write(varying.name);
-        stream.write(varying.type);
-        stream.write(varying.size);
-        stream.write(varying.semanticName);
-        stream.write(varying.semanticIndex);
-        stream.write(varying.semanticIndexCount);
+        stream.writeString(varying.name);
+        stream.writeInt(varying.type);
+        stream.writeInt(varying.size);
+        stream.writeString(varying.semanticName);
+        stream.writeInt(varying.semanticIndex);
+        stream.writeInt(varying.semanticIndexCount);
     }
 
-    stream.write(mVertexHLSL);
-    stream.write(mVertexWorkarounds);
+    stream.writeString(mVertexHLSL);
+    stream.writeInt(mVertexWorkarounds);
 
-    stream.write(mVertexExecutables.size());
+    stream.writeInt(mVertexExecutables.size());
     for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size(); vertexExecutableIndex++)
     {
         VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex];
@@ -1448,32 +1419,32 @@
         for (size_t inputIndex = 0; inputIndex < gl::MAX_VERTEX_ATTRIBS; inputIndex++)
         {
             const VertexFormat &vertexInput = vertexExecutable->inputs()[inputIndex];
-            stream.write(vertexInput.mType);
-            stream.write(vertexInput.mNormalized);
-            stream.write(vertexInput.mComponents);
-            stream.write(vertexInput.mPureInteger);
+            stream.writeInt(vertexInput.mType);
+            stream.writeInt(vertexInput.mNormalized);
+            stream.writeInt(vertexInput.mComponents);
+            stream.writeInt(vertexInput.mPureInteger);
         }
 
-        UINT vertexShaderSize = vertexExecutable->shaderExecutable()->getLength();
-        stream.write(vertexShaderSize);
+        size_t vertexShaderSize = vertexExecutable->shaderExecutable()->getLength();
+        stream.writeInt(vertexShaderSize);
 
         unsigned char *vertexBlob = static_cast<unsigned char *>(vertexExecutable->shaderExecutable()->getFunction());
-        stream.write(vertexBlob, vertexShaderSize);
+        stream.writeBytes(vertexBlob, vertexShaderSize);
     }
 
-    UINT pixelShaderSize = mPixelExecutable->getLength();
-    stream.write(pixelShaderSize);
+    size_t pixelShaderSize = mPixelExecutable->getLength();
+    stream.writeInt(pixelShaderSize);
 
     unsigned char *pixelBlob = static_cast<unsigned char *>(mPixelExecutable->getFunction());
-    stream.write(pixelBlob, pixelShaderSize);
+    stream.writeBytes(pixelBlob, pixelShaderSize);
 
-    UINT geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0;
-    stream.write(geometryShaderSize);
+    size_t geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0;
+    stream.writeInt(geometryShaderSize);
 
     if (mGeometryExecutable != NULL && geometryShaderSize > 0)
     {
         unsigned char *geometryBlob = static_cast<unsigned char *>(mGeometryExecutable->getFunction());
-        stream.write(geometryBlob, geometryShaderSize);
+        stream.writeBytes(geometryBlob, geometryShaderSize);
     }
 
     GUID identifier = mRenderer->getAdapterIdentifier();
@@ -1985,7 +1956,7 @@
     if (IsSampler(constant.type))
     {
         unsigned int samplerIndex = constant.registerIndex;
-            
+
         do
         {
             if (shader == GL_VERTEX_SHADER)
@@ -2352,7 +2323,7 @@
     return true;
 }
 
-bool ProgramBinary::isValidated() const 
+bool ProgramBinary::isValidated() const
 {
     return mValidated;
 }
@@ -2620,7 +2591,7 @@
         if (mSamplersPS[i].active)
         {
             unsigned int unit = mSamplersPS[i].logicalTextureUnit;
-            
+
             if (unit >= maxCombinedTextureImageUnits)
             {
                 if (infoLog)
@@ -2655,7 +2626,7 @@
         if (mSamplersVS[i].active)
         {
             unsigned int unit = mSamplersVS[i].logicalTextureUnit;
-            
+
             if (unit >= maxCombinedTextureImageUnits)
             {
                 if (infoLog)