aboutsummaryrefslogtreecommitdiff
path: root/zenhttp/httpshared.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-13 22:25:03 +0200
committerStefan Boberg <[email protected]>2021-09-13 22:25:03 +0200
commitf277fad0ea747807021bb92ae8fd026384901fb7 (patch)
treeffdcb6af33450105d3dc0d5046bec8090d6dff27 /zenhttp/httpshared.cpp
parentChanged package parsing test code (diff)
downloadzen-f277fad0ea747807021bb92ae8fd026384901fb7.tar.xz
zen-f277fad0ea747807021bb92ae8fd026384901fb7.zip
Implemented intended package streaming API flow (but currently it "streams" from memory)
Diffstat (limited to 'zenhttp/httpshared.cpp')
-rw-r--r--zenhttp/httpshared.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/zenhttp/httpshared.cpp b/zenhttp/httpshared.cpp
index 85687b60b..68252a763 100644
--- a/zenhttp/httpshared.cpp
+++ b/zenhttp/httpshared.cpp
@@ -81,16 +81,16 @@ FormatPackageMessage(const CbPackage& Data)
}
CbPackage
-ParsePackageMessage(IoBuffer Payload)
+ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint64_t)> CreateBuffer)
{
- MemoryInStream InStream(Payload);
- BinaryReader Reader(InStream);
-
if (!Payload)
{
return {};
}
+ MemoryInStream InStream(Payload);
+ BinaryReader Reader(InStream);
+
CbPackage Package;
CbPackageHeader Hdr;
@@ -110,18 +110,24 @@ ParsePackageMessage(IoBuffer Payload)
for (uint32_t i = 0; i < ChunkCount; ++i)
{
- const uint64_t AttachmentSize = AttachmentEntries[i].AttachmentSize;
- IoBuffer AttachmentBuffer{AttachmentSize};
+ const CbAttachmentEntry& Entry = AttachmentEntries[i];
+ const uint64_t AttachmentSize = Entry.AttachmentSize;
+ IoBuffer AttachmentBuffer = CreateBuffer(Entry.AttachmentHash, AttachmentSize);
+
+ ZEN_ASSERT(AttachmentBuffer);
+ ZEN_ASSERT(AttachmentBuffer.Size() == AttachmentSize);
+
Reader.Read(AttachmentBuffer.MutableData(), AttachmentSize);
+
CompressedBuffer CompBuf(CompressedBuffer::FromCompressed(SharedBuffer(AttachmentBuffer)));
if (i == 0)
{
- Package.SetObject(LoadCompactBinaryObject(CompBuf));
+ Package.SetObject(LoadCompactBinaryObject(std::move(CompBuf)));
}
else
{
- CbAttachment Attachment(CompBuf);
+ CbAttachment Attachment(std::move(CompBuf));
Package.AddAttachment(Attachment);
}
}