aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-11 21:54:35 +0200
committerStefan Boberg <[email protected]>2021-05-11 21:54:35 +0200
commit57384321386f01f6e0f80e3984f08c05a0bb7a42 (patch)
treed63d45f885478f23967135788f8a434a596d0b8d
parentAdded paths as context to I/O error exception messages (diff)
downloadzen-57384321386f01f6e0f80e3984f08c05a0bb7a42.tar.xz
zen-57384321386f01f6e0f80e3984f08c05a0bb7a42.zip
Implemented basic support for marshaling attachments out-of-band with the package payload
Currently supported in project store but will also be used for the structured cache Currently, cleanup is missing. Ultimately the intent is that the file used for marshaling will simply be moved into place.
-rw-r--r--zencore/compactbinarypackage.cpp14
-rw-r--r--zencore/include/zencore/compactbinarypackage.h5
-rw-r--r--zenserver/projectstore.cpp15
-rw-r--r--zenserver/projectstore.h1
4 files changed, 29 insertions, 6 deletions
diff --git a/zencore/compactbinarypackage.cpp b/zencore/compactbinarypackage.cpp
index 21883f5b1..9eb67ac93 100644
--- a/zencore/compactbinarypackage.cpp
+++ b/zencore/compactbinarypackage.cpp
@@ -299,12 +299,12 @@ CbPackage::GatherAttachments(const CbFieldViewIterator& Fields, AttachmentResolv
}
void
-CbPackage::Load(IoBuffer& InBuffer, BufferAllocator Allocator)
+CbPackage::Load(IoBuffer& InBuffer, BufferAllocator Allocator, AttachmentResolver* Mapper)
{
MemoryInStream InStream(InBuffer.Data(), InBuffer.Size());
BinaryReader Reader(InStream);
- Load(Reader, Allocator);
+ Load(Reader, Allocator, Mapper);
}
void
@@ -345,7 +345,7 @@ CbPackage::Load(CbFieldIterator& Fields)
}
void
-CbPackage::Load(BinaryReader& Reader, BufferAllocator Allocator)
+CbPackage::Load(BinaryReader& Reader, BufferAllocator Allocator, AttachmentResolver* Mapper)
{
uint8_t StackBuffer[64];
const auto StackAllocator = [&Allocator, &StackBuffer](uint64_t Size) -> UniqueBuffer {
@@ -386,6 +386,14 @@ CbPackage::Load(BinaryReader& Reader, BufferAllocator Allocator)
}
}
}
+ else if (ValueField.IsHash())
+ {
+ const IoHash Hash = ValueField.AsHash();
+
+ ZEN_ASSERT(Mapper);
+
+ AddAttachment(CbAttachment((*Mapper)(Hash), Hash));
+ }
else
{
ZEN_ASSERT(ValueField.IsObject(), "Expected Object, Binary, or Null field when loading a package");
diff --git a/zencore/include/zencore/compactbinarypackage.h b/zencore/include/zencore/compactbinarypackage.h
index c98ab047f..03098f494 100644
--- a/zencore/include/zencore/compactbinarypackage.h
+++ b/zencore/include/zencore/compactbinarypackage.h
@@ -16,6 +16,7 @@ class CbWriter;
class BinaryReader;
class BinaryWriter;
class IoBuffer;
+class CbAttachment;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -278,9 +279,9 @@ public:
*/
ZENCORE_API void Load(CbFieldIterator& Fields);
- ZENCORE_API void Load(IoBuffer& Buffer, BufferAllocator Allocator = UniqueBuffer::Alloc);
+ ZENCORE_API void Load(IoBuffer& Buffer, BufferAllocator Allocator = UniqueBuffer::Alloc, AttachmentResolver* Mapper = nullptr);
- ZENCORE_API void Load(BinaryReader& Reader, BufferAllocator Allocator = UniqueBuffer::Alloc);
+ ZENCORE_API void Load(BinaryReader& Reader, BufferAllocator Allocator = UniqueBuffer::Alloc, AttachmentResolver* Mapper = nullptr);
/** Save the object and attachments into the writer as a stream of compact binary fields. */
ZENCORE_API void Save(CbWriter& Writer) const;
diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp
index 0dc0da1ae..c2c8c2421 100644
--- a/zenserver/projectstore.cpp
+++ b/zenserver/projectstore.cpp
@@ -1057,8 +1057,21 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects)
IoBuffer Payload = HttpReq.ReadPayload();
+ CbPackage::AttachmentResolver Resolver = [&](const IoHash& Hash) -> SharedBuffer {
+ std::filesystem::path AttachmentPath = Log.TempPath() / Hash.ToHexString();
+
+ if (IoBuffer Data = IoBufferBuilder::MakeFromFile(AttachmentPath.native().c_str()))
+ {
+ return SharedBuffer::Clone(MemoryView(Data.Data(), Data.Size()));
+ }
+ else
+ {
+ return {};
+ }
+ };
+
CbPackage Package;
- Package.Load(Payload);
+ Package.Load(Payload, &UniqueBuffer::Alloc, &Resolver);
CbObject Core = Package.GetObject();
diff --git a/zenserver/projectstore.h b/zenserver/projectstore.h
index 4ad0e42e0..0b41b837b 100644
--- a/zenserver/projectstore.h
+++ b/zenserver/projectstore.h
@@ -88,6 +88,7 @@ public:
const std::string& OplogId() const { return m_OplogId; }
const std::wstring& TempDir() const { return m_TempPath.native(); }
+ const std::filesystem::path& TempPath() const { return m_TempPath; }
spdlog::logger& Log() { return m_OuterProject->Log(); }