aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-02 12:58:15 +0200
committerStefan Boberg <[email protected]>2021-09-02 12:58:15 +0200
commit6807b8309e10938eb4d5dcfeb29c66bf7f1cdd76 (patch)
treeecfa54df804937dd60c66d8a548ebf52a34a4f25
parentCompactBinary: Restricted compact binary attachments to objects to simplify p... (diff)
downloadzen-6807b8309e10938eb4d5dcfeb29c66bf7f1cdd76.tar.xz
zen-6807b8309e10938eb4d5dcfeb29c66bf7f1cdd76.zip
Added HashMemory() function accepting CompositeBuffer argument
-rw-r--r--zencore/include/zencore/iohash.h3
-rw-r--r--zencore/iohash.cpp14
2 files changed, 17 insertions, 0 deletions
diff --git a/zencore/include/zencore/iohash.h b/zencore/include/zencore/iohash.h
index 14049e2b2..853076129 100644
--- a/zencore/include/zencore/iohash.h
+++ b/zencore/include/zencore/iohash.h
@@ -1,4 +1,5 @@
// Copyright Epic Games, Inc. All Rights Reserved.
+// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
@@ -12,6 +13,7 @@
namespace zen {
class StringBuilderBase;
+class CompositeBuffer;
/**
* Hash used for content addressable storage
@@ -41,6 +43,7 @@ struct IoHash
static IoHash HashMemory(const void* data, size_t byteCount);
static IoHash HashMemory(MemoryView Data) { return HashMemory(Data.GetData(), Data.GetSize()); }
+ static IoHash HashMemory(const CompositeBuffer& Buffer);
static IoHash FromHexString(const char* string);
static IoHash FromHexString(const std::string_view string);
const char* ToHexString(char* outString /* 40 characters + NUL terminator */) const;
diff --git a/zencore/iohash.cpp b/zencore/iohash.cpp
index afe2e54ba..9b095ccdb 100644
--- a/zencore/iohash.cpp
+++ b/zencore/iohash.cpp
@@ -3,6 +3,7 @@
#include <zencore/iohash.h>
#include <zencore/blake3.h>
+#include <zencore/compositebuffer.h>
#include <zencore/string.h>
#include <doctest/doctest.h>
@@ -24,6 +25,19 @@ IoHash::HashMemory(const void* data, size_t byteCount)
}
IoHash
+IoHash::HashMemory(const CompositeBuffer& Buffer)
+{
+ IoHashStream Hasher;
+
+ for (const SharedBuffer& Segment : Buffer.GetSegments())
+ {
+ Hasher.Append(Segment.GetData(), Segment.GetSize());
+ }
+
+ return Hasher.GetHash();
+}
+
+IoHash
IoHash::FromHexString(const char* string)
{
return FromHexString({string, sizeof(IoHash::Hash) * 2});