Class BinaryReader
Defined in File BinaryReader.h
Inheritance Relationships
Derived Type
protected KxdbParser
(Class KxdbParser)
Class Documentation
-
class BinaryReader
A class for reading and parsing data from a binary buffer with offset tracking and structural awareness.
Subclassed by KxdbParser
Public Functions
-
uint64_t Uint(int size)
Reads an unsigned integer of a specified size.
- Parameters:
size – The size of the unsigned integer to read (1, 2, 4, or 8 bytes).
- Returns:
The unsigned integer value read from the buffer.
-
uint64_t EndOffset()
Returns the end offset of the current structure or the entire data if seeking is in progress.
- Returns:
The end offset.
-
uint64_t RemainingBytes()
Returns the number of remaining bytes in the current structure or until the end of the data if seeking is in progress.
- Returns:
The number of remaining bytes.
-
void SizeCheck(uint64_t len)
Checks if there are enough remaining bytes to read a specified length.
- Parameters:
len – The length to check against the remaining bytes.
- Throws:
ExpKitError – if there are not enough remaining bytes.
-
void Skip(uint64_t len)
Skip len amount of bytes.
- Parameters:
len – The number of bytes to skip.
- Throws:
ExpKitError – if there are not enough remaining bytes.
-
void SeekTo(uint64_t offset)
Seek to offset.
- Parameters:
offset – The offset within the file to seek.
- Throws:
ExpKitError – if the offset is out-of-bounds.
-
uint8_t *Read(uint16_t len)
Reads a block of raw bytes from the buffer.
- Parameters:
len – The number of bytes to read.
- Throws:
ExpKitError – if reading beyond the buffer limits.
- Returns:
A pointer to the read bytes within the internal buffer.
-
uint8_t ReadU8()
Reads a single byte (uint8_t) from the buffer.
- Returns:
The byte value.
-
uint16_t ReadU16()
Reads a 16-bit unsigned integer (uint16_t) from the buffer.
- Returns:
The 16-bit unsigned integer value.
-
uint32_t ReadU32()
Reads a 32-bit unsigned integer (uint32_t) from the buffer.
- Returns:
The 32-bit unsigned integer value.
-
uint64_t ReadU64()
Reads a 64-bit unsigned integer (uint64_t) from the buffer.
- Returns:
The 64-bit unsigned integer value.
-
int64_t ReadInt(bool signed_ = true)
Reads a variable-length integer from the buffer.
- Parameters:
signed_ – Whether the integer is signed. Defaults to true.
- Returns:
The integer value.
-
uint64_t ReadUInt()
Reads a variable-length unsigned integer from the buffer.
- Returns:
The unsigned integer value.
-
uint64_t SeekableListCount()
Reads the count of a seekable list and skips the seek list data.
- Returns:
The number of items in the seekable list.
-
std::vector<uint64_t> IndexableIntList()
-
std::vector<uint64_t> SeekableListSizes()
-
bool IsSeekingInProgress()
Checks if a seek operation is currently in progress.
- Returns:
True if seeking is in progress, false otherwise.
-
void SeekToItem(uint64_t seeklist_offset, uint64_t item_idx)
Seeks to a specific item within a seekable list.
- Parameters:
seeklist_offset – The offset of the seekable list.
item_idx – The index of the item to seek to.
- Throws:
ExpKitError – if seeking is already in progress or the item index is out of bounds.
-
void EndSeek()
Ends a seek operation and returns to the original offset.
- Throws:
ExpKitError – if no seek operation is in progress.
-
template<typename ...Args>
inline void DebugLog(const char *format, const Args&... args) Logs a debug message with the current offset.
- Template Parameters:
Args – The types of the arguments.
- Parameters:
format – The format string for the log message.
-
bool BeginStruct(uint64_t struct_size)
Limits the reader to struct_size.
- Parameters:
struct_size – The structure size in bytes.
- Returns:
struct_size is not zero.
-
void EndStruct()
Ends parsing a structure. Jumps the offset to the end of the current structure.
- Throws:
ExpKitError – if EndStruct() is called without a corresponding BeginStruct().
-
const char *ZStr(uint16_t len)
Reads a null-terminated string with a specified maximum length.
- Parameters:
len – The maximum length of the string (excluding the null terminator).
- Returns:
A pointer to the null-terminated string within the internal buffer.
-
const char *ZStr()
Reads a null-terminated string where the length is encoded as a variable-length unsigned integer before the string data.
- Returns:
A pointer to the null-terminated string within the internal buffer.
-
BinaryReader(const uint8_t *buffer, size_t size)
Constructs a BinaryReader from a raw buffer.
- Parameters:
buffer – A pointer to the raw data buffer.
size – The size of the buffer.
-
BinaryReader(const std::vector<uint8_t> data)
Constructs a BinaryReader from a vector of bytes.
- Parameters:
data – The vector of bytes.
Public Static Functions
-
static BinaryReader FromFile(const char *filename)
Creates a BinaryReader by reading data from a file.
- Parameters:
filename – The path to the file.
- Returns:
A BinaryReader instance with the file data.
-
uint64_t Uint(int size)