summaryrefslogtreecommitdiff
path: root/source/kit/unival.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/kit/unival.h')
-rw-r--r--source/kit/unival.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/source/kit/unival.h b/source/kit/unival.h
new file mode 100644
index 0000000..a87a763
--- /dev/null
+++ b/source/kit/unival.h
@@ -0,0 +1,79 @@
+#ifndef KIT_UV_H
+#define KIT_UV_H
+
+#include "status.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 };
+enum { KIT_UV_PRINT_PRETTY = 1, KIT_UV_PRINT_JSON = 2 };
+
+typedef struct kit_uv_data kit_unival_t;
+
+typedef KIT_DA(kit_unival_t) kit_da_unival_t;
+typedef KIT_DA(u8) kit_uv_bytes_t;
+
+struct kit_uv_data {
+ 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 {
+ kit_status_t status;
+ kit_unival_t *value;
+} kit_uv_decode_result_t;
+
+typedef struct {
+ kit_status_t status;
+ kit_uv_bytes_t value;
+} kit_uv_encode_result_t;
+
+typedef struct {
+ kit_status_t status;
+ kit_str_builder_t value;
+} kit_uv_print_result_t;
+
+kit_uv_decode_result_t kit_uv_decode(kit_is_handle_t is,
+ kit_allocator_t *alloc);
+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);
+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