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

@ -41,7 +41,7 @@
// using namespace std;
// using namespace NLMISC;
#define NL_DEBUG_STORAGE
// #define NL_DEBUG_STORAGE
namespace PIPELINE {
namespace MAX {
@ -120,13 +120,17 @@ void CStorageContainer::serial(NLMISC::IStream &stream)
CStorageStream *storageStream = dynamic_cast<CStorageStream *>(&stream);
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);
serial(chunks);
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;
stream.serialCheck(magic);
@ -134,7 +138,9 @@ void CStorageContainer::serial(NLMISC::IStream &stream)
sint32 sizePos;
bool reading = stream.isReading();
if (!reading)
{
sizePos = stream.getPos();
}
sint64 size = 0;
stream.serial(size);
CStorageChunks chunks(stream, size);
@ -142,10 +148,25 @@ void CStorageContainer::serial(NLMISC::IStream &stream)
if (!reading)
{
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);
#ifdef NL_DEBUG_STORAGE
nldebug("current (size) pos is %i", stream.getPos());
#endif
stream.serial(size);
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;
}
}
@ -227,6 +248,9 @@ void CStorageContainer::serial(CStorageChunks &chunks)
{
if (chunks.stream().isReading())
{
#ifdef NL_DEBUG_STORAGE
nldebug("Reading container chunk");
#endif
nlassert(ChunksOwnsPointers);
nlassert(Chunks.empty());
while (chunks.enterChunk())
@ -247,10 +271,15 @@ void CStorageContainer::serial(CStorageChunks &chunks)
}
else
{
#ifdef NL_DEBUG_STORAGE
nldebug("Writing container chunk");
#endif
for (TStorageObjectContainer::iterator it = Chunks.begin(), end = Chunks.end(); it != end; ++it)
{
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();
}
}

@ -16,6 +16,8 @@
#include <vector>
#include <utility>
#include <nel/misc/file.h>
#include "../max/storage_stream.h"
#include "../max/storage_object.h"
#include "../max/dll_directory.h"
@ -82,7 +84,18 @@ int main(int argc, char **argv)
input = gsf_infile_child_by_name(infile, "DllDirectory");
{
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);
//dllDirectory.toString(std::cout);

Loading…
Cancel
Save