From f277fad0ea747807021bb92ae8fd026384901fb7 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 13 Sep 2021 22:25:03 +0200 Subject: Implemented intended package streaming API flow (but currently it "streams" from memory) --- zenhttp/httpshared.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'zenhttp/httpshared.cpp') 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 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); } } -- cgit v1.2.3