From f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Apr 2007 03:49:53 +0000 Subject: Ok, no code is left in src, it's all in src/old. We'll gradually move code back into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier. --- src/old/serializerbinary.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/old/serializerbinary.cpp (limited to 'src/old/serializerbinary.cpp') diff --git a/src/old/serializerbinary.cpp b/src/old/serializerbinary.cpp new file mode 100644 index 0000000..ea7ed93 --- /dev/null +++ b/src/old/serializerbinary.cpp @@ -0,0 +1,63 @@ +#include "serializerbinary.h" +#include "serializable.h" +#include "exceptions.h" + +SerializerBinary::SerializerBinary(FILE *fhFile, bool bLoading): + Serializer(bLoading), + fhFile(fhFile), + bCloseFile(false) +{ +} + +SerializerBinary::SerializerBinary(const char *sFileName, bool bLoading): + Serializer(bLoading), + bCloseFile(true) +{ + if (bLoading) + { + fhFile = fopen(sFileName, "rb"); + if( fhFile == NULL ) + throw FileException("Unable to open file: %s", sFileName ); + } + else + { + fhFile = fopen(sFileName, "wb"); + if( fhFile == NULL ) + throw FileException("Unable to open file: %s", sFileName ); + } +} + +SerializerBinary::~SerializerBinary() +{ + close(); +} + +void SerializerBinary::close() +{ + if (fhFile != NULL && bCloseFile ) + { + fclose(fhFile); + fhFile = NULL; + } +} + +void SerializerBinary::write(const void * pData, int32_t nSize) +{ + if( nSize == 0 ) + return; + + fwrite(pData, nSize, 1, fhFile); +} + +void SerializerBinary::read(void * pData, int32_t nSize) +{ + if( nSize == 0 ) + return; + + uint32_t nRead = fread(pData, nSize, 1, fhFile); + if( nRead < 1 ) + { + throw FileException( excodeEOF, "End of file read"); + } +} + -- cgit v1.2.3