A generic storage interface.
More...
|
RUAPI KvStore * | ruNewStore (void) |
| Returns a generic KvStore interface. This function is mainly used by those implementing the KvStore interface. More...
|
|
RUAPI void | ruFreeStore (void *obj) |
| Public function to free the given KvStore object. More...
|
|
RUAPI int32_t | ruValidStore (void *obj) |
| Checks given object to be a valid KvStore object. More...
|
|
RUAPI KvStore * | ruNewFileStore (const char *folderPath, int32_t *code) |
| Returns a newly created file system based KvStore object. If there is already store data in the given folder, it is opened and used. More...
|
|
RUAPI int32_t | ruFileStoreSet (KvStore *kvs, const char *key, const char *val, rusize len) |
| Set the value of key in the given FileStore. More...
|
|
RUAPI int32_t | ruFileStoreGet (KvStore *kvs, const char *key, char **val, rusize *len) |
| Get the value of key from the given FileStore. More...
|
|
RUAPI int32_t | ruFileStoreList (KvStore *kvs, const char *key, ruList *result) |
| Returns a list of keys under the given key. More...
|
|
RUAPI KvStore * | ruNewNullStore (void) |
| Returns a newly created NULL based KvStore interface. This keystore silently ignores setters and never returns data. More...
|
|
RUAPI int32_t | ruNullStoreSet (KvStore *kvs, const char *key, const char *val, rusize len) |
| Set the value of key in the given FileStore. More...
|
|
RUAPI int32_t | ruNullStoreGet (KvStore *kvs, const char *key, char **val, rusize *len) |
| Get the value of key from the given KvStore. More...
|
|
RUAPI int32_t | ruNullStoreList (KvStore *kvs, const char *key, ruList *list) |
| Returns a list of items under given key. More...
|
|
A generic storage interface.
Key Value Storage
Currently provided implementations are ruFileStore for file system based storage and ruNullStore to omit local storage altogether. It consists of a simple kvget, kvset and kvlist call.
Key Value Storage
A Key Value Store is a generic storage interface designed to allow for flexible data serialization.
kvstore key
This is a space separated string that also accept filesystem type globs like *. Each intersecting space indicates a sub level much like a folder in a file system, or a sub branch in a hierarchy. In most cases * is only supported at the end.
◆ kvget
typedef int32_t(* kvget) (struct KvStore_ *kvs, const char *key, char **val, rusize *len) |
KvStore getter function interface.
- Parameters
-
kvs | KvStore object. |
key | The kvstore key to the data in question. |
val | Where the retrieved value will be stored. Most of the time the caller should free this with ruFree when done with it. See implementation details. |
len | The number of bytes that make up val. |
- Returns
- RUE_OK on success else an error code.
◆ kvlist
typedef int32_t(* kvlist) (struct KvStore_ *kvs, const char *key, ruList *list) |
KvStore list function interface.
- Parameters
-
kvs | KvStore context where data will be retrieved from. |
key | The kvstore key to the data in question. Should end with a *. |
list | An ruList of kvstore key strings. Should be freed with ruListFree after use. |
- Returns
- RUE_OK on success else an error code.
◆ kvset
typedef int32_t(* kvset) (struct KvStore_ *kvs, const char *key, const char *val, rusize len) |
KvStore setter function interface.
- Parameters
-
kvs | KvStore object. |
key | The kvstore key to the data in question. |
val | The value that will be stored or NULL if the key is to be removed. |
len | The number of bytes that make up val or RU_SIZE_AUTO. |
- Returns
- RUE_OK on success else an error code.
◆ KvStore
The key/value store interface type. This object holds the kvget, kvlist and kvset methods of an implementation.
◆ ruFileStore
Opaque pointer to a File based KvStore interface.
◆ ruNullStore
Opaque pointer to a Null KvStore interface.
◆ ruFileStoreGet()
RUAPI int32_t ruFileStoreGet |
( |
KvStore * |
kvs, |
|
|
const char * |
key, |
|
|
char ** |
val, |
|
|
rusize * |
len |
|
) |
| |
Get the value of key from the given FileStore.
- Parameters
-
kvs | FileStore context where data will be retrieved from. |
key | The kvstore key to the data in question. |
val | Where the retrieved value will be stored. Caller should free this with ruFree when done with it. |
len | The number of bytes that make up val. |
- Returns
- RUE_OK on success else an error code.
◆ ruFileStoreList()
RUAPI int32_t ruFileStoreList |
( |
KvStore * |
kvs, |
|
|
const char * |
key, |
|
|
ruList * |
result |
|
) |
| |
Returns a list of keys under the given key.
- Parameters
-
kvs | FileStore context where key will be listed from. |
key | The kvstore key to the data in question. May end with " *" |
result | An ruList of kvstore key strings. Should be freed with ruListFree after use. |
- Returns
- RUE_OK on success else an error code.
◆ ruFileStoreSet()
RUAPI int32_t ruFileStoreSet |
( |
KvStore * |
kvs, |
|
|
const char * |
key, |
|
|
const char * |
val, |
|
|
rusize |
len |
|
) |
| |
Set the value of key in the given FileStore.
- Parameters
-
kvs | FileStore context where data will be stored. |
key | The kvstore key to the data in question. |
val | The value that will be stored or NULL if the key is to be removed. The value will be copied. |
len | The number of bytes that make up val or RU_SIZE_AUTO. |
- Returns
- RUE_OK on success else an error code.
◆ ruFreeStore()
RUAPI void ruFreeStore |
( |
void * |
obj | ) |
|
Public function to free the given KvStore object.
- Parameters
-
◆ ruNewFileStore()
RUAPI KvStore* ruNewFileStore |
( |
const char * |
folderPath, |
|
|
int32_t * |
code |
|
) |
| |
Returns a newly created file system based KvStore object. If there is already store data in the given folder, it is opened and used.
- Parameters
-
folderPath | Top level folder under which the data will be stored. |
code | Return code willbe RUE_OK on success or error otherwise. |
- Returns
- KvStore object on success else NULL.
◆ ruNewNullStore()
RUAPI KvStore* ruNewNullStore |
( |
void |
| ) |
|
Returns a newly created NULL based KvStore interface. This keystore silently ignores setters and never returns data.
- Returns
- KvStore object.
◆ ruNewStore()
Returns a generic KvStore interface. This function is mainly used by those implementing the KvStore interface.
- Returns
- A new empty KvStore object;
◆ ruNullStoreGet()
RUAPI int32_t ruNullStoreGet |
( |
KvStore * |
kvs, |
|
|
const char * |
key, |
|
|
char ** |
val, |
|
|
rusize * |
len |
|
) |
| |
Get the value of key from the given KvStore.
- Parameters
-
kvs | KvStore context where data will be retrieved from. |
key | The kvstore key to the data in question. |
val | Where the retrieved value will be stored. Will always be NULL. |
len | The number of bytes that make up val. Will always be 0. |
- Returns
- RUE_OK on success else an error code.
◆ ruNullStoreList()
RUAPI int32_t ruNullStoreList |
( |
KvStore * |
kvs, |
|
|
const char * |
key, |
|
|
ruList * |
list |
|
) |
| |
Returns a list of items under given key.
- Parameters
-
kvs | KvStore context where data will be retrieved from. |
key | The kvstore key to the data in question. Should end with a *. |
list | A NULL ruList of keys that would normally be found. |
- Returns
- RUE_OK on success else an error code.
◆ ruNullStoreSet()
RUAPI int32_t ruNullStoreSet |
( |
KvStore * |
kvs, |
|
|
const char * |
key, |
|
|
const char * |
val, |
|
|
rusize |
len |
|
) |
| |
Set the value of key in the given FileStore.
- Parameters
-
kvs | KvStore context where data will be stored. |
key | The kvstore key to the data in question. |
val | The value that will be stored or NULL if the key is to be removed. |
len | The number of bytes that make up val or RU_SIZE_AUTO. |
- Returns
- RUE_OK on success else an error code.
◆ ruValidStore()
RUAPI int32_t ruValidStore |
( |
void * |
obj | ) |
|
Checks given object to be a valid KvStore object.
- Parameters
-
obj | The object to validate. |
- Returns
- RUE_OK if valid else an errro code.