Added: #1440 Test code for writing the storage back to a stream, which works

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 12 years ago
parent 39feef9c8b
commit b175f4e8bc

@ -111,6 +111,9 @@ bool CStorageChunks::enterChunk()
if (iscont) chunk->Size |= 0x80000000; if (iscont) chunk->Size |= 0x80000000;
m_Is64Bit = true; // it's true m_Is64Bit = true; // it's true
} }
#ifdef NL_DEBUG_STORAGE
nldebug("Entered reading chunk of size %i", chunk->Size);
#endif
return true; return true;
} }
else else
@ -126,6 +129,10 @@ bool CStorageChunks::enterChunk(uint16 id, bool container)
{ {
if (!m_Stream.isReading()) if (!m_Stream.isReading())
{ {
#ifdef NL_DEBUG_STORAGE
nldebug("Writing, enter chunk");
#endif
if (m_Is64Bit) if (m_Is64Bit)
throw NLMISC::EStream("64bit chunks not supported"); throw NLMISC::EStream("64bit chunks not supported");
@ -171,6 +178,9 @@ sint32 CStorageChunks::leaveChunk()
} }
else else
{ {
#ifdef NL_DEBUG_STORAGE
nldebug("Writing, leave chunk");
#endif
sint32 pos = m_Stream.getPos(); sint32 pos = m_Stream.getPos();
sint32 sizeWithHeader = pos - currentChunk()->OffsetBegin; sint32 sizeWithHeader = pos - currentChunk()->OffsetBegin;
sint32 sizePos = currentChunk()->OffsetBegin + 2; sint32 sizePos = currentChunk()->OffsetBegin + 2;
@ -179,6 +189,9 @@ sint32 CStorageChunks::leaveChunk()
m_Stream.serial(sizeField); m_Stream.serial(sizeField);
m_Stream.seek(pos, NLMISC::IStream::begin); m_Stream.seek(pos, NLMISC::IStream::begin);
m_Chunks.resize(m_Chunks.size() - 1); m_Chunks.resize(m_Chunks.size() - 1);
#ifdef NL_DEBUG_STORAGE
nldebug("Size: %i, Field: %x", sizeWithHeader, sizeField);
#endif
return sizeWithHeader; return sizeWithHeader;
} }
} }

