wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
wowlib::db Namespace Reference

Namespaces

namespace  blob
namespace  detail
namespace  wdc

Classes

struct  Column
 One column of a record schema, derived from a record member by reflection (typed records) or from the schema catalog (the generic table). More...
struct  ColumnAccess
 Everything the erased core needs to touch one column of a record: where it lives, what it is, and how its array elements stride. More...
class  DynTable
 The generic client-database table: schema resolved at runtime from the schema catalog, rows in a column store, format engine and preserved decode state inherited from TableBase (read/write/validate/strings/ encryptedSections all bind once, there). More...
struct  EncryptedSection
 One WDC section whose records could not be decoded because they are encrypted under a TACT key wowlib does not hold. More...
class  ErasedRecordSink
 RecordSink over a live std::vector<Record>& — the decode target. More...
class  ErasedRecordSource
 RecordSource over a const std::vector<Record>& — the encode source. More...
struct  LocString
 A decoded pre-Cataclysm localized string column: Langs language slots (8 before TBC 2.1.0.6692 added ruRU, 16 after) plus the trailing locale flags field. More...
struct  PodColumnView
 A scalar column's whole storage, for zero-copy array views: the raw exact-width buffer plus the facts to type it (rows x elements_per_row matrix, row-major). More...
struct  RecordOps
 The one thing that stays per-record: a table of thunks over the record VECTOR (only they know sizeof(Record)) plus the access table above. More...
class  RecordSink
 The decode target: the codecs build the record vector through this, one field at a time. More...
class  RecordSource
 The encode source: the codecs read the record vector through this. More...
class  SchemaCatalog
 The parsed, materialized form of one WDBS schema blob. More...
class  Table
 A client database table: the typed records of one DBFilesClient file. More...
class  TableBase
 The welded supertype of every generated table class: the whole table surface — decode, encode, validation, the preserved-state getters — bound ONCE and inherited, in every language, by all ~4200 generated (table x era) classes. More...
class  TableCore
 The erased engine of one table: identity + records access + preserved decode state, with every operation's body compiled once. More...
struct  TableInfo
 The per-table identity a codec needs beyond the record data: the client version (format selection, diagnostics), the WoWDBDefs table name (diagnostics), and the runtime schema. More...
struct  TableSchema
 One resolved (table, client version) schema: what SchemaCatalog::lookup hands the engine. More...
struct  TableState
 The preserved decode state a table carries between read() and write() so a WDBC/WDB2 write is byte-perfect and a WDC write reproduces the original compression. More...
class  TypedTable
 A typed, consteval-validated face over one DynTable: the table itself stays fully generic (every column decodes, byte-perfect round-trip holds); this projects rows into Record values, copies edits back, and hands out zero-copy typed column spans. More...
struct  Wdb2Header
 The 48-byte WDB2 header (wowdev.wiki/DB2). More...
struct  WdbcHeader
 The 20-byte WDBC header (wowdev.wiki/DBC). More...

Concepts

concept  TableRecord
 A type the table engine can carry as its record: a flat generated (or hand-written test) struct naming its client version and table.

Typedefs

using LocString8 = LocString<8>
 The vanilla-era column shape: 8 language slots (pre-2.1.0.6692).
using LocString16 = LocString<16>
 The TBC..WotLK column shape: 16 language slots (2.1.0.6692+).

Enumerations

enum class  EncryptedPolicy { Preserve , Drop }
 How write() treats a table that still holds keyless (undecryptable) encrypted sections. More...
enum class  ColumnType : std::uint8_t { Int , Float , String , LocString }
 The logical value class of a column. More...
