diff options
Diffstat (limited to 'zenhttp/httpshared.cpp')
| -rw-r--r-- | zenhttp/httpshared.cpp | 22 |
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); } } |