diff options
| author | yangwei <[email protected]> | 2024-11-25 19:22:20 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-11-25 19:22:20 +0800 |
| commit | 40083638202cbedea0728ce0ebe49472212aad9f (patch) | |
| tree | 9ddcdda9dc2dea08e0281730a35806736a9e2816 /include | |
| parent | 1199e9d83f1b2c2d47d8fb7de911674319379651 (diff) | |
✨ feat(define kv.h): include in .stellar/
Diffstat (limited to 'include')
| -rw-r--r-- | include/stellar/kv.h | 100 | ||||
| -rw-r--r-- | include/stellar/mq.h | 2 |
2 files changed, 101 insertions, 1 deletions
diff --git a/include/stellar/kv.h b/include/stellar/kv.h new file mode 100644 index 0000000..9f8bcc1 --- /dev/null +++ b/include/stellar/kv.h @@ -0,0 +1,100 @@ +#pragma once + +#include <stddef.h> +#include <uuid/uuid.h> + +struct kv +{ + char *key; + size_t key_sz; + enum + { + KV_VALUE_TYPE_INTEGER, + KV_VALUE_TYPE_DOUBLE, + KV_VALUE_TYPE_STRING, + KV_VALUE_TYPE_UUID, + KV_VALUE_TYPE_INTERGE_ARRAY, + KV_VALUE_TYPE_DOUBLE_ARRAY, + KV_VALUE_TYPE_STRING_ARRAY, + KV_VALUE_TYPE_UUID_ARRAY + }vtype; + union + { + long long value_longlong; + double value_double; + struct + { + char *str; + size_t sz; + }value_str; + uuid_t value_uuid; + struct + { + long long *elems; + size_t n_elems; + }value_interger_array; + struct + { + double *elems; + size_t n_elems; + }value_double_array; + struct + { + char **elems; + size_t *sz; + size_t n_elems; + }value_str_array; + struct + { + uuid_t *elems; + size_t n_elems; + }value_uuid_array; +/* + struct + { + struct kv *elems; + size_t n_elems; + }value_list; +*/ + }; +}; + +struct kv *kv_new_with_interger(const char *key, size_t key_sz, long long value); +struct kv *kv_new_with_double(const char *key, size_t key_sz, double value); +struct kv *kv_new_with_string(const char *key, size_t key_sz, const char *value, size_t value_sz); +struct kv *kv_new_with_uuid(const char *key, size_t key_sz, const uuid_t value); +struct kv *kv_new_with_interger_array(const char *key, size_t key_sz, long long value[], size_t n_value); +struct kv *kv_new_with_double_array(const char *key, size_t key_sz, double value[], size_t n_value); +struct kv *kv_new_with_string_array(const char *key, size_t key_sz, const char* value[], size_t value_sz[], size_t n_value); +struct kv *kv_new_with_uuid_array(const char *key, size_t key_sz, const uuid_t value[], size_t n_value); + +struct kv *kv_duplicate(const struct kv *kv); + +void kv_free(struct kv *kv); + +struct kv_table; + +struct kv_table *kv_table_new(size_t initial_size); +void kv_table_free(struct kv_table *table); + +//struct kv_table *kv_table_new_by_indexing(struct kv *kv); + +int kv_table_add(struct kv_table *table, const struct kv *kv); +int kv_table_del(struct kv_table *table, const char *key, size_t key_sz); + +typedef void (kv_ref_cleanup_cb)(const struct kv *kv, void *arg); +int kv_table_add_reference(struct kv_table *table, const struct kv *kv, kv_ref_cleanup_cb *cleanup_cb, void *arg); + +const struct kv *kv_table_get0(struct kv_table *table, const char *key, size_t key_sz); + +void kv_table_reset_iter(struct kv_table *table); +const struct kv *kv_table_next(struct kv_table *table); + +struct kv_table *kv_table_duplicate(const struct kv_table *table); +int kv_table_union(struct kv_table *dst, const struct kv_table *src); + +void kv_table_serialize(const struct kv_table *table, char **blob, size_t *blob_len); +struct kv_table *kv_table_deserialize(const char *blob, size_t blob_len); + +int kv_table_export_json(const struct kv_table *table, char **blob, size_t *blob_len); +int kv_table_export_msgpack(const struct kv_table *table, char **blob, size_t *blob_len);
\ No newline at end of file diff --git a/include/stellar/mq.h b/include/stellar/mq.h index 0a0bb9e..c273658 100644 --- a/include/stellar/mq.h +++ b/include/stellar/mq.h @@ -13,7 +13,7 @@ typedef void mq_msg_free_cb_func(void *msg, void *msg_free_arg); typedef void on_msg_cb_func(int topic_id, void *msg, void *on_msg_arg); typedef void on_msg_dispatch_cb_func(int topic_id, void *msg, - on_msg_cb_func* on_msg_cb, + on_msg_cb_func *on_msg_cb, void *on_msg_cb_arg, void *dispatch_arg); |
