summaryrefslogtreecommitdiff
path: root/kit/unival.h
diff options
context:
space:
mode:
Diffstat (limited to 'kit/unival.h')
-rw-r--r--kit/unival.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/kit/unival.h b/kit/unival.h
new file mode 100644
index 0000000..e0362b1
--- /dev/null
+++ b/kit/unival.h
@@ -0,0 +1,86 @@
+#ifndef KIT_UNIVAL_H
+#define KIT_UNIVAL_H
+
+#include "string_builder.h"
+#include "input_stream.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum {
+ KIT_UV_NONE,
+ KIT_UV_BOOLEAN,
+ KIT_UV_INTEGER,
+ KIT_UV_FLOAT,
+ KIT_UV_STRING,
+ KIT_UV_BYTES,
+ KIT_UV_ARRAY,
+ KIT_UV_COMPOSITE,
+};
+
+enum {
+ KIT_UV_ENCODE_BZIP = 1,
+ KIT_UV_PRINT_PRETTY = 1,
+ KIT_UV_PRINT_JSON = 2,
+};
+
+typedef struct kit_unival_ kit_unival_t;
+
+typedef KIT_DA(kit_unival_t) kit_da_unival_t;
+typedef KIT_DA(u8) kit_uv_bytes_t;
+
+struct kit_unival_ {
+ i8 type;
+ union {
+ i8 boolean;
+ i64 integer;
+ f64 float_;
+ kit_str_builder_t string;
+ kit_uv_bytes_t bytes;
+ kit_da_unival_t array;
+ struct {
+ kit_da_unival_t keys;
+ kit_da_unival_t values;
+ } composite;
+ };
+};
+
+typedef struct {
+ s32 status;
+ kit_unival_t *value;
+} kit_uv_decode_result_t;
+
+kit_uv_decode_result_t kit_uv_decode(kit_is_handle_t is,
+ kit_allocator_t *alloc);
+
+typedef struct {
+ s32 status;
+ kit_uv_bytes_t value;
+} kit_uv_encode_result_t;
+
+kit_uv_encode_result_t kit_uv_encode(kit_unival_t *value,
+ kit_allocator_t *alloc,
+ i32 flags);
+
+kit_uv_decode_result_t kit_uv_parse(kit_is_handle_t is,
+ kit_allocator_t *alloc);
+
+kit_uv_decode_result_t kit_uv_parse_json(kit_is_handle_t is,
+ kit_allocator_t *alloc);
+
+typedef struct {
+ s32 status;
+ kit_str_builder_t value;
+} kit_uv_print_result_t;
+
+kit_uv_print_result_t kit_uv_print(kit_unival_t *value,
+ kit_allocator_t *alloc, i32 flags);
+
+void kit_uv_destroy(kit_unival_t *value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif