// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include #include "projectstore.h" #include namespace zen { class CidStore; class WorkerThreadPool; class RemoteProjectStore { public: struct Result { int32_t ErrorCode{}; double ElapsedSeconds{}; std::string Reason; std::string Text; }; struct SaveResult : public Result { std::unordered_set Needs; IoHash RawHash; }; struct FinalizeResult : public Result { std::unordered_set Needs; }; struct SaveAttachmentResult : public Result { }; struct SaveAttachmentsResult : public Result { }; struct LoadAttachmentResult : public Result { IoBuffer Bytes; }; struct LoadContainerResult : public Result { CbObject ContainerObject; }; struct LoadAttachmentsResult : public Result { std::vector> Chunks; }; struct RemoteStoreInfo { bool CreateBlocks; bool UseTempBlockFiles; std::string Description; }; RemoteProjectStore(); virtual ~RemoteProjectStore(); virtual RemoteStoreInfo GetInfo() const = 0; virtual SaveResult SaveContainer(const IoBuffer& Payload) = 0; virtual SaveAttachmentResult SaveAttachment(const CompositeBuffer& Payload, const IoHash& RawHash) = 0; virtual FinalizeResult FinalizeContainer(const IoHash& RawHash) = 0; virtual SaveAttachmentsResult SaveAttachments(const std::vector& Payloads) = 0; virtual LoadContainerResult LoadContainer() = 0; virtual LoadContainerResult LoadBaseContainer() = 0; virtual LoadAttachmentResult LoadAttachment(const IoHash& RawHash) = 0; virtual LoadAttachmentsResult LoadAttachments(const std::vector& RawHashes) = 0; }; struct RemoteStoreOptions { size_t MaxBlockSize = 128u * 1024u * 1024u; size_t MaxChunkEmbedSize = 1024u * 1024u; }; RemoteProjectStore::LoadContainerResult BuildContainer( CidStore& ChunkStore, ProjectStore::Project& Project, ProjectStore::Oplog& Oplog, size_t MaxBlockSize, size_t MaxChunkEmbedSize, bool BuildBlocks, const std::function& AsyncOnBlock, const std::function& OnLargeAttachment, const std::function)>& OnBlockChunks, tsl::robin_map* OutOptionalTempAttachments); // Set OutOptionalTempAttachments to nullptr to avoid embedding loose "additional files" class JobContext; RemoteProjectStore::Result SaveOplogContainer(ProjectStore::Oplog& Oplog, const CbObject& ContainerObject, const std::function& HasAttachment, const std::function&& Chunks)>& OnNeedBlock, const std::function& OnNeedAttachment, JobContext* OptionalContext); RemoteProjectStore::Result SaveOplog(CidStore& ChunkStore, RemoteProjectStore& RemoteStore, ProjectStore::Project& Project, ProjectStore::Oplog& Oplog, size_t MaxBlockSize, size_t MaxChunkEmbedSize, bool EmbedLooseFiles, bool BuildBlocks, bool UseTempBlocks, bool ForceUpload, JobContext* OptionalContext); RemoteProjectStore::Result LoadOplog(CidStore& ChunkStore, RemoteProjectStore& RemoteStore, ProjectStore::Oplog& Oplog, bool ForceDownload, JobContext* OptionalContext); CompressedBuffer GenerateBlock(std::vector&& Chunks); bool IterateBlock(IoBuffer&& CompressedBlock, std::function Visitor); } // namespace zen