mirror of
https://github.com/libretro/RetroArch
synced 2025-03-31 19:21:06 +00:00
(libretro-db) Simplifications/cleanups
This commit is contained in:
parent
66ad277dc1
commit
6b21ad6f53
@ -169,26 +169,6 @@ clean:
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int libretrodb_read_index_header(RFILE *fd, libretrodb_index_t *idx)
|
||||
{
|
||||
uint64_t name_len = 50;
|
||||
return rmsgpack_dom_read_into(fd,
|
||||
"name", idx->name, &name_len,
|
||||
"key_size", &idx->key_size,
|
||||
"next", &idx->next, NULL);
|
||||
}
|
||||
|
||||
static void libretrodb_write_index_header(RFILE *fd, libretrodb_index_t *idx)
|
||||
{
|
||||
rmsgpack_write_map_header(fd, 3);
|
||||
rmsgpack_write_string(fd, "name", STRLEN_CONST("name"));
|
||||
rmsgpack_write_string(fd, idx->name, (uint32_t)strlen(idx->name));
|
||||
rmsgpack_write_string(fd, "key_size", (uint32_t)STRLEN_CONST("key_size"));
|
||||
rmsgpack_write_uint(fd, idx->key_size);
|
||||
rmsgpack_write_string(fd, "next", STRLEN_CONST("next"));
|
||||
rmsgpack_write_uint(fd, idx->next);
|
||||
}
|
||||
|
||||
void libretrodb_close(libretrodb_t *db)
|
||||
{
|
||||
if (db->fd)
|
||||
@ -251,7 +231,12 @@ static int libretrodb_find_index(libretrodb_t *db, const char *index_name,
|
||||
/* TODO: this should use filestream_eof instead */
|
||||
while (offset < eof)
|
||||
{
|
||||
libretrodb_read_index_header(db->fd, idx);
|
||||
uint64_t name_len = 50;
|
||||
/* Read index header */
|
||||
rmsgpack_dom_read_into(db->fd,
|
||||
"name", idx->name, &name_len,
|
||||
"key_size", &idx->key_size,
|
||||
"next", &idx->next, NULL);
|
||||
|
||||
if (strncmp(index_name, idx->name, strlen(idx->name)) == 0)
|
||||
return 0;
|
||||
@ -523,7 +508,15 @@ int libretrodb_create_index(libretrodb_t *db,
|
||||
|
||||
idx.key_size = field_size;
|
||||
idx.next = db->count * (field_size + sizeof(uint64_t));
|
||||
libretrodb_write_index_header(db->fd, &idx);
|
||||
|
||||
/* Write index header */
|
||||
rmsgpack_write_map_header(db->fd, 3);
|
||||
rmsgpack_write_string(db->fd, "name", STRLEN_CONST("name"));
|
||||
rmsgpack_write_string(db->fd, idx.name, (uint32_t)strlen(idx.name));
|
||||
rmsgpack_write_string(db->fd, "key_size", (uint32_t)STRLEN_CONST("key_size"));
|
||||
rmsgpack_write_uint (db->fd, idx.key_size);
|
||||
rmsgpack_write_string(db->fd, "next", STRLEN_CONST("next"));
|
||||
rmsgpack_write_uint (db->fd, idx.next);
|
||||
|
||||
nictx.db = db;
|
||||
nictx.idx = &idx;
|
||||
|
@ -405,8 +405,8 @@ static int rmsgpack_read_int(RFILE *fd, int64_t *out, size_t size)
|
||||
|
||||
static int rmsgpack_read_buff(RFILE *fd, size_t size, char **pbuff, uint64_t *len)
|
||||
{
|
||||
ssize_t read_len;
|
||||
uint64_t tmp_len = 0;
|
||||
ssize_t read_len = 0;
|
||||
|
||||
if (rmsgpack_read_uint(fd, &tmp_len, size) == -1)
|
||||
return -1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user