@ -41,7 +41,7 @@
// using namespace std; // using namespace std;
// using namespace NLMISC; // using namespace NLMISC;
#define NL_DEBUG_STORAGE // #define NL_DEBUG_STORAGE
namespace PIPELINE { namespace PIPELINE {
namespace MAX { namespace MAX {
@ -120,13 +120,17 @@ void CStorageContainer::serial(NLMISC::IStream &stream)
CStorageStream *storageStream = dynamic_cast<CStorageStream *>(&stream); CStorageStream *storageStream = dynamic_cast<CStorageStream *>(&stream);
if (storageStream) if (storageStream)
{ {
// implicitly assume the entire stream is the container #ifdef NL_DEBUG_STORAGE
nldebug("Implicitly assume the entire stream is the container");
#endif
CStorageChunks chunks(stream, stream.isReading() ? storageStream->size() : 0); CStorageChunks chunks(stream, stream.isReading() ? storageStream->size() : 0);
serial(chunks); serial(chunks);
return; return;
} }
} }
// wrapping the container inside a stream with necessary size markers #ifdef NL_DEBUG_STORAGE
nldebug("Wrapping the container inside a stream with necessary size markers");
#endif
{ {
const uint32 magic = 0xC0C01473; const uint32 magic = 0xC0C01473;
stream.serialCheck(magic); stream.serialCheck(magic);
@ -134,7 +138,9 @@ void CStorageContainer::serial(NLMISC::IStream &stream)
sint32 sizePos; sint32 sizePos;
bool reading = stream.isReading(); bool reading = stream.isReading();
if (!reading) if (!reading)
{
sizePos = stream.getPos(); sizePos = stream.getPos();
}
sint64 size = 0; sint64 size = 0;
stream.serial(size); stream.serial(size);
CStorageChunks chunks(stream, size); CStorageChunks chunks(stream, size);
@ -142,10 +148,25 @@ void CStorageContainer::serial(NLMISC::IStream &stream)
if (!reading) if (!reading)
{ {
sint32 returnPos = stream.getPos(); sint32 returnPos = stream.getPos();
#ifdef NL_DEBUG_STORAGE
nldebug("current (return) pos is %i", stream.getPos());
#endif
size = returnPos - sizePos - 8;
stream.seek(sizePos, NLMISC::IStream::begin); stream.seek(sizePos, NLMISC::IStream::begin);
#ifdef NL_DEBUG_STORAGE
nldebug("current (size) pos is %i", stream.getPos());
#endif
stream.serial(size); stream.serial(size);
stream.seek(returnPos, NLMISC::IStream::begin); stream.seek(returnPos, NLMISC::IStream::begin);
} #ifdef NL_DEBUG_STORAGE
nldebug("sizePos is %i", sizePos);
nldebug("returnPos is %i", returnPos);
nldebug("current (return) pos is %i", stream.getPos());
#endif
}
#ifdef NL_DEBUG_STORAGE
nldebug("Chunk container wrapper size is %i", size);
#endif
return; return;
} }
} }
@ -227,6 +248,9 @@ void CStorageContainer::serial(CStorageChunks &chunks)
{ {
if (chunks.stream().isReading()) if (chunks.stream().isReading())
{ {
#ifdef NL_DEBUG_STORAGE
nldebug("Reading container chunk");
#endif
nlassert(ChunksOwnsPointers); nlassert(ChunksOwnsPointers);
nlassert(Chunks.empty()); nlassert(Chunks.empty());
while (chunks.enterChunk()) while (chunks.enterChunk())
@ -247,10 +271,15 @@ void CStorageContainer::serial(CStorageChunks &chunks)
} }
else else
{ {
#ifdef NL_DEBUG_STORAGE
nldebug("Writing container chunk");
#endif
for (TStorageObjectContainer::iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it) for (TStorageObjectContainer::iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it)
{ {
chunks.enterChunk(it->first, it->second->isContainer()); chunks.enterChunk(it->first, it->second->isContainer());
it->second->serial(chunks.stream()); IStorageObject *storageObject = it->second;
if (storageObject->isContainer()) static_cast<CStorageContainer *>(storageObject)->serial(chunks);
else storageObject->serial(chunks.stream());
chunks.leaveChunk(); chunks.leaveChunk();
} }
} }

@ -16,6 +16,8 @@
#include <vector> #include <vector>
#include <utility> #include <utility>
#include <nel/misc/file.h>
#include "../max/storage_stream.h" #include "../max/storage_stream.h"
#include "../max/storage_object.h" #include "../max/storage_object.h"
#include "../max/dll_directory.h" #include "../max/dll_directory.h"
@ -82,7 +84,18 @@ int main(int argc, char **argv)
input = gsf_infile_child_by_name(infile, "DllDirectory"); input = gsf_infile_child_by_name(infile, "DllDirectory");
{ {
PIPELINE::MAX::CStorageStream instream(input); PIPELINE::MAX::CStorageStream instream(input);
dllDirectory.serial(instream); PIPELINE::MAX::CStorageContainer ctr;
ctr.serial(instream);
{
NLMISC::COFile of("temp.bin");
ctr.serial(of); // out
// nldebug("Written %i bytes", of.getPos());
}
{
NLMISC::CIFile inf("temp.bin");
dllDirectory.serial(inf); // in
}
//dllDirectory.serial(instream);
} }
g_object_unref(input); g_object_unref(input);
//dllDirectory.toString(std::cout); //dllDirectory.toString(std::cout);

Loading…
Cancel
Save