feat(lsm): add some attr & data support functions; fix str bug

This commit is contained in:
Jef Roosens 2023-11-03 13:23:46 +01:00
parent fbf6557c05
commit 8b6d1f6e91
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
4 changed files with 91 additions and 11 deletions

View file

@ -44,6 +44,16 @@ bool lsm_entry_attr_present(lsm_entry_handle *handle, lsm_attr_type type);
lsm_error lsm_entry_attr_get(lsm_str **out, lsm_entry_handle *handle,
lsm_attr_type type);
/**
* Convenience wrapper around `lsm_entry_attr_get` that can be used if we know
* beforehand the attribute value is a 64-bit number.
*
* @param out where to store attribute data
* @param entry entry to search for
* @param type type of attribute to return
*/
lsm_error lsm_entry_attr_get_num(uint64_t *out, lsm_entry_handle *handle, lsm_attr_type type);
/**
* Add a new attribute to the entry.
*
@ -54,6 +64,16 @@ lsm_error lsm_entry_attr_get(lsm_str **out, lsm_entry_handle *handle,
lsm_error lsm_entry_attr_insert(lsm_entry_handle *handle, lsm_attr_type type,
lsm_str *data);
/**
* Convenience wrapper around `lsm_entry_attr_insert` that can be used if the
* data to be stored is a 64-bit number.
*
* @param entry entry to modify
* @param type type of attribute to add
* @param data data of attribute
*/
lsm_error lsm_entry_attr_insert_num(lsm_entry_handle *handle, lsm_attr_type type, uint64_t data);
/**
* Remove an atribute from the given entry, if present.
*
@ -151,6 +171,16 @@ lsm_error lsm_store_insert(lsm_entry_handle **out, lsm_store *store,
lsm_error lsm_entry_data_append(lsm_store *store, lsm_entry_handle *handle,
lsm_str *data);
/**
* Same as `lsm_entry_data_append`, except that it takes a direct char array.
*
* @param store store the entry is stored in
* @param entry entry to append data to
* @param data data to append
* @param len length of data array
*/
lsm_error lsm_entry_data_append_raw(lsm_store *store, lsm_entry_handle *handle, char *data, uint64_t len);
/**
* Read a number of bytes from the entry's data field. The position from which
* data is read is dependent on previous read calls.
@ -163,4 +193,12 @@ lsm_error lsm_entry_data_append(lsm_store *store, lsm_entry_handle *handle,
lsm_error lsm_entry_data_read(uint64_t *out, char *buf,
lsm_entry_handle *handle, uint64_t len);
/**
* Return the length of the entry's data.
*
* @param handle entry handle to return length for
* @return length of the data
*/
uint64_t lsm_entry_data_len(lsm_entry_handle *handle);
#endif