9 SchemaCatalog SchemaCatalog::_materialize(std::span<const unsigned char> bytes, std::vector<unsigned char> owned) {
10 const blob::View view{bytes};
12 out._owned = std::move(owned);
14 out._eras.reserve(view.eraCount());
15 for (std::size_t i = 0; i < view.eraCount(); ++i) out._eras.push_back(view.era(i));
17 out._columns.reserve(view.columnCount());
18 for (std::size_t i = 0; i < view.columnCount(); ++i) {
19 const blob::ColumnEntry entry = view.column(i);
21 col.name = view.stringAt(entry.nameOff).data();
22 col.dbdName = view.stringAt(entry.dbdNameOff).data();
23 col.type = entry.type;
24 col.bits = entry.bits;
25 col.isSigned = entry.isSigned;
26 col.arrayLen = entry.arrayLen;
27 col.localeCount = entry.localeCount;
28 col.isId = entry.isId;
29 col.isRelation = entry.isRelation;
30 col.noninline = entry.noninline;
31 out._columns.push_back(col);
34 out._ranges.reserve(view.rangeCount());
35 for (std::size_t i = 0; i < view.rangeCount(); ++i) {
36 const blob::RangeEntry entry = view.range(i);
37 out._ranges.push_back(RangeIndex{entry.firstColumn, entry.columnCount, entry.eraMask});
40 out._tables.reserve(view.tableCount());
41 for (std::size_t i = 0; i < view.tableCount(); ++i) {
42 const blob::TableEntry entry = view.table(i);
43 out._tables.push_back(TableIndex{
44 view.stringAt(entry.nameOff),
45 view.stringAt(entry.diskNameOff),
53#if WOWLIB_DB_SCHEMA_RUNTIME
55 const blob::View view{bytes};
58 "not a WDBS v2 schema blob (bad magic, version or " "section bounds)");
61 std::vector<unsigned char> owned{std::move(bytes)};
62 const std::span<const unsigned char> stable{owned};
63 return _materialize(stable, std::move(owned));
65 std::ifstream in{path, std::ios::binary};
68 std::vector<unsigned char> bytes{std::istreambuf_iterator<char>{in}, std::istreambuf_iterator<char>{}};
69 if (!in.good() && !in.eof())
71 return fromBlob(std::move(bytes));
76 for (std::size_t i = 0; i < _eras.size(); ++i)
77 if (_eras[i].major == version.major)
return i;
79 "no targeted era shares major version " + std::to_string(version.major));
85 std::size_t hi = _tables.size();
86 const TableIndex* found =
nullptr;
88 const std::size_t mid = lo + (hi - lo) / 2;
89 const TableIndex& entry = _tables[mid];
90 if (entry.name == table) {
94 if (entry.name < table) lo = mid + 1;
100 for (std::size_t r = 0; r < found->rangeCount; ++r) {
101 const RangeIndex& range = _ranges[found->firstRange + r];
102 if ((range.eraMask & (std::uint16_t{1} << era)) == 0)
continue;
106 std::span<const Column>{_columns}.subspan(range.firstColumn, range.columnCount)
110 "table '" + std::string{found->name} +
"' has no schema for the era of build " + std::to_string(
115#if WOWLIB_DB_SCHEMA_EMBEDDED
120 constexpr unsigned char EmbeddedSchemaBlob[] = {
121#embed <wowlib_schema.wdbs>
123 static_assert(blob::View{std::span<const unsigned char>{EmbeddedSchemaBlob}}.valid(),
124 "the embedded schema blob failed structural validation — "
125 "dbdgen output and schema_blob.hpp disagree on the format");
127 static const SchemaCatalog Catalog = _materialize(std::span<const unsigned char>{detail::EmbeddedSchemaBlob}, {});
The parsed, materialized form of one WDBS schema blob.
SchemaCatalog(SchemaCatalog &&) noexcept=default
Result< TableSchema > lookup(std::string_view table, ClientVersion version) const
Resolve the schema of table for client version.
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
std::unexpected< Error > makeError(ErrorCode code, std::string message, std::uint32_t nativeError=0)
Shorthand for constructing the error branch of a Result.
@ TableUnknown
The schema catalog knows no table of the requested name.
@ UnsupportedClientVersion
No format instantiation exists for the requested client version.
@ SchemaBlobInvalid
A WDBS schema blob (or WoWDBDefs source) is malformed or truncated.
@ IoError
Generic filesystem I/O failure (project directory).
The WDBS schema-blob format: a constexpr-parseable view over the compact binary dbdgen emits (--schem...
The runtime schema source of the generic ClientDB engine: table name + client version in,...
std::uint32_t build
Exact client build number, e.g.
One resolved (table, client version) schema: what SchemaCatalog::lookup hands the engine.