enum class  AccessKind
 The storage kind of one record member, as the erased accessors see it: exact width and signedness for integers (the store must truncate the codec's int64 exactly as the typed member assignment did), float, std::string, or LocString. More...

Functions

constexpr std::optional< std::size_t > localeColumnSlot (Locale locale)
 The langstringref column slot locale occupies, in the client's fixed column order (0 enUS/enGB, 1 koKR, 2 frFR, 3 deDE, 4 zhCN, 5 zhTW, 6 esES, 7 esMX, 8 ruRU, 10 ptBR, 11 itIT — slots 9 and 12..15 belong to locales wowlib does not model).
template<typename Record>
consteval auto schemaOf ()
 The column schema of record Record, derived by reflection: one Column per member, declaration order, with the annotation-carried roles applied.
template<typename Record>
consteval std::size_t recordStride ()
 The fixed record stride of Record inside a WDBC/WDB2 record block.
template<typename Record>
consteval std::uint32_t fieldSlotCount ()
 The expanded on-disk field slot count of Record (the WDBC/WDB2 header fieldCount a fresh write derives).
template<typename Record>
consteval std::size_t stringSlotCount ()
 The string-block references one record of Record stores — the width of the engine's per-record original-offset journal.
Result< void > readWdb2 (const TableInfo &info, std::span< const std::byte > data, RecordSink &sink, TableState &state)
 Decode a WDB2 image: header, optional id-index block, fixed-stride records, string block, optional trailing copy table (index/copy preserved verbatim).
Result< FileBuffer > writeWdb2 (const TableInfo &info, const RecordSource &source, const TableState &state)
 Encode a WDB2 image; header identity and the verbatim index/copy blocks are re-emitted.
Result< void > readWdbc (const TableInfo &info, std::span< const std::byte > data, RecordSink &sink, TableState &state)
 Decode a WDBC image: 20-byte header, fixed-stride records, string block.
Result< FileBuffer > writeWdbc (const TableInfo &info, const RecordSource &source, const TableState &state)
 Encode a WDBC image; the string block preserves decoded offsets and appends new/changed strings (byte-perfect for an unmodified table).

Variables

constexpr detail::IdSpec Id {}
 Mark the table's primary-key column ($id$ in WoWDBDefs).
constexpr detail::NoninlineSpec Noninline {}
 Mark a column stored outside the record image ($noninline$ in WoWDBDefs): ids delivered by the WDC id list, relations delivered by the relationship block.
constexpr detail::RelationSpec Relation {}
 Mark a relationship-key column ($relation$ in WoWDBDefs): its value references the id of the table's parent (e.g.
constexpr std::uint32_t Wdb2Magic = formats::fourcc("WDB2", formats::FourCCEndian::Forward)
 The WDB2 magic as memcpy'd off the file front (the bytes "WDB2").
constexpr std::size_t Wdb2IndexEntryBytes = 6
 The per-id index block entry stride when maxId != 0: int32 indices[maxId - minId + 1] followed by int16 string_lengths[maxId - minId + 1] — 6 bytes per id in total.
constexpr std::uint32_t WdbcMagic = formats::fourcc("WDBC", formats::FourCCEndian::Forward)
 The WDBC magic as memcpy'd off the file front (the bytes "WDBC").

Typedef Documentation

◆ LocString16

The TBC..WotLK column shape: 16 language slots (2.1.0.6692+).

Definition at line 101 of file locstring.hpp.

◆ LocString8

The vanilla-era column shape: 8 language slots (pre-2.1.0.6692).

Definition at line 98 of file locstring.hpp.

Enumeration Type Documentation

◆ AccessKind

enum class wowlib::db::detail::AccessKind : std::uint8_t
strong

The storage kind of one record member, as the erased accessors see it: exact width and signedness for integers (the store must truncate the codec's int64 exactly as the typed member assignment did), float, std::string, or LocString.

Definition at line 45 of file record_bridge.hpp.

◆ ColumnType

enum class wowlib::db::ColumnType : std::uint8_t
strong

The logical value class of a column.

The logical value class of a table column.

Enumerator
Int 

An integer column; Column::bits / Column::isSigned give the shape.

Float 

A 32-bit IEEE float column.

String 

A string-block reference column (u32 offset on disk).

LocString 

A pre-Cataclysm localized string column (see LocString).

Definition at line 34 of file schema.hpp.

◆ EncryptedPolicy

enum class wowlib::db::EncryptedPolicy
strong

How write() treats a table that still holds keyless (undecryptable) encrypted sections.

Enumerator
Preserve 

Re-emit the original image verbatim; edits are not applied.

Drop 

Write only decoded rows as plaintext; keyless rows are dropped.

Definition at line 33 of file codec.hpp.

Function Documentation

◆ fieldSlotCount()

template<typename Record>
std::uint32_t wowlib::db::fieldSlotCount ( )
consteval

The expanded on-disk field slot count of Record (the WDBC/WDB2 header fieldCount a fresh write derives).

Template Parameters
Recordthe record type.
Returns
the field slot count.

Definition at line 250 of file schema.hpp.

References schemaOf().

◆ localeColumnSlot()

std::optional< std::size_t > wowlib::db::localeColumnSlot ( Locale locale)
constexpr

The langstringref column slot locale occupies, in the client's fixed column order (0 enUS/enGB, 1 koKR, 2 frFR, 3 deDE, 4 zhCN, 5 zhTW, 6 esES, 7 esMX, 8 ruRU, 10 ptBR, 11 itIT — slots 9 and 12..15 belong to locales wowlib does not model).

Parameters
localethe locale.
Returns
the slot index, or nullopt for locales without a fixed slot.

Definition at line 28 of file locstring.hpp.

References wowlib::deDE, wowlib::enGB, wowlib::enUS, wowlib::esES, wowlib::esMX, wowlib::frFR, wowlib::itIT, wowlib::koKR, wowlib::ptBR, wowlib::ruRU, wowlib::zhCN, and wowlib::zhTW.

Referenced by wowlib::db::LocString< 8 >::at(), and wowlib::db::LocString< 8 >::set().

◆ readWdb2()

Result< void > wowlib::db::readWdb2 ( const TableInfo & info,
std::span< const std::byte > data,
RecordSink & sink,
TableState & state )

◆ readWdbc()

Result< void > wowlib::db::readWdbc ( const TableInfo & info,
std::span< const std::byte > data,
RecordSink & sink,
TableState & state )

Decode a WDBC image: 20-byte header, fixed-stride records, string block.

Records are appended to sink; state keeps the string block and the per-field original-offset journal for a byte-perfect write-back.

Parameters
infothe table identity + schema.
datathe whole file content.
sinkthe decode target (records appended in file order).
statethe preserved-state store (reset and filled here).
Returns
nothing, or why the image does not decode.

Definition at line 17 of file wdbc.cpp.

References wowlib::db::RecordSink::add(), wowlib::db::RecordSink::clear(), wowlib::db::detail::decodeInlineRecord(), wowlib::db::TableState::fieldCount, wowlib::db::WdbcHeader::fieldCount, wowlib::db::WdbcHeader::magic, wowlib::makeError(), wowlib::db::TableInfo::name, wowlib::formats::StringBlock::read(), wowlib::db::WdbcHeader::recordCount, wowlib::db::TableState::recordSize, wowlib::db::WdbcHeader::recordSize, wowlib::db::detail::recordStride(), wowlib::db::RecordSink::reserve(), wowlib::db::TableState::reset(), wowlib::db::TableInfo::schema, wowlib::SchemaMismatch, wowlib::db::TableState::sourceMagic, wowlib::db::WdbcHeader::stringBlockSize, wowlib::db::TableState::stringOffsets, wowlib::db::TableState::strings, wowlib::db::detail::stringSlotCount(), and wowlib::TableTruncated.

Referenced by wowlib::db::TableCore::read().

◆ recordStride()

template<typename Record>
std::size_t wowlib::db::recordStride ( )
consteval

The fixed record stride of Record inside a WDBC/WDB2 record block.

Template Parameters
Recordthe record type.
Returns
the on-disk record size in bytes.

Definition at line 239 of file schema.hpp.

References schemaOf().

◆ schemaOf()

template<typename Record>
auto wowlib::db::schemaOf ( )
consteval

The column schema of record Record, derived by reflection: one Column per member, declaration order, with the annotation-carried roles applied.

Template Parameters
Recordthe record type.
Returns
a static span of Columns, never dangling.

Definition at line 220 of file schema.hpp.

References wowlib::db::detail::annotation(), wowlib::db::detail::classifyMember(), wowlib::db::Column::isId, wowlib::db::Column::isRelation, wowlib::db::Column::name, wowlib::db::Column::noninline, and wowlib::db::detail::recordMembers().

Referenced by fieldSlotCount(), wowlib::db::detail::idColumnOf(), wowlib::db::TypedTable< Record >::load(), recordStride(), stringSlotCount(), wowlib::db::detail::typedProjection(), wowlib::db::detail::typedValidate(), and wowlib::db::TypedTable< Record >::writeBack().

◆ stringSlotCount()

template<typename Record>
std::size_t wowlib::db::stringSlotCount ( )
consteval

The string-block references one record of Record stores — the width of the engine's per-record original-offset journal.

Template Parameters
Recordthe record type.
Returns
the per-record string slot count.

Definition at line 261 of file schema.hpp.

References schemaOf().

◆ writeWdb2()

Result< FileBuffer > wowlib::db::writeWdb2 ( const TableInfo & info,
const RecordSource & source,
const TableState & state )

◆ writeWdbc()

Result< FileBuffer > wowlib::db::writeWdbc ( const TableInfo & info,
const RecordSource & source,
const TableState & state )

Encode a WDBC image; the string block preserves decoded offsets and appends new/changed strings (byte-perfect for an unmodified table).

Parameters
infothe table identity + schema.
sourcethe records to encode.
statethe preserved-state store (read only).
Returns
the file bytes, or why encoding failed.

Definition at line 58 of file wdbc.cpp.

References wowlib::db::detail::StringPool::block, wowlib::db::detail::encodeInlineRecord(), wowlib::db::TableState::fieldCount, wowlib::db::WdbcHeader::fieldCount, wowlib::db::detail::fieldSlotCount(), wowlib::db::WdbcHeader::recordCount, wowlib::db::TableState::recordSize, wowlib::db::WdbcHeader::recordSize, wowlib::db::detail::recordStride(), wowlib::db::TableInfo::schema, wowlib::db::RecordSource::size(), wowlib::formats::StringBlock::size(), wowlib::db::TableState::sourceMagic, wowlib::db::WdbcHeader::stringBlockSize, wowlib::db::TableState::strings, and wowlib::formats::StringBlock::write().

Variable Documentation

◆ Id

detail::IdSpec wowlib::db::Id {}
inlineconstexpr

Mark the table's primary-key column ($id$ in WoWDBDefs).

Exactly one member per record carries it.

Definition at line 49 of file annotations.hpp.

◆ Noninline

detail::NoninlineSpec wowlib::db::Noninline {}
inlineconstexpr

Mark a column stored outside the record image ($noninline$ in WoWDBDefs): ids delivered by the WDC id list, relations delivered by the relationship block.

Combined with id or relation.

Definition at line 54 of file annotations.hpp.

◆ Relation

detail::RelationSpec wowlib::db::Relation {}
inlineconstexpr

Mark a relationship-key column ($relation$ in WoWDBDefs): its value references the id of the table's parent (e.g.

SpellID on the SpellX* satellites).

Definition at line 59 of file annotations.hpp.

◆ Wdb2IndexEntryBytes

std::size_t wowlib::db::Wdb2IndexEntryBytes = 6
inlineconstexpr

The per-id index block entry stride when maxId != 0: int32 indices[maxId - minId + 1] followed by int16 string_lengths[maxId - minId + 1] — 6 bytes per id in total.

Definition at line 50 of file wdb2.hpp.

Referenced by readWdb2().

◆ Wdb2Magic

std::uint32_t wowlib::db::Wdb2Magic = formats::fourcc("WDB2", formats::FourCCEndian::Forward)
inlineconstexpr

The WDB2 magic as memcpy'd off the file front (the bytes "WDB2").

Definition at line 27 of file wdb2.hpp.

Referenced by wowlib::db::TableCore::read(), and writeWdb2().

◆ WdbcMagic

std::uint32_t wowlib::db::WdbcMagic = formats::fourcc("WDBC", formats::FourCCEndian::Forward)
inlineconstexpr

The WDBC magic as memcpy'd off the file front (the bytes "WDBC").

Definition at line 25 of file wdbc.hpp.

Referenced by wowlib::db::TableCore::read().