aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/compactbinaryfile.cpp
blob: f2121a0bdc31feff16a115662e43b69e78d8efcb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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