diff options
| author | Dan Engelbrecht <[email protected]> | 2025-10-02 16:35:22 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-10-02 16:35:22 +0200 |
| commit | 289379b55d19e08c47afb54a363fda9478623b9d (patch) | |
| tree | da2eb6aa2f95833c0c7063c6f71dc9576512d7c1 /src/zenstore/oplogreferencedset.cpp | |
| parent | fix for RPC replay issue (wrong content-type) (#536) (diff) | |
| download | zen-289379b55d19e08c47afb54a363fda9478623b9d.tar.xz zen-289379b55d19e08c47afb54a363fda9478623b9d.zip | |
move projectstore to zenstore (#541)
Diffstat (limited to 'src/zenstore/oplogreferencedset.cpp')
| -rw-r--r-- | src/zenstore/oplogreferencedset.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/zenstore/oplogreferencedset.cpp b/src/zenstore/oplogreferencedset.cpp new file mode 100644 index 000000000..f34b80b1a --- /dev/null +++ b/src/zenstore/oplogreferencedset.cpp @@ -0,0 +1,95 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include <zenstore/oplogreferencedset.h> + +#include <zenstore/projectstore.h> + +#include <zencore/iobuffer.h> +#include <zencore/logging.h> +#include <zencore/string.h> + +namespace zen { + +std::optional<OplogReferencedSet> +OplogReferencedSet::LoadFromChunk(const IoBuffer& ChunkData) +{ + using namespace std::literals; + + if (!ChunkData || ChunkData.Size() == 0) + { + return std::optional<OplogReferencedSet>(); + } + std::string_view ChunkText(reinterpret_cast<const char*>(ChunkData.Data()), ChunkData.Size()); + + AsciiSet TrimWhitespace(" \t\r\n"); + const char* FirstNonComment = nullptr; + uint64_t Version = 0; + + // Parse the initial comment block: the leading block of empty or comment lines. + ForEachStrTok(ChunkText, '\n', [&Version, &FirstNonComment, &TrimWhitespace](std::string_view Line) { + Line = AsciiSet::TrimSuffixWith(AsciiSet::TrimPrefixWith(Line, TrimWhitespace), TrimWhitespace); + if (Line.empty()) + { + return true; // empty line, keep reading + } + if (!Line.starts_with('#')) + { + FirstNonComment = Line.data(); + return false; // non-comment line, stop + } + + // Comment line in the header block of comments in the file. Interpret it if it is a version line. + // Skip past the '#' and whitespace. + Line.remove_prefix(1); + Line = AsciiSet::TrimPrefixWith(Line, TrimWhitespace); + + // Parse "# Version <uint64>". + constexpr std::string_view VersionStr("Version "sv); + if (Line.starts_with(VersionStr)) + { + std::string_view VersionToken = Line; + VersionToken.remove_prefix(VersionStr.length()); + VersionToken.remove_suffix(AsciiSet::TrimPrefixWithout(VersionToken, TrimWhitespace).length()); + std::optional<uint64_t> ParsedVersion = ParseInt<uint64_t>(VersionToken); + if (ParsedVersion) + { + Version = *ParsedVersion; + } + } + return true; + }); + + // Report no referencedset if the version is below our minimum version. + constexpr uint64_t MinSupportedVersion = 1; + if (Version < MinSupportedVersion) + { + ZEN_WARN("ReferencedSet is below the minimum supported version, ignoring it. Version: {}, minimum version: {}.", + Version, + MinSupportedVersion); + return std::optional<OplogReferencedSet>(); + } + + // Parse the remaining lines after the leading comment block. + ChunkText.remove_prefix(FirstNonComment ? FirstNonComment - ChunkText.data() : ChunkText.length()); + + eastl::fixed_vector<uint8_t, 256> TmpBuffer; + + OplogReferencedSet Result; + ForEachStrTok(ChunkText, '\n', [&Result, &TrimWhitespace, &TmpBuffer](std::string_view Line) { + Line = AsciiSet::TrimSuffixWith(AsciiSet::TrimPrefixWith(Line, TrimWhitespace), TrimWhitespace); + if (!Line.empty() && !Line.starts_with('#')) + { + Result.Set.emplace(OpKeyStringAsOid(Line, TmpBuffer)); + } + return true; + }); + return std::optional<OplogReferencedSet>(std::move(Result)); +} + +void +OplogReferencedSet::Clear() +{ + Set.clear(); +} + +} // namespace zen |