aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/compactbinaryfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/compactbinaryfile.cpp')
-rw-r--r--src/zencore/compactbinaryfile.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/zencore/compactbinaryfile.cpp b/src/zencore/compactbinaryfile.cpp
new file mode 100644
index 000000000..f2121a0bd
--- /dev/null
+++ b/src/zencore/compactbinaryfile.cpp
@@ -0,0 +1,33 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#include "zencore/compactbinaryfile.h"
+#include "zencore/compactbinaryvalidation.h"
+
+#include <zencore/filesystem.h>
+
+namespace zen {
+
+CbObjectFromFile
+LoadCompactBinaryObject(const std::filesystem::path& FilePath)
+{
+ FileContents ObjectFile = ReadFile(FilePath);
+
+ if (ObjectFile.ErrorCode)
+ {
+ throw std::system_error(ObjectFile.ErrorCode);
+ }
+
+ IoBuffer ObjectBuffer = ObjectFile.Flatten();
+
+ if (CbValidateError Result = ValidateCompactBinary(ObjectBuffer, CbValidateMode::All); Result == CbValidateError::None)
+ {
+ CbObject Object = LoadCompactBinaryObject(ObjectBuffer);
+ const IoHash WorkerId = IoHash::HashBuffer(ObjectBuffer);
+
+ return {.Object = Object, .Hash = WorkerId};
+ }
+
+ return {.Hash = IoHash::Zero};
+}
+
+} // namespace zen