mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-20 20:41:08 +01:00
cri utf: performance tweaks for some cases
This commit is contained in:
parent
af2f88993a
commit
ce7ffc6d38
@ -1,14 +1,15 @@
|
||||
#include "cri_utf.h"
|
||||
#include "../util/log.h"
|
||||
|
||||
#define UTF_MAX_SCHEMA_SIZE 0x8000 /* arbitrary max */
|
||||
#define COLUMN_BITMASK_FLAG 0xf0
|
||||
#define COLUMN_BITMASK_TYPE 0x0f
|
||||
|
||||
enum columna_flag_t {
|
||||
COLUMN_FLAG_NAME = 0x10,
|
||||
COLUMN_FLAG_DEFAULT = 0x20,
|
||||
COLUMN_FLAG_ROW = 0x40,
|
||||
COLUMN_FLAG_UNDEFINED = 0x80 /* shouldn't exist */
|
||||
COLUMN_FLAG_NAME = 0x10, /* column has name (may be empty) */
|
||||
COLUMN_FLAG_DEFAULT = 0x20, /* data is found relative to schema start (typically constant value for all rows) */
|
||||
COLUMN_FLAG_ROW = 0x40, /* data is found relative to row start */
|
||||
COLUMN_FLAG_UNDEFINED = 0x80 /* shouldn't exist */
|
||||
};
|
||||
|
||||
enum column_type_t {
|
||||
@ -28,34 +29,8 @@ enum column_type_t {
|
||||
COLUMN_TYPE_UNDEFINED = -1
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int found;
|
||||
enum column_type_t type;
|
||||
union {
|
||||
int8_t value_s8;
|
||||
uint8_t value_u8;
|
||||
int16_t value_s16;
|
||||
uint16_t value_u16;
|
||||
int32_t value_s32;
|
||||
uint32_t value_u32;
|
||||
int64_t value_s64;
|
||||
uint64_t value_u64;
|
||||
float value_float;
|
||||
double value_double;
|
||||
struct utf_data_t {
|
||||
uint32_t offset;
|
||||
uint32_t size;
|
||||
} value_data;
|
||||
//struct utf_u128_t {
|
||||
// uint64_t hi;
|
||||
// uint64_t lo;
|
||||
//} value_u128;
|
||||
const char *value_string;
|
||||
} value;
|
||||
} utf_result_t;
|
||||
|
||||
struct utf_context {
|
||||
STREAMFILE *sf;
|
||||
STREAMFILE* sf;
|
||||
uint32_t table_offset;
|
||||
|
||||
/* header */
|
||||
@ -68,25 +43,31 @@ struct utf_context {
|
||||
uint16_t columns;
|
||||
uint16_t row_width;
|
||||
uint32_t rows;
|
||||
|
||||
uint8_t* schema_buf;
|
||||
struct utf_column_t {
|
||||
uint8_t flag;
|
||||
uint8_t type;
|
||||
const char *name;
|
||||
const char* name;
|
||||
uint32_t offset;
|
||||
} *schema;
|
||||
|
||||
/* derived */
|
||||
uint32_t schema_offset;
|
||||
uint32_t schema_size;
|
||||
uint32_t rows_size;
|
||||
uint32_t data_size;
|
||||
uint32_t strings_size;
|
||||
char *string_table;
|
||||
const char *table_name;
|
||||
char* string_table;
|
||||
const char* table_name;
|
||||
};
|
||||
|
||||
|
||||
/* @UTF table context creation */
|
||||
utf_context* utf_open(STREAMFILE* sf, uint32_t table_offset, int* p_rows, const char** p_row_name) {
|
||||
utf_context* utf = NULL;
|
||||
|
||||
uint8_t buf[0x20];
|
||||
int bytes;
|
||||
|
||||
utf = calloc(1, sizeof(utf_context));
|
||||
if (!utf) goto fail;
|
||||
@ -94,27 +75,33 @@ utf_context* utf_open(STREAMFILE* sf, uint32_t table_offset, int* p_rows, const
|
||||
utf->sf = sf;
|
||||
utf->table_offset = table_offset;
|
||||
|
||||
/* check header */
|
||||
if (read_u32be(table_offset + 0x00, sf) != 0x40555446) /* "@UTF" */
|
||||
goto fail;
|
||||
bytes = read_streamfile(buf, table_offset, sizeof(buf), sf);
|
||||
if (bytes != sizeof(buf)) goto fail;
|
||||
|
||||
/* load table header */
|
||||
utf->table_size = read_u32be(table_offset + 0x04, sf) + 0x08;
|
||||
utf->version = read_u16be(table_offset + 0x08, sf);
|
||||
utf->rows_offset = read_u16be(table_offset + 0x0a, sf) + 0x08;
|
||||
utf->strings_offset = read_u32be(table_offset + 0x0c, sf) + 0x08;
|
||||
utf->data_offset = read_u32be(table_offset + 0x10, sf) + 0x08;
|
||||
utf->name_offset = read_u32be(table_offset + 0x14, sf); /* within string table */
|
||||
utf->columns = read_u16be(table_offset + 0x18, sf);
|
||||
utf->row_width = read_u16be(table_offset + 0x1a, sf);
|
||||
utf->rows = read_u32be(table_offset + 0x1c, sf);
|
||||
if (get_u32be(buf + 0x00) != get_id32be("@UTF"))
|
||||
goto fail;
|
||||
utf->table_size = get_u32be(buf + 0x04) + 0x08;
|
||||
utf->version = get_u16be(buf + 0x08);
|
||||
utf->rows_offset = get_u16be(buf + 0x0a) + 0x08;
|
||||
utf->strings_offset = get_u32be(buf + 0x0c) + 0x08;
|
||||
utf->data_offset = get_u32be(buf + 0x10) + 0x08;
|
||||
utf->name_offset = get_u32be(buf + 0x14); /* within string table */
|
||||
utf->columns = get_u16be(buf + 0x18);
|
||||
utf->row_width = get_u16be(buf + 0x1a);
|
||||
utf->rows = get_u32be(buf + 0x1c);
|
||||
|
||||
utf->schema_offset = 0x20;
|
||||
utf->schema_size = utf->rows_offset - utf->schema_offset;
|
||||
utf->rows_size = utf->strings_offset - utf->rows_offset;
|
||||
utf->strings_size = utf->data_offset - utf->strings_offset;
|
||||
utf->data_size = utf->table_size - utf->data_offset;
|
||||
|
||||
utf->schema_offset = 0x20;
|
||||
utf->strings_size = utf->data_offset - utf->strings_offset;
|
||||
|
||||
/* 00: early (32b rows_offset?), 01: +2017 (no apparent differences) */
|
||||
if (utf->version != 0x00 && utf->version != 0x01) {
|
||||
vgm_logi("@UTF: unknown version\n");
|
||||
goto fail;
|
||||
}
|
||||
if (utf->table_offset + utf->table_size > get_streamfile_size(sf))
|
||||
goto fail;
|
||||
@ -125,39 +112,48 @@ utf_context* utf_open(STREAMFILE* sf, uint32_t table_offset, int* p_rows, const
|
||||
/* no rows is possible for empty tables (have schema and columns names but no data) [PES 2013 (PC)] */
|
||||
if (utf->columns <= 0 /*|| utf->rows <= 0 || utf->rows_width <= 0*/)
|
||||
goto fail;
|
||||
if (utf->schema_size >= UTF_MAX_SCHEMA_SIZE)
|
||||
goto fail;
|
||||
|
||||
|
||||
/* load string table */
|
||||
/* load sections linearly (to optimize stream) */
|
||||
{
|
||||
size_t read;
|
||||
/* schema section: small so keep it around (useful to avoid re-reads on column values) */
|
||||
utf->schema_buf = malloc(utf->schema_size);
|
||||
if (!utf->schema_buf) goto fail;
|
||||
|
||||
bytes = read_streamfile(utf->schema_buf, utf->table_offset + utf->schema_offset, utf->schema_size, sf);
|
||||
if (bytes != utf->schema_size) goto fail;
|
||||
|
||||
/* row section: skip, mid to big (0x10000~0x50000) so not preloaded for now */
|
||||
|
||||
/* string section: low to mid size but used to return c-strings */
|
||||
utf->string_table = calloc(utf->strings_size + 1, sizeof(char));
|
||||
if (!utf->string_table) goto fail;
|
||||
|
||||
utf->table_name = utf->string_table + utf->name_offset;
|
||||
bytes = read_streamfile((unsigned char*)utf->string_table, utf->table_offset + utf->strings_offset, utf->strings_size, sf);
|
||||
if (bytes != utf->strings_size) goto fail;
|
||||
|
||||
read = read_streamfile((unsigned char*)utf->string_table, utf->table_offset + utf->strings_offset, utf->strings_size, sf);
|
||||
if (utf->strings_size != read) goto fail;
|
||||
/* data section: skip (may be big with memory AWB) */
|
||||
}
|
||||
|
||||
|
||||
/* load column schema */
|
||||
{
|
||||
int i;
|
||||
uint32_t value_size, column_offset = 0;
|
||||
uint32_t schema_offset = utf->table_offset + utf->schema_offset;
|
||||
int schema_pos = 0;
|
||||
|
||||
utf->table_name = utf->string_table + utf->name_offset;
|
||||
|
||||
utf->schema = malloc(sizeof(struct utf_column_t) * utf->columns);
|
||||
utf->schema = malloc(utf->columns * sizeof(struct utf_column_t));
|
||||
if (!utf->schema) goto fail;
|
||||
|
||||
for (i = 0; i < utf->columns; i++) {
|
||||
uint8_t info = read_u8(schema_offset + 0x00, sf);
|
||||
uint32_t name_offset = read_u32be(schema_offset + 0x01, sf);
|
||||
uint8_t info = get_u8(utf->schema_buf + schema_pos + 0x00);
|
||||
uint32_t name_offset = get_u32be(utf->schema_buf + schema_pos + 0x01);
|
||||
|
||||
if (name_offset > utf->strings_size)
|
||||
goto fail;
|
||||
schema_offset += 0x01 + 0x04;
|
||||
|
||||
schema_pos += 0x01 + 0x04;
|
||||
|
||||
utf->schema[i].flag = info & COLUMN_BITMASK_FLAG;
|
||||
utf->schema[i].type = info & COLUMN_BITMASK_TYPE;
|
||||
@ -165,7 +161,7 @@ utf_context* utf_open(STREAMFILE* sf, uint32_t table_offset, int* p_rows, const
|
||||
utf->schema[i].offset = 0;
|
||||
|
||||
/* known flags are name+default or name+row, but name+default+row is mentioned in VGMToolbox
|
||||
* even though isn't possible in CRI's craft utils, and no name is apparently possible */
|
||||
* even though isn't possible in CRI's craft utils (meaningless), and no name is apparently possible */
|
||||
if ( (utf->schema[i].flag == 0) ||
|
||||
!(utf->schema[i].flag & COLUMN_FLAG_NAME) ||
|
||||
((utf->schema[i].flag & COLUMN_FLAG_DEFAULT) && (utf->schema[i].flag & COLUMN_FLAG_ROW)) ||
|
||||
@ -207,20 +203,25 @@ utf_context* utf_open(STREAMFILE* sf, uint32_t table_offset, int* p_rows, const
|
||||
}
|
||||
|
||||
if (utf->schema[i].flag & COLUMN_FLAG_DEFAULT) {
|
||||
/* data is found relative to schema start */
|
||||
utf->schema[i].offset = schema_offset - (utf->table_offset + utf->schema_offset);
|
||||
schema_offset += value_size;
|
||||
utf->schema[i].offset = schema_pos;
|
||||
schema_pos += value_size;
|
||||
}
|
||||
|
||||
if (utf->schema[i].flag & COLUMN_FLAG_ROW) {
|
||||
/* data is found relative to row start */
|
||||
utf->schema[i].offset = column_offset;
|
||||
column_offset += value_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* next section is row and variable length data (pointed above) then end of table */
|
||||
#if 0
|
||||
VGM_LOG("- %s\n", utf->table_name);
|
||||
VGM_LOG("utf_o=%08x (%x)\n", utf->table_offset, utf->table_size);
|
||||
VGM_LOG(" sch_o=%08x (%x), c=%i\n", utf->table_offset + utf->schema_offset, utf->schema_size, utf->columns);
|
||||
VGM_LOG(" row_o=%08x (%x), r=%i\n", utf->table_offset + utf->rows_offset, utf->rows_size, utf->rows);
|
||||
VGM_LOG(" str_o=%08x (%x)\n", utf->table_offset + utf->strings_offset, utf->strings_size);
|
||||
VGM_LOG(" dat_o=%08x (%x))\n", utf->table_offset + utf->data_offset, utf->data_size);
|
||||
#endif
|
||||
|
||||
/* write info */
|
||||
if (p_rows) *p_rows = utf->rows;
|
||||
@ -237,107 +238,139 @@ void utf_close(utf_context* utf) {
|
||||
if (!utf) return;
|
||||
|
||||
free(utf->string_table);
|
||||
free(utf->schema_buf);
|
||||
free(utf->schema);
|
||||
free(utf);
|
||||
}
|
||||
|
||||
|
||||
static int utf_query(utf_context* utf, int row, const char* column, utf_result_t* result) {
|
||||
int utf_get_column(utf_context* utf, const char* column) {
|
||||
int i;
|
||||
|
||||
|
||||
result->found = 0;
|
||||
|
||||
if (row >= utf->rows || row < 0)
|
||||
goto fail;
|
||||
|
||||
/* find target column */
|
||||
for (i = 0; i < utf->columns; i++) {
|
||||
struct utf_column_t *col = &utf->schema[i];
|
||||
uint32_t data_offset;
|
||||
struct utf_column_t* col = &utf->schema[i];
|
||||
|
||||
if (col->name == NULL || strcmp(col->name, column) != 0)
|
||||
continue;
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
enum column_type_t type;
|
||||
union {
|
||||
int8_t s8;
|
||||
uint8_t u8;
|
||||
int16_t s16;
|
||||
uint16_t u16;
|
||||
int32_t s32;
|
||||
uint32_t u32;
|
||||
int64_t s64;
|
||||
uint64_t u64;
|
||||
float flt;
|
||||
double dbl;
|
||||
struct utf_data_t {
|
||||
uint32_t offset;
|
||||
uint32_t size;
|
||||
} data;
|
||||
#if 0
|
||||
struct utf_u128_t {
|
||||
uint64_t hi;
|
||||
uint64_t lo;
|
||||
} value_u128;
|
||||
#endif
|
||||
const char* str;
|
||||
} value;
|
||||
} utf_result_t;
|
||||
|
||||
static int utf_query(utf_context* utf, int row, int column, utf_result_t* result) {
|
||||
|
||||
if (row >= utf->rows || row < 0)
|
||||
goto fail;
|
||||
if (column >= utf->columns || column < 0)
|
||||
goto fail;
|
||||
|
||||
/* get target column */
|
||||
{
|
||||
struct utf_column_t* col = &utf->schema[column];
|
||||
uint32_t data_offset = 0;
|
||||
uint8_t* buf = NULL;
|
||||
|
||||
result->found = 1;
|
||||
result->type = col->type;
|
||||
|
||||
if (col->flag & COLUMN_FLAG_DEFAULT) {
|
||||
data_offset = utf->table_offset + utf->schema_offset + col->offset;
|
||||
if (utf->schema_buf)
|
||||
buf = utf->schema_buf + col->offset;
|
||||
else
|
||||
data_offset = utf->table_offset + utf->schema_offset + col->offset;
|
||||
}
|
||||
else if (col->flag & COLUMN_FLAG_ROW) {
|
||||
data_offset = utf->table_offset + utf->rows_offset + row * utf->row_width + col->offset;
|
||||
}
|
||||
else {
|
||||
data_offset = 0;
|
||||
/* shouldn't happen */
|
||||
memset(&result->value, 0, sizeof(result->value));
|
||||
return 1; /* ??? */
|
||||
}
|
||||
|
||||
/* ignore zero value */
|
||||
if (data_offset == 0) {
|
||||
memset(&result->value, 0, sizeof(result->value)); /* just in case... */
|
||||
break;
|
||||
}
|
||||
|
||||
/* read row/constant value */
|
||||
/* read row/constant value (use buf if available) */
|
||||
switch (col->type) {
|
||||
case COLUMN_TYPE_UINT8:
|
||||
result->value.value_u8 = read_u8(data_offset, utf->sf);
|
||||
result->value.u8 = buf ? get_u8(buf) : read_u8(data_offset, utf->sf);
|
||||
break;
|
||||
case COLUMN_TYPE_SINT8:
|
||||
result->value.value_s8 = read_s8(data_offset, utf->sf);
|
||||
result->value.s8 = buf ? get_s8(buf) : read_s8(data_offset, utf->sf);
|
||||
break;
|
||||
case COLUMN_TYPE_UINT16:
|
||||
result->value.value_u16 = read_u16be(data_offset, utf->sf);
|
||||
result->value.u16 = buf ? get_u16be(buf) : read_u16be(data_offset, utf->sf);
|
||||
break;
|
||||
case COLUMN_TYPE_SINT16:
|
||||
result->value.value_s16 = read_s16be(data_offset, utf->sf);
|
||||
result->value.s16 = buf ? get_s16be(buf) : read_s16be(data_offset, utf->sf);
|
||||
break;
|
||||
case COLUMN_TYPE_UINT32:
|
||||
result->value.value_u32 = read_u32be(data_offset, utf->sf);
|
||||
result->value.u32 = buf ? get_u32be(buf) : read_u32be(data_offset, utf->sf);
|
||||
break;
|
||||
case COLUMN_TYPE_SINT32:
|
||||
result->value.value_s32 = read_s32be(data_offset, utf->sf);
|
||||
result->value.s32 = buf ? get_s32be(buf) : read_s32be(data_offset, utf->sf);
|
||||
break;
|
||||
case COLUMN_TYPE_UINT64:
|
||||
result->value.value_u64 = read_u64be(data_offset, utf->sf);
|
||||
result->value.u64 = buf ? get_u64be(buf) : read_u64be(data_offset, utf->sf);
|
||||
break;
|
||||
case COLUMN_TYPE_SINT64:
|
||||
result->value.value_s64 = read_s64be(data_offset, utf->sf);
|
||||
result->value.s64 = buf ? get_s64be(buf) : read_s64be(data_offset, utf->sf);
|
||||
break;
|
||||
case COLUMN_TYPE_FLOAT: {
|
||||
result->value.value_float = read_f32be(data_offset, utf->sf);
|
||||
case COLUMN_TYPE_FLOAT:
|
||||
result->value.flt = buf ? get_f32be(buf) : read_f32be(data_offset, utf->sf);
|
||||
break;
|
||||
}
|
||||
#if 0
|
||||
case COLUMN_TYPE_DOUBLE: {
|
||||
result->value.value_double = read_d64be(data_offset, utf->sf);
|
||||
case COLUMN_TYPE_DOUBLE:
|
||||
result->value.dbl = buf ? get_d64be(buf) : read_d64be(data_offset, utf->sf);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case COLUMN_TYPE_STRING: {
|
||||
uint32_t name_offset = read_u32be(data_offset, utf->sf);
|
||||
uint32_t name_offset = buf ? get_u32be(buf) : read_u32be(data_offset, utf->sf);
|
||||
if (name_offset > utf->strings_size)
|
||||
goto fail;
|
||||
result->value.value_string = utf->string_table + name_offset;
|
||||
result->value.str = utf->string_table + name_offset;
|
||||
break;
|
||||
}
|
||||
|
||||
case COLUMN_TYPE_VLDATA:
|
||||
result->value.value_data.offset = read_u32be(data_offset + 0x00, utf->sf);
|
||||
result->value.value_data.size = read_u32be(data_offset + 0x04, utf->sf);
|
||||
result->value.data.offset = buf ? get_u32be(buf + 0x0) : read_u32be(data_offset + 0x00, utf->sf);
|
||||
result->value.data.size = buf ? get_u32be(buf + 0x4) : read_u32be(data_offset + 0x04, utf->sf);
|
||||
break;
|
||||
#if 0
|
||||
case COLUMN_TYPE_UINT128: {
|
||||
result->value.value_u128.hi = read_u64be(data_offset + 0x00, utf->sf);
|
||||
result->value.value_u128.lo = read_u64be(data_offset + 0x08, utf->sf);
|
||||
case COLUMN_TYPE_UINT128:
|
||||
result->value.value_u128.hi = buf ? get_u32be(buf + 0x0) : read_u64be(data_offset + 0x00, utf->sf);
|
||||
result->value.value_u128.lo = buf ? get_u32be(buf + 0x4) : read_u64be(data_offset + 0x08, utf->sf);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
||||
break; /* column found and read */
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -345,24 +378,24 @@ fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int utf_query_value(utf_context* utf, int row, const char* column, void* value, enum column_type_t type) {
|
||||
static int utf_query_value(utf_context* utf, int row, int column, void* value, enum column_type_t type) {
|
||||
utf_result_t result = {0};
|
||||
int valid;
|
||||
|
||||
valid = utf_query(utf, row, column, &result);
|
||||
if (!valid || !result.found || result.type != type)
|
||||
if (!valid || result.type != type)
|
||||
return 0;
|
||||
|
||||
switch(result.type) {
|
||||
case COLUMN_TYPE_UINT8: (*(uint8_t*)value) = result.value.value_u8; break;
|
||||
case COLUMN_TYPE_SINT8: (*(int8_t*)value) = result.value.value_s8; break;
|
||||
case COLUMN_TYPE_UINT16: (*(uint16_t*)value) = result.value.value_u16; break;
|
||||
case COLUMN_TYPE_SINT16: (*(int16_t*)value) = result.value.value_s16; break;
|
||||
case COLUMN_TYPE_UINT32: (*(uint32_t*)value) = result.value.value_u32; break;
|
||||
case COLUMN_TYPE_SINT32: (*(int32_t*)value) = result.value.value_s32; break;
|
||||
case COLUMN_TYPE_UINT64: (*(uint64_t*)value) = result.value.value_u64; break;
|
||||
case COLUMN_TYPE_SINT64: (*(int64_t*)value) = result.value.value_s64; break;
|
||||
case COLUMN_TYPE_STRING: (*(const char**)value) = result.value.value_string; break;
|
||||
case COLUMN_TYPE_UINT8: (*(uint8_t*)value) = result.value.u8; break;
|
||||
case COLUMN_TYPE_SINT8: (*(int8_t*)value) = result.value.s8; break;
|
||||
case COLUMN_TYPE_UINT16: (*(uint16_t*)value) = result.value.u16; break;
|
||||
case COLUMN_TYPE_SINT16: (*(int16_t*)value) = result.value.s16; break;
|
||||
case COLUMN_TYPE_UINT32: (*(uint32_t*)value) = result.value.u32; break;
|
||||
case COLUMN_TYPE_SINT32: (*(int32_t*)value) = result.value.s32; break;
|
||||
case COLUMN_TYPE_UINT64: (*(uint64_t*)value) = result.value.u64; break;
|
||||
case COLUMN_TYPE_SINT64: (*(int64_t*)value) = result.value.s64; break;
|
||||
case COLUMN_TYPE_STRING: (*(const char**)value) = result.value.str; break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -370,43 +403,76 @@ static int utf_query_value(utf_context* utf, int row, const char* column, void*
|
||||
return 1;
|
||||
}
|
||||
|
||||
int utf_query_s8(utf_context* utf, int row, const char* column, int8_t* value) {
|
||||
int utf_query_col_s8(utf_context* utf, int row, int column, int8_t* value) {
|
||||
return utf_query_value(utf, row, column, (void*)value, COLUMN_TYPE_SINT8);
|
||||
}
|
||||
int utf_query_u8(utf_context* utf, int row, const char* column, uint8_t* value) {
|
||||
int utf_query_col_u8(utf_context* utf, int row, int column, uint8_t* value) {
|
||||
return utf_query_value(utf, row, column, (void*)value, COLUMN_TYPE_UINT8);
|
||||
}
|
||||
int utf_query_s16(utf_context* utf, int row, const char* column, int16_t* value) {
|
||||
int utf_query_col_s16(utf_context* utf, int row, int column, int16_t* value) {
|
||||
return utf_query_value(utf, row, column, (void*)value, COLUMN_TYPE_SINT16);
|
||||
}
|
||||
int utf_query_u16(utf_context* utf, int row, const char* column, uint16_t* value) {
|
||||
int utf_query_col_u16(utf_context* utf, int row, int column, uint16_t* value) {
|
||||
return utf_query_value(utf, row, column, (void*)value, COLUMN_TYPE_UINT16);
|
||||
}
|
||||
int utf_query_s32(utf_context* utf, int row, const char* column, int32_t* value) {
|
||||
int utf_query_col_s32(utf_context* utf, int row, int column, int32_t* value) {
|
||||
return utf_query_value(utf, row, column, (void*)value, COLUMN_TYPE_SINT32);
|
||||
}
|
||||
int utf_query_u32(utf_context* utf, int row, const char* column, uint32_t* value) {
|
||||
int utf_query_col_u32(utf_context* utf, int row, int column, uint32_t* value) {
|
||||
return utf_query_value(utf, row, column, (void*)value, COLUMN_TYPE_UINT32);
|
||||
}
|
||||
int utf_query_s64(utf_context* utf, int row, const char* column, int64_t* value) {
|
||||
int utf_query_col_s64(utf_context* utf, int row, int column, int64_t* value) {
|
||||
return utf_query_value(utf, row, column, (void*)value, COLUMN_TYPE_SINT64);
|
||||
}
|
||||
int utf_query_u64(utf_context* utf, int row, const char* column, uint64_t* value) {
|
||||
int utf_query_col_u64(utf_context* utf, int row, int column, uint64_t* value) {
|
||||
return utf_query_value(utf, row, column, (void*)value, COLUMN_TYPE_UINT64);
|
||||
}
|
||||
int utf_query_string(utf_context* utf, int row, const char* column, const char** value) {
|
||||
int utf_query_col_string(utf_context* utf, int row, int column, const char** value) {
|
||||
return utf_query_value(utf, row, column, (void*)value, COLUMN_TYPE_STRING);
|
||||
}
|
||||
|
||||
int utf_query_data(utf_context* utf, int row, const char* column, uint32_t* p_offset, uint32_t* p_size) {
|
||||
int utf_query_col_data(utf_context* utf, int row, int column, uint32_t* p_offset, uint32_t* p_size) {
|
||||
utf_result_t result = {0};
|
||||
int valid;
|
||||
|
||||
valid = utf_query(utf, row, column, &result);
|
||||
if (!valid || !result.found || result.type != COLUMN_TYPE_VLDATA)
|
||||
if (!valid || result.type != COLUMN_TYPE_VLDATA)
|
||||
return 0;
|
||||
|
||||
if (p_offset) *p_offset = utf->table_offset + utf->data_offset + result.value.value_data.offset;
|
||||
if (p_size) *p_size = result.value.value_data.size;
|
||||
if (p_offset) *p_offset = utf->table_offset + utf->data_offset + result.value.data.offset;
|
||||
if (p_size) *p_size = result.value.data.size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int utf_query_s8(utf_context* utf, int row, const char* column_name, int8_t* value) {
|
||||
return utf_query_value(utf, row, utf_get_column(utf, column_name), (void*)value, COLUMN_TYPE_SINT8);
|
||||
}
|
||||
int utf_query_u8(utf_context* utf, int row, const char* column_name, uint8_t* value) {
|
||||
return utf_query_value(utf, row, utf_get_column(utf, column_name), (void*)value, COLUMN_TYPE_UINT8);
|
||||
}
|
||||
int utf_query_s16(utf_context* utf, int row, const char* column_name, int16_t* value) {
|
||||
return utf_query_value(utf, row, utf_get_column(utf, column_name), (void*)value, COLUMN_TYPE_SINT16);
|
||||
}
|
||||
int utf_query_u16(utf_context* utf, int row, const char* column_name, uint16_t* value) {
|
||||
return utf_query_value(utf, row, utf_get_column(utf, column_name), (void*)value, COLUMN_TYPE_UINT16);
|
||||
}
|
||||
int utf_query_s32(utf_context* utf, int row, const char* column_name, int32_t* value) {
|
||||
return utf_query_value(utf, row, utf_get_column(utf, column_name), (void*)value, COLUMN_TYPE_SINT32);
|
||||
}
|
||||
int utf_query_u32(utf_context* utf, int row, const char* column_name, uint32_t* value) {
|
||||
return utf_query_value(utf, row, utf_get_column(utf, column_name), (void*)value, COLUMN_TYPE_UINT32);
|
||||
}
|
||||
int utf_query_s64(utf_context* utf, int row, const char* column_name, int64_t* value) {
|
||||
return utf_query_value(utf, row, utf_get_column(utf, column_name), (void*)value, COLUMN_TYPE_SINT64);
|
||||
}
|
||||
int utf_query_u64(utf_context* utf, int row, const char* column_name, uint64_t* value) {
|
||||
return utf_query_value(utf, row, utf_get_column(utf, column_name), (void*)value, COLUMN_TYPE_UINT64);
|
||||
}
|
||||
int utf_query_string(utf_context* utf, int row, const char* column_name, const char** value) {
|
||||
return utf_query_value(utf, row, utf_get_column(utf, column_name), (void*)value, COLUMN_TYPE_STRING);
|
||||
}
|
||||
|
||||
int utf_query_data(utf_context* utf, int row, const char* column_name, uint32_t* p_offset, uint32_t* p_size) {
|
||||
return utf_query_col_data(utf, row, utf_get_column(utf, column_name), p_offset, p_size);
|
||||
}
|
||||
|
@ -23,16 +23,30 @@ typedef struct utf_context utf_context;
|
||||
/* open a CRI UTF table at offset, returning table name and rows. Passed streamfile is used internally for next calls */
|
||||
utf_context* utf_open(STREAMFILE* sf, uint32_t table_offset, int* p_rows, const char** p_row_name);
|
||||
void utf_close(utf_context* utf);
|
||||
/* query calls */
|
||||
int utf_query_s8(utf_context* utf, int row, const char* column, int8_t* value);
|
||||
int utf_query_u8(utf_context* utf, int row, const char* column, uint8_t* value);
|
||||
int utf_query_s16(utf_context* utf, int row, const char* column, int16_t* value);
|
||||
int utf_query_u16(utf_context* utf, int row, const char* column, uint16_t* value);
|
||||
int utf_query_s32(utf_context* utf, int row, const char* column, int32_t* value);
|
||||
int utf_query_u32(utf_context* utf, int row, const char* column, uint32_t* value);
|
||||
int utf_query_s64(utf_context* utf, int row, const char* column, int64_t* value);
|
||||
int utf_query_u64(utf_context* utf, int row, const char* column, uint64_t* value);
|
||||
int utf_query_string(utf_context* utf, int row, const char* column, const char** value);
|
||||
int utf_query_data(utf_context* utf, int row, const char* column, uint32_t* offset, uint32_t* size);
|
||||
|
||||
int utf_get_column(utf_context* utf, const char* column);
|
||||
|
||||
/* query calls (passing column index is faster, when you have to read lots of rows) */
|
||||
int utf_query_col_s8(utf_context* utf, int row, int column, int8_t* value);
|
||||
int utf_query_col_u8(utf_context* utf, int row, int column, uint8_t* value);
|
||||
int utf_query_col_s16(utf_context* utf, int row, int column, int16_t* value);
|
||||
int utf_query_col_u16(utf_context* utf, int row, int column, uint16_t* value);
|
||||
int utf_query_col_s32(utf_context* utf, int row, int column, int32_t* value);
|
||||
int utf_query_col_u32(utf_context* utf, int row, int column, uint32_t* value);
|
||||
int utf_query_col_s64(utf_context* utf, int row, int column, int64_t* value);
|
||||
int utf_query_col_u64(utf_context* utf, int row, int column, uint64_t* value);
|
||||
int utf_query_col_string(utf_context* utf, int row, int column, const char** value);
|
||||
int utf_query_col_data(utf_context* utf, int row, int column, uint32_t* offset, uint32_t* size);
|
||||
|
||||
int utf_query_s8(utf_context* utf, int row, const char* column_name, int8_t* value);
|
||||
int utf_query_u8(utf_context* utf, int row, const char* column_name, uint8_t* value);
|
||||
int utf_query_s16(utf_context* utf, int row, const char* column_name, int16_t* value);
|
||||
int utf_query_u16(utf_context* utf, int row, const char* column_name, uint16_t* value);
|
||||
int utf_query_s32(utf_context* utf, int row, const char* column_name, int32_t* value);
|
||||
int utf_query_u32(utf_context* utf, int row, const char* column_name, uint32_t* value);
|
||||
int utf_query_s64(utf_context* utf, int row, const char* column_name, int64_t* value);
|
||||
int utf_query_u64(utf_context* utf, int row, const char* column_name, uint64_t* value);
|
||||
int utf_query_string(utf_context* utf, int row, const char* column_name, const char** value);
|
||||
int utf_query_data(utf_context* utf, int row, const char* column_name, uint32_t* offset, uint32_t* size);
|
||||
|
||||
#endif /* _CRI_UTF_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user