From 5ca446888656da91165b7bf90b7b2195d1e1afac Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 21 Oct 2019 15:32:13 -0400 Subject: `Repro` functionality (#1085) * WIP on serialize/save state. * Relative string encoding. * Added RelativeContainer unit test. Split out RelativeContainer into core. * Fix bug in RelativeString encoding. * More work around relative container. * Fix checks. * Use RelativeBase for safe access. Use malloc/free/realloc instead of List. * Add natvis support for relative types. * Setting up of state (not includes) writing of repro state. * Capture after spCompile. * Writing SourceFile and file system files. Added -dump-repo * First pass at loading state. * First pass at reading repro. * Small optimization around Safe32Ptr * Refactor how repro data is stored - to make saving off the files more simple, by having all all backed by 'files'. Make file loading always set up PathInfo so we get uniqueIdentifier info. * Generate unique file names. * Added RelativeFileSystem Added saveFile to ISlangFileSystemExt and implemented for interfaces Added mechanism to save of files (and manifest) * Added ability to replace files in repo with directory holding their contents. * Add support for entry points. * Fix problem compiling on linux. * Added SIMPLE_EX option, where everything on command line must be specified. * Fix typo in unit test for relative container. * Fix another typo in unit test for RelativeContainer. * Fix small bugs. * Fix release unused variable issue in slang-state-serialize.cpp * Fix checking for SIMPLE_EX in testing, else broke COMMAND_LINE_SIMPLE. * Fix warnings on 32 bit debug build. * Added import-subdir-search-path-repro.slang test. Although disabled for now as writes to root of slang project. * Remove wrong version of import-subdir-search-path-repro.slang * Added import-subdir-search-path-repro.slang --- source/core/slang-riff.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 source/core/slang-riff.cpp (limited to 'source/core/slang-riff.cpp') diff --git a/source/core/slang-riff.cpp b/source/core/slang-riff.cpp new file mode 100644 index 000000000..df2076013 --- /dev/null +++ b/source/core/slang-riff.cpp @@ -0,0 +1,99 @@ +#include "slang-riff.h" + +#include "../../slang-com-helper.h" + +namespace Slang +{ + +/* static */int64_t RiffUtil::calcChunkTotalSize(const RiffChunk& chunk) +{ + int64_t size = chunk.m_size + sizeof(RiffChunk); + return (size + 3) & ~int64_t(3); +} + +/* static */SlangResult RiffUtil::skip(const RiffChunk& chunk, Stream* stream, int64_t* remainingBytesInOut) +{ + int64_t chunkSize = calcChunkTotalSize(chunk); + if (remainingBytesInOut) + { + *remainingBytesInOut -= chunkSize; + } + + // Skip the payload (we don't need to skip the Chunk because that was already read + stream->Seek(SeekOrigin::Current, chunkSize - sizeof(RiffChunk)); + return SLANG_OK; +} + + +/* static */SlangResult RiffUtil::readChunk(Stream* stream, RiffChunk& outChunk) +{ + try + { + stream->Read(&outChunk, sizeof(RiffChunk)); + } + catch (IOException&) + { + return SLANG_FAIL; + } + + // TODO(JS): Could handle endianness issues here... + + return SLANG_OK; +} + + +/* static */SlangResult RiffUtil::writeData(uint32_t riffType, const void* data, size_t size, Stream* out) +{ + SLANG_ASSERT(uint64_t(size) <= uint64_t(0xfffffffff)); + + // TODO(JS): Could handle endianness here + RiffChunk chunk; + chunk.m_type = riffType; + chunk.m_size = uint32_t(size); + + try + { + out->Write(&chunk, sizeof(chunk)); + out->Write(data, size); + size_t remaining = size & 3; + if (remaining) + { + uint8_t end[4] = { 0, 0, 0, 0}; + out->Write(end, 4 - remaining); + } + } + catch (IOException&) + { + return SLANG_FAIL; + } + + return SLANG_OK; +} + + +/* static */SlangResult RiffUtil::readData(Stream* stream, RiffChunk& outChunk, List& data) +{ + SLANG_RETURN_ON_FAIL(readChunk(stream, outChunk)); + + data.setCount(outChunk.m_size); + + try + { + stream->Read(data.getBuffer(), outChunk.m_size); + + // Skip to the alignment + uint32_t remaining = outChunk.m_size & 3; + if (remaining) + { + stream->Seek(SeekOrigin::Current, 4 - remaining); + } + } + catch (IOException&) + { + return SLANG_FAIL; + } + + return SLANG_OK; +} + +} -- cgit v1.2.3