summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-11-16 14:27:30 +0800
committeryangwei <[email protected]>2024-11-18 17:10:28 +0800
commita342c7793a626dde650e754beeef317f1f859bd5 (patch)
tree9665f525b018408c2ef2de1d936e50690923645f /include
parent88dbc0b001ce688f01930bd97b4f010859c0c18b (diff)
✨ feat(define kv.h): include in .stellar/
Diffstat (limited to 'include')
-rw-r--r--include/stellar/kv.h100
-rw-r--r--include/stellar/mq.h2
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);