Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
plywood/repos/plywood/src/reflect/ply-reflect/Asset.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
53 lines (43 sloc)
1.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*------------------------------------ | |
| ///\ Plywood C++ Framework | |
| \\\/ https://plywood.arc80.com/ | |
| ------------------------------------*/ | |
| #include <ply-reflect/Core.h> | |
| #include <ply-reflect/Asset.h> | |
| #include <ply-reflect/PersistWrite.h> | |
| namespace ply { | |
| //-------------------------------------------------------------------- | |
| // Write | |
| // | |
| void writeAsset(OutStream* out, TypedPtr obj) { | |
| WriteFormatContext writeFormatContext{out}; | |
| MemOutStream memOut; | |
| WriteObjectContext writeObjectContext{&memOut, &writeFormatContext}; | |
| writeObject(obj, &writeObjectContext); | |
| writeFormatContext.endSchema(); | |
| // Resolve links and write link table | |
| Buffer bin = memOut.moveToBuffer(); | |
| resolveLinksAndWriteLinkTable(bin, out, &writeObjectContext.ptrResolver); | |
| // Write object data | |
| out->write(bin); | |
| } | |
| //-------------------------------------------------------------------- | |
| // Read | |
| // | |
| TypedPtr readAsset(InStream* ins, PersistentTypeResolver* resolver) { | |
| Schema schema; | |
| readSchema(schema, ins); | |
| ReadObjectContext context{&schema, ins, resolver}; | |
| readLinkTable(&context.in, &context.ptrResolver); | |
| context.ptrResolver.objDataOffset = safeDemote<u32>(ins->getSeekPos()); | |
| TypedPtr obj = readObject(&context); | |
| resolveLinks(&context.ptrResolver); | |
| return obj; | |
| } | |
| //-------------------------------------------------------------------- | |
| // ExpectedTypeResolver | |
| // | |
| TypeDescriptor* ExpectedTypeResolver::getType(FormatDescriptor* formatDesc) { | |
| return m_expected; | |
| } | |
| } // namespace ply |