diff options
| author | Dan Engelbrecht <[email protected]> | 2022-11-18 12:02:41 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-11-25 10:17:34 +0100 |
| commit | 5041f3521c2b3074032c06ed04a391ed90a06c7e (patch) | |
| tree | fbe6c18c79de5abff79394b69d65e38004d9e39e /zenhttp/httpshared.cpp | |
| parent | 0.1.9 (diff) | |
| download | zen-5041f3521c2b3074032c06ed04a391ed90a06c7e.tar.xz zen-5041f3521c2b3074032c06ed04a391ed90a06c7e.zip | |
reduce parsing of compressed headers
Diffstat (limited to 'zenhttp/httpshared.cpp')
| -rw-r--r-- | zenhttp/httpshared.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/zenhttp/httpshared.cpp b/zenhttp/httpshared.cpp index e2f061a87..23d9f9a30 100644 --- a/zenhttp/httpshared.cpp +++ b/zenhttp/httpshared.cpp @@ -344,7 +344,9 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint { if (i == 0) { - CompressedBuffer CompBuf(CompressedBuffer::FromCompressed(SharedBuffer(AttachmentBuffer))); + IoHash RawHash; + uint64_t RawSize; + CompressedBuffer CompBuf(CompressedBuffer::FromCompressed(SharedBuffer(AttachmentBuffer), RawHash, RawSize)); if (!CompBuf) { throw std::runtime_error(fmt::format("invalid format for chunk #{} expected compressed buffer for CbObject", i)); @@ -360,16 +362,22 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint else { // Make a copy of the buffer so we attachements don't reference the entire payload - IoBuffer AttachmentBufferCopy = CreateBuffer(Entry.AttachmentHash, AttachmentSize); - ZEN_ASSERT(AttachmentBufferCopy); - ZEN_ASSERT(AttachmentBufferCopy.Size() == AttachmentSize); - AttachmentBufferCopy.GetMutableView().CopyFrom(AttachmentBuffer.GetView()); - - CompressedBuffer CompBuf(CompressedBuffer::FromCompressed(SharedBuffer(AttachmentBufferCopy))); + // IoBuffer AttachmentBufferCopy = CreateBuffer(Entry.AttachmentHash, AttachmentSize); + // ZEN_ASSERT(AttachmentBufferCopy); + // ZEN_ASSERT(AttachmentBufferCopy.Size() == AttachmentSize); + // AttachmentBufferCopy.GetMutableView().CopyFrom(AttachmentBuffer.GetView()); + + IoHash RawHash; + uint64_t RawSize; + CompressedBuffer CompBuf(CompressedBuffer::FromCompressed(SharedBuffer(AttachmentBuffer), RawHash, RawSize)); if (!CompBuf) { throw std::runtime_error(fmt::format("invalid format for chunk #{} expected compressed buffer for attachment", i)); } + if (RawHash != Entry.AttachmentHash) + { + throw std::runtime_error(fmt::format("invalid hash for chunk #{} for attachment", i)); + } Attachments.emplace_back(CbAttachment(std::move(CompBuf), Entry.AttachmentHash)); } @@ -531,7 +539,13 @@ CbPackageReader::Finalize() } else if (Entry.Flags & CbAttachmentEntry::kIsCompressed) { - m_RootObject = LoadCompactBinaryObject(CompressedBuffer::FromCompressed(SharedBuffer(AttachmentBuffer))); + IoHash RawHash; + uint64_t RawSize; + CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(AttachmentBuffer), RawHash, RawSize); + if (RawHash == Entry.AttachmentHash) + { + m_RootObject = LoadCompactBinaryObject(Compressed); + } } else { @@ -549,13 +563,19 @@ CbPackageReader::Finalize() if (Entry.Flags & CbAttachmentEntry::kIsCompressed) { - m_Attachments.push_back(CbAttachment(CompressedBuffer::FromCompressed(SharedBuffer(ChunkReference)), Entry.AttachmentHash)); + IoHash RawHash; + uint64_t RawSize; + CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(ChunkReference), RawHash, RawSize); + if (RawHash == Entry.AttachmentHash) + { + m_Attachments.push_back(CbAttachment(Compressed, Entry.AttachmentHash)); + } } else { CompressedBuffer Compressed = CompressedBuffer::Compress(SharedBuffer(ChunkReference), OodleCompressor::NotSet, OodleCompressionLevel::None); - m_Attachments.push_back(CbAttachment(std::move(Compressed), IoHash::FromBLAKE3(Compressed.GetRawHash()))); + m_Attachments.push_back(CbAttachment(std::move(Compressed), IoHash::FromBLAKE3(Compressed.DecodeRawHash()))); } } |