wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
codec_detail.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <cstddef>
10#include <cstdint>
11#include <span>
12#include <string>
13#include <string_view>
14#include <unordered_map>
15#include <vector>
16
18#include <wowlib/db/codec.hpp>
19#include <wowlib/db/schema.hpp>
21
22namespace wowlib::db::detail {
25 std::int64_t readInt(std::span<const std::byte> image, std::size_t& pos, std::size_t bytes, bool isSigned);
26
28 void writeInt(FileBuffer& out, std::int64_t value, std::size_t bytes);
29
33 struct StringPool {
35 std::unordered_map<std::string, std::uint32_t> lookup;
36
38 explicit StringPool(const formats::StringBlock& source);
39
42 std::uint32_t resolve(std::string_view value, const std::vector<std::uint32_t>& journal, std::size_t& cursor);
43 };
44
47 void decodeInlineRecord(std::span<const Column> schema,
48 std::size_t record,
49 std::span<const std::byte> image,
50 RecordSink& sink,
51 TableState& state);
52
55 void encodeInlineRecord(std::span<const Column> schema,
56 const RecordSource& source,
57 std::size_t record,
58 FileBuffer& out,
59 StringPool& pool,
60 const TableState& state,
61 std::size_t& cursor);
62}
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...
std::int64_t readInt(std::span< const std::byte > image, std::size_t &pos, std::size_t bytes, bool isSigned)
Read a little-endian integer of bytes bytes at pos, sign-extended when isSigned, advancing pos.
void decodeInlineRecord(std::span< const Column > schema, std::size_t record, std::span< const std::byte > image, RecordSink &sink, TableState &state)
Decode one fixed-stride record's inline fields into sink and journal its string offsets (record then ...
void encodeInlineRecord(std::span< const Column > schema, const RecordSource &source, std::size_t record, FileBuffer &out, StringPool &pool, const TableState &state, std::size_t &cursor)
Encode one fixed-stride record's inline fields from source, appending to out and resolving strings th...
void writeInt(FileBuffer &out, std::int64_t value, std::size_t bytes)
Append value's low bytes bytes (little-endian) to out.
std::vector< std::byte > FileBuffer
Owning byte buffer for file contents read out of a client storage.
Definition buffer.hpp:16
Schema reflection over generated client-database record structs: the column list, record stride and f...
StringBlock — the decoded representation of a chunk of zero-terminated strings (MOTX,...
The preserved decode state a table carries between read() and write() so a WDBC/WDB2 write is byte-pe...
Definition codec.hpp:68
A writable string block resolving values to byte-perfect offsets: the journaled original offset while...
StringPool(const formats::StringBlock &source)
Copy source (leading with the mandatory zero byte) and index it.
std::unordered_map< std::string, std::uint32_t > lookup
std::uint32_t resolve(std::string_view value, const std::vector< std::uint32_t > &journal, std::size_t &cursor)
The offset to store for value: journal[cursor] when it still holds value, else a deduped/appended off...