QByteArray IAsset::RawData(const QString serializationParameters) const { std::vector<u8> data; if (SerializeTo(data, serializationParameters) && data.size() > 0) return QByteArray((const char*)&data[0], data.size()); else return QByteArray(); }
bool IAsset::SaveToFile(const QString &filename, const QString &serializationParameters) const { std::vector<u8> data; bool success = SerializeTo(data, serializationParameters); if (!success || data.size() == 0) { LogError("IAsset::SaveToFile: SerializeTo returned no data for asset \"" + ToString() + "\"!"); return false; } return SaveAssetFromMemoryToFile(&data[0], data.size(), filename); }
void JoinCascador::Snapshot() const { int stage_idx = current_stage_idx; int cart_idx = current_cart_idx; char buff1[256]; char buff2[256]; time_t t = time(NULL); strftime(buff1, sizeof(buff1), "%Y%m%d-%H%M%S", localtime(&t)); sprintf(buff2, "../model/jda_tmp_%s_stage_%d_cart_%d.model", \ buff1, stage_idx + 1, cart_idx + 1); FILE* fd = fopen(buff2, "wb"); JDA_Assert(fd, "Can not open a temp file to save the model"); SerializeTo(fd); fclose(fd); }
AssetPtr IAsset::Clone(QString newAssetName) const { assert(assetAPI); if (!IsLoaded()) return AssetPtr(); AssetPtr existing = assetAPI->GetAsset(newAssetName); if (existing) { LogError("Cannot Clone() asset \"" + Name() + "\" to a new asset \"" + newAssetName + "\": An asset with that name already exists!"); return AssetPtr(); } std::vector<u8> data; bool success = SerializeTo(data); if (!success) { LogError("Cannot Clone() asset \"" + Name() + "\" to a new asset \"" + newAssetName + "\": Serializing the asset failed!"); return AssetPtr(); } if (data.size() == 0) { LogError("Cannot Clone() asset \"" + Name() + "\" to a new asset \"" + newAssetName + "\": Asset serialization succeeded with zero size!"); return AssetPtr(); } AssetPtr newAsset = assetAPI->CreateNewAsset(this->Type(), newAssetName); if (!newAsset) { LogError("Cannot Clone() asset \"" + Name() + "\" to a new asset \"" + newAssetName + "\": AssetAPI::CreateNewAsset failed!"); return AssetPtr(); } // Do not allow asynchronous loading due the caller of this // expects the asset to be usable when this function returns. success = newAsset->LoadFromFileInMemory(&data[0], data.size(), false); if (!success) { LogError("Cannot Clone() asset \"" + Name() + "\" to a new asset \"" + newAssetName + "\": Deserializing the new asset from bytes failed!"); assetAPI->ForgetAsset(newAsset, false); return AssetPtr(); } return newAsset; }
const char *GStringList::Serialize(const char *pzDelimiter, int nStartIndex/* = 0*/, int nItemCount /* = -1*/) { m_strSerializeDest = ""; SerializeTo(m_strSerializeDest, pzDelimiter, nStartIndex, nItemCount); return m_strSerializeDest; }