Squashed 'third_party/rawrtc/re/' content from commit f3163ce8b
Change-Id: I6a235e6ac0f03269d951026f9d195da05c40fdab
git-subtree-dir: third_party/rawrtc/re
git-subtree-split: f3163ce8b526a13b35ef71ce4dd6f43585064d8a
diff --git a/include/re_json.h b/include/re_json.h
new file mode 100644
index 0000000..0cc43db
--- /dev/null
+++ b/include/re_json.h
@@ -0,0 +1,50 @@
+/**
+ * @file re_json.h Interface to JavaScript Object Notation (JSON) -- RFC 7159
+ *
+ * Copyright (C) 2010 - 2015 Creytiv.com
+ */
+
+enum json_typ {
+ JSON_STRING,
+ JSON_INT,
+ JSON_DOUBLE,
+ JSON_BOOL,
+ JSON_NULL,
+};
+
+struct json_value {
+ union {
+ char *str;
+ int64_t integer;
+ double dbl;
+ bool boolean;
+ } v;
+ enum json_typ type;
+};
+
+struct json_handlers;
+
+typedef int (json_object_entry_h)(const char *name,
+ const struct json_value *value, void *arg);
+typedef int (json_array_entry_h)(unsigned idx,
+ const struct json_value *value, void *arg);
+typedef int (json_object_h)(const char *name, unsigned idx,
+ struct json_handlers *h);
+typedef int (json_array_h)(const char *name, unsigned idx,
+ struct json_handlers *h);
+
+struct json_handlers {
+ json_object_h *oh;
+ json_array_h *ah;
+ json_object_entry_h *oeh;
+ json_array_entry_h *aeh;
+ void *arg;
+};
+
+int json_decode(const char *str, size_t len, unsigned maxdepth,
+ json_object_h *oh, json_array_h *ah,
+ json_object_entry_h *oeh, json_array_entry_h *aeh, void *arg);
+
+int json_decode_odict(struct odict **op, uint32_t hash_size, const char *str,
+ size_t len, unsigned maxdepth);
+int json_encode_odict(struct re_printf *pf, const struct odict *o);