diff options
| author | Dan Engelbrecht <[email protected]> | 2025-10-03 14:52:01 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-10-03 14:52:01 +0200 |
| commit | a2a19b533bbcdab37b7704a8b89a22069db39ec8 (patch) | |
| tree | 7e4cc4a9c9ede02db1dbef16883698cd0474e11b /src/zenutil | |
| parent | move zen vfs implementation to zenstore (#549) (diff) | |
| download | zen-a2a19b533bbcdab37b7704a8b89a22069db39ec8.tar.xz zen-a2a19b533bbcdab37b7704a8b89a22069db39ec8.zip | |
zenutil cleanup (#550)
* move referencemetadata to zenstore
* rename zenutil/windows/service to windowsservice
Diffstat (limited to 'src/zenutil')
| -rw-r--r-- | src/zenutil/include/zenutil/referencemetadata.h | 109 | ||||
| -rw-r--r-- | src/zenutil/include/zenutil/windows/windowsservice.h (renamed from src/zenutil/include/zenutil/windows/service.h) | 0 | ||||
| -rw-r--r-- | src/zenutil/referencemetadata.cpp | 32 | ||||
| -rw-r--r-- | src/zenutil/service.cpp | 2 | ||||
| -rw-r--r-- | src/zenutil/windows/windowsservice.cpp (renamed from src/zenutil/windows/service.cpp) | 2 |
5 files changed, 2 insertions, 143 deletions
diff --git a/src/zenutil/include/zenutil/referencemetadata.h b/src/zenutil/include/zenutil/referencemetadata.h deleted file mode 100644 index 5160bfb8b..000000000 --- a/src/zenutil/include/zenutil/referencemetadata.h +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include <zencore/compositebuffer.h> - -ZEN_THIRD_PARTY_INCLUDES_START -#include <gsl/gsl-lite.hpp> -ZEN_THIRD_PARTY_INCLUDES_END - -namespace zen { - -#pragma pack(push) -#pragma pack(1) - -struct ReferenceMetaDataHeader -{ - static constexpr uint32_t Version1 = 1; - static constexpr uint32_t CurrentVersion = Version1; - - ReferenceMetaDataHeader(uint32_t InMagic, uint32_t InEntryCount, uint64_t InAttachmentCount) - : Magic(InMagic) - , EntryCount(InEntryCount) - , AttachmentCount(InAttachmentCount) - , Checksum(ComputeChecksum()) - { - } - - uint32_t Magic = 0xffffffffu; - uint32_t Version = CurrentVersion; - - uint32_t EntryCount = 0; - uint64_t AttachmentCount = 0; - uint64_t Padding = 0; - - uint32_t Checksum = 0; - - bool IsValid(uint32_t ExpectedMagic) const; - - template<typename KeyType, typename AttachmentType> - static uint64_t ExpectedSize(uint32_t EntryCount, uint64_t AttachmentCount) - { - return sizeof(ReferenceMetaDataHeader) + sizeof(KeyType) * EntryCount + sizeof(uint32_t) * EntryCount + - sizeof(AttachmentType) * AttachmentCount; - } - - ReferenceMetaDataHeader() = delete; - -private: - uint32_t ComputeChecksum() const; -}; - -static_assert(sizeof(ReferenceMetaDataHeader) == 32); - -#pragma pack(pop) - -template<typename KeyType, typename AttachmentType> -CompositeBuffer -BuildReferenceMetaData(uint32_t HeaderMagic, - std::span<const KeyType> Keys, - std::span<const uint32_t> AttachmentCounts, - std::span<const AttachmentType> Attachments) -{ - uint32_t KeyCount = gsl::narrow<uint32_t>(Keys.size()); - - ReferenceMetaDataHeader Header(HeaderMagic, KeyCount, Attachments.size()); - return CompositeBuffer(std::vector<SharedBuffer>{ - SharedBuffer(IoBuffer(IoBuffer::Clone, &Header, sizeof(ReferenceMetaDataHeader))), - SharedBuffer(IoBuffer(IoBuffer::Wrap, Keys.data(), sizeof(KeyType) * Keys.size())), - SharedBuffer(IoBuffer(IoBuffer::Wrap, AttachmentCounts.data(), sizeof(uint32_t) * AttachmentCounts.size())), - SharedBuffer(IoBuffer(IoBuffer::Wrap, Attachments.data(), sizeof(AttachmentType) * Attachments.size()))}); -} - -template<typename KeyType, typename AttachmentType> -bool -GetAttachmentsFromMetaData(const IoBuffer& MetaData, - const uint32_t ExpectedHeaderMagic, - std::function<void(std::span<const KeyType> Keys, - std::span<const uint32_t> AttachmentCounts, - std::span<const AttachmentType> Attachments)>&& Parser) -{ - MemoryView PayloadView = MetaData.GetView(); - if (PayloadView.GetSize() >= sizeof(ReferenceMetaDataHeader)) - { - const ReferenceMetaDataHeader* Header = (const ReferenceMetaDataHeader*)PayloadView.GetData(); - if (Header->IsValid(ExpectedHeaderMagic)) - { - if (MetaData.GetSize() == - ReferenceMetaDataHeader::ExpectedSize<KeyType, AttachmentType>(Header->EntryCount, Header->AttachmentCount)) - { - PayloadView.MidInline(sizeof(ReferenceMetaDataHeader)); - std::span<const KeyType> PayloadKeys = {(const KeyType*)PayloadView.GetData(), Header->EntryCount}; - PayloadView.MidInline(sizeof(KeyType) * Header->EntryCount); - std::span<const uint32_t> PayloadAttachmentCounts = {(const uint32_t*)PayloadView.GetData(), Header->EntryCount}; - PayloadView.MidInline(sizeof(uint32_t) * Header->EntryCount); - std::span<const AttachmentType> PayloadAttachments = {(const AttachmentType*)PayloadView.GetData(), - Header->AttachmentCount}; - PayloadView.MidInline(sizeof(AttachmentType) * Header->AttachmentCount); - ZEN_ASSERT(PayloadView.GetSize() == 0); - - Parser(PayloadKeys, PayloadAttachmentCounts, PayloadAttachments); - - return true; - } - } - } - return false; -} -} // namespace zen diff --git a/src/zenutil/include/zenutil/windows/service.h b/src/zenutil/include/zenutil/windows/windowsservice.h index ca0270a36..ca0270a36 100644 --- a/src/zenutil/include/zenutil/windows/service.h +++ b/src/zenutil/include/zenutil/windows/windowsservice.h diff --git a/src/zenutil/referencemetadata.cpp b/src/zenutil/referencemetadata.cpp deleted file mode 100644 index bbcafcfba..000000000 --- a/src/zenutil/referencemetadata.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include <zenutil/referencemetadata.h> -////////////////////////////////////////////////////////////////////////// - -#include <zencore/xxhash.h> - -namespace zen { - -uint32_t -ReferenceMetaDataHeader::ComputeChecksum() const -{ - return XXH32(&Magic, sizeof(ReferenceMetaDataHeader) - sizeof(uint32_t), 0xC0C0'BABA); -} - -bool -ReferenceMetaDataHeader::IsValid(uint32_t ExpectedMagic) const -{ - if (Magic != ExpectedMagic) - { - return false; - } - - if (Checksum != ComputeChecksum()) - { - return false; - } - - return true; -} - -} // namespace zen diff --git a/src/zenutil/service.cpp b/src/zenutil/service.cpp index e4a9a951e..103fdaa2f 100644 --- a/src/zenutil/service.cpp +++ b/src/zenutil/service.cpp @@ -10,7 +10,7 @@ #if ZEN_PLATFORM_WINDOWS # include <zencore/windows.h> -# include <zenutil/windows/service.h> +# include <zenutil/windows/windowsservice.h> #endif #if ZEN_PLATFORM_MAC # include <zencore/filesystem.h> diff --git a/src/zenutil/windows/service.cpp b/src/zenutil/windows/windowsservice.cpp index b76ed7a66..ebb88b018 100644 --- a/src/zenutil/windows/service.cpp +++ b/src/zenutil/windows/windowsservice.cpp @@ -3,7 +3,7 @@ #include <zencore/zencore.h> #if ZEN_PLATFORM_WINDOWS -# include <zenutil/windows/service.h> +# include <zenutil/windows/windowsservice.h> # include <zencore/except.h> # include <zencore/thread.h> |