载入中...
搜索中...
未找到
ImportCommon.h
浏览该文件的文档.
1#pragma once
2
4
5#include "common/Export.h"
6#include "data/HashFunction.h"
7
8#include <algorithm>
9#include <cctype>
10
12
14inline std::string sha256(std::span<const std::uint8_t> bytes) {
18 ->hash("sha256", reinterpret_cast<const char*>(bytes.data()), bytes.size(), digest);
19 static constexpr char digits[] = "0123456789abcdef";
20 std::string result = "sha256:";
21 result.reserve(71);
22 for (std::size_t index = 0; index < 32; ++index) {
23 const auto byte = static_cast<unsigned char>(digest.data[index]);
24 result.push_back(digits[byte >> 4]);
25 result.push_back(digits[byte & 0x0f]);
26 }
27 return result;
28}
29
32 std::string_view importer) {
33 if (package.packageId.isNil() || package.packageName.empty() || package.packageVersion.empty())
36 "package identity, name and version are required",
37 {}, {}, "asset.import"));
38 asset::EvaManifest manifest;
39 manifest.packageId = package.packageId;
40 manifest.packageName = package.packageName;
41 manifest.packageVersion = package.packageVersion;
42 manifest.provenance = package.provenance;
43 manifest.provenance["importer"] = Value(std::string(importer));
44 manifest.provenance["importerVersion"] = Value(std::int64_t(1));
46 return Result<asset::EvaManifest>::success(std::move(manifest));
47}
48
51 auto reference = AssetRef::fromId(id);
52 if (!reference) return Result<AssetRef>::failure(reference.status());
54 return Result<AssetRef>::success(std::move(reference).takeValue());
55}
56
58inline std::string extension(std::string_view name) {
59 const auto dot = name.find_last_of('.');
60 if (dot == std::string_view::npos) return {};
62 std::string result(name.substr(dot + 1));
64 std::transform(result.begin(), result.end(), result.begin(), [](unsigned char value) {
65 return static_cast<char>(std::tolower(value));
66 });
67 return result;
68}
69
72 const ImportPackageIdentity& package,
73 std::string_view sourceEngine,
74 std::string_view sourceVersion,
76
77} // namespace eve::asset_import::detail
double value
Tool-side image and glTF importers producing canonical .eva candidates.
AuthorityStoreHandleRef reference
Definition Authority.cpp:24
#define EVENGINE_API_PLATFORM
Definition Export.h:107
std::uint64_t bytes
std::string name
std::string digest
const SquirrelValueOptions & options
uint32_t index
static Result< AssetRef > fromId(PersistentId id)
Build an asset reference from a non-nil persistent identity.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
static HashFunction * getHashFunction(std::string function)
Get a HashFunction instance for the given function.
virtual void hash(std::string function, const char *input, uint64_t length, Value &output) const =0
Hash the input, producing an set of bytes as output.
Id128 public API.
Definition Identity.h:112
constexpr bool isNil() const noexcept
Returns whether this value is the all-zero nil ID.
Definition Identity.h:176
std::string sha256(std::span< const std::uint8_t > bytes)
Sha 256.
std::string extension(std::string_view name)
Extension.
EVENGINE_API_PLATFORM Result< void > finalizeImportReport(PreparedAssetImport &prepared, const ImportPackageIdentity &package, std::string_view sourceEngine, std::string_view sourceVersion, Value::Object options={})
Append the deterministic mandatory import report and bind it from provenance.
Result< asset::EvaManifest > baseManifest(const ImportPackageIdentity &package, std::string_view importer)
Base manifest.
Result< AssetRef > assetRef(PersistentId id)
Asset ref.
Validated, owning .eva manifest.
Definition EvaManifest.h:62
std::string packageVersion
Definition EvaManifest.h:68
Value::Object provenance
Definition EvaManifest.h:72
Common stable package metadata supplied by an import transaction.
Owning, validated source archive candidate not yet published to disk/database.