wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
wdb2.hpp
Go to the documentation of this file.
1#pragma once
2
14
15#include <cstddef>
16#include <cstdint>
17#include <span>
18#include <type_traits>
19
21#include <wowlib/core/error.hpp>
22#include <wowlib/db/codec.hpp>
24
25namespace wowlib::db {
27 inline constexpr std::uint32_t Wdb2Magic = formats::fourcc("WDB2", formats::FourCCEndian::Forward);
28
30 struct Wdb2Header {
31 std::uint32_t magic = Wdb2Magic;
32 std::uint32_t recordCount = 0;
33 std::uint32_t fieldCount = 0;
34 std::uint32_t recordSize = 0;
35 std::uint32_t stringBlockSize = 0;
36 std::uint32_t tableHash = 0;
37 std::uint32_t build = 0;
38 std::uint32_t timestampLastWritten = 0;
39 std::uint32_t minId = 0;
40 std::uint32_t maxId = 0;
41 std::uint32_t locale = 0;
42 std::uint32_t copyTableSize = 0;
43 };
44
45 static_assert(sizeof(Wdb2Header) == 48 && std::is_trivially_copyable_v<Wdb2Header>);
46
50 inline constexpr std::size_t Wdb2IndexEntryBytes = 6;
51
59 Result<void> readWdb2(const TableInfo& info, std::span<const std::byte> data, RecordSink& sink, TableState& state);
60
68 Result<FileBuffer> writeWdb2(const TableInfo& info, const RecordSource& source, const TableState& state);
69}
The owning byte buffer file contents are read into.
The decode target: the codecs build the record vector through this, one field at a time.
Definition codec.hpp:110
The encode source: the codecs read the record vector through this.
Definition codec.hpp:135
The type-erased boundary between the templated Table<Record> facade (table.hpp) and the per-format co...
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
FourCC chunk identifiers: compile-time conversion of the four-letter codes to the host integers chunk...
constexpr std::size_t Wdb2IndexEntryBytes
The per-id index block entry stride when maxId != 0: int32 indices[maxId - minId + 1] followed by int...
Definition wdb2.hpp:50
constexpr std::uint32_t Wdb2Magic
The WDB2 magic as memcpy'd off the file front (the bytes "WDB2").
Definition wdb2.hpp:27
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.
Definition wdb2.cpp:68
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,...
Definition wdb2.cpp:14
constexpr std::uint32_t fourcc(const char(&cc)[5], FourCCEndian endian=FourCCEndian::Reversed)
The host integer a scanned chunk id compares equal to for code cc.
Definition fourcc.hpp:33
@ Forward
The characters are stored as written: 'AFID' appears in the file as the bytes "AFID".
Definition fourcc.hpp:22
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition error.hpp:100
The per-table identity a codec needs beyond the record data: the client version (format selection,...
Definition codec.hpp:58
The preserved decode state a table carries between read() and write() so a WDBC/WDB2 write is byte-pe...
Definition codec.hpp:68
The 48-byte WDB2 header (wowdev.wiki/DB2).
Definition wdb2.hpp:30
std::uint32_t maxId
Highest record id; non-zero engages the index block.
Definition wdb2.hpp:40
std::uint32_t minId
Lowest record id; 0 when no index block.
Definition wdb2.hpp:39
std::uint32_t recordSize
Record stride in bytes.
Definition wdb2.hpp:34
std::uint32_t recordCount
Records in the record block.
Definition wdb2.hpp:32
std::uint32_t timestampLastWritten
Unix timestamp, often 0.
Definition wdb2.hpp:38
std::uint32_t fieldCount
Expanded on-disk field slots per record.
Definition wdb2.hpp:33
std::uint32_t locale
Locale mask of the generating client.
Definition wdb2.hpp:41
std::uint32_t tableHash
SStrHash of the uppercased table name.
Definition wdb2.hpp:36
std::uint32_t stringBlockSize
String block bytes after the records.
Definition wdb2.hpp:35
std::uint32_t copyTableSize
Trailing copy-table bytes (id pairs).
Definition wdb2.hpp:42
std::uint32_t build
Client build the file was generated for.
Definition wdb2.hpp:37
std::uint32_t magic
"WDB2".
Definition wdb2.hpp:31