|
Kohi Game Engine
|
This files contains an implementation of a binary string table. More...
#include "defines.h"Go to the source code of this file.
Data Structures | |
| struct | binary_string_table_entry |
| struct | binary_string_table_header |
| struct | binary_string_table |
Typedefs | |
| typedef struct binary_string_table_entry | binary_string_table_entry |
| typedef struct binary_string_table_header | binary_string_table_header |
| typedef struct binary_string_table | binary_string_table |
Functions | |
| KAPI binary_string_table | binary_string_table_create (void) |
| KAPI binary_string_table | binary_string_table_from_block (void *block) |
| KAPI void | binary_string_table_destroy (binary_string_table *table) |
| Destroys the provided binary string table. More... | |
| KAPI u32 | binary_string_table_add (binary_string_table *table, const char *string) |
| Adds the given string to the provided table. String MUST be null-terminated. More... | |
| KAPI const char * | binary_string_table_get (const binary_string_table *table, u32 index) |
| Returns a null-terminated copy of the string from the table. Dynamically allocated and must be freed by the caller. More... | |
| KAPI u32 | binary_string_table_length_get (const binary_string_table *table, u32 index) |
| Returns the length of the string, NOT accounting for null terminator. More... | |
| KAPI void | binary_string_table_get_buffered (const binary_string_table *table, u32 index, char *buffer) |
| Copies string into already-existing buffer. Use binary_string_table_length_get to obtain the length of an entry's string. More... | |
| KAPI void * | binary_string_table_serialized (const binary_string_table *table, u64 *out_size) |
| Serialize table to a single block of memory, tagged with MEMORY_TAG_BINARY_DATA. Should be freed by the caller. More... | |
This files contains an implementation of a binary string table.
A binary string table is used to hold strings in a contiguous block of memory in a way that is easily serialized and referenced. Strings are referenced by an index that is returned when an entry is added. This allows data structures that are to be serialized (for example) to simply store that index into this table, which itself can also be serialized into a binary block within the same file and can be referenced later during deserialization.
| typedef struct binary_string_table binary_string_table |
| typedef struct binary_string_table_entry binary_string_table_entry |
| typedef struct binary_string_table_header binary_string_table_header |
| KAPI u32 binary_string_table_add | ( | binary_string_table * | table, |
| const char * | string | ||
| ) |
Adds the given string to the provided table. String MUST be null-terminated.
| table | A pointer to the table to add to. |
| The | null-terminated string to be added. |
| KAPI binary_string_table binary_string_table_create | ( | void | ) |
Creates a binary string table.
| KAPI void binary_string_table_destroy | ( | binary_string_table * | table | ) |
Destroys the provided binary string table.
| table | A pointer to the table to be destroyted. |
| KAPI binary_string_table binary_string_table_from_block | ( | void * | block | ) |
Creates a binary string table from the given block of memory. This should have been created by the binary_string_table_serialized() function for this to work correctly. Typically used when reading from a file.
| KAPI const char* binary_string_table_get | ( | const binary_string_table * | table, |
| u32 | index | ||
| ) |
Returns a null-terminated copy of the string from the table. Dynamically allocated and must be freed by the caller.
| table | A constant pointer to the table to search. |
| index | The index of the string to look up. |
| KAPI void binary_string_table_get_buffered | ( | const binary_string_table * | table, |
| u32 | index, | ||
| char * | buffer | ||
| ) |
Copies string into already-existing buffer. Use binary_string_table_length_get to obtain the length of an entry's string.
| table | A constant pointer to the table to search. |
| index | The index of the string to look up. |
| buffer | Allocated memory to hold the string data. Ideally should be length + 1 to account for a null terminator (although one is not added by this function) |
| KAPI u32 binary_string_table_length_get | ( | const binary_string_table * | table, |
| u32 | index | ||
| ) |
Returns the length of the string, NOT accounting for null terminator.
| table | A constant pointer to the table to search. |
| index | The index of the string to look up. |
| KAPI void* binary_string_table_serialized | ( | const binary_string_table * | table, |
| u64 * | out_size | ||
| ) |
Serialize table to a single block of memory, tagged with MEMORY_TAG_BINARY_DATA. Should be freed by the caller.
| table | A constant pointer to the table to serialize. |
| out_size | A pointer to hold the total serialized block size. |