aboutsummaryrefslogtreecommitdiff
path: root/msgpack.h
diff options
context:
space:
mode:
Diffstat (limited to 'msgpack.h')
-rw-r--r--msgpack.h71
1 files changed, 37 insertions, 34 deletions
diff --git a/msgpack.h b/msgpack.h
index fc3ab9a..7eff711 100644
--- a/msgpack.h
+++ b/msgpack.h
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <stdbool.h>
/* -- Data structures --
*
@@ -40,19 +41,18 @@
*/
typedef struct mp_msgpack {
- char *bin;
+ uint8_t *bin;
size_t size;
- struct mp_membuf {
- uintptr_t offset;
- size_t *buf;
- } *membuf;
+ // struct mp_membuf {
+ // uintptr_t offset;
+ // size_t *buf;
+ // } *membuf;
} msgpack_t;
#define msgpack_init(bin, size, membuf) \
- ((msgpack_t){(bin), (size), (membuf)})
-#define membuf_init(uintptr_bin, size_t_buf) \
- ((struct mp_membuf){(offset), (buf)})
+ ((msgpack_t){(bin), (size)})
+// ((msgpack_t){(bin), (size), (membuf)})
union mp_int {
int64_t i;
@@ -62,7 +62,12 @@ union mp_int {
union mp_float {
float f;
double d;
- uint64_t _u;
+ uint64_t u;
+};
+
+struct mp_bin {
+ uint8_t* bin;
+ size_t size;
};
struct mp_array {
@@ -76,11 +81,6 @@ struct mp_map {
size_t length;
};
-struct mp_bin {
- char* bin;
- size_t size;
-};
-
struct mp_timestamp {
// ...
};
@@ -111,30 +111,33 @@ struct mp_timestamp {
*
*/
-int msgpack_read_int (const msgpack_t *pack, union mp_int *m);
-int msgpack_read_bool (const msgpack_t *pack, int *m);
-int msgpack_read_float (const msgpack_t *pack, union mp_float *m);
+enum msgpack_type;
-int msgpack_read_raw (const msgpack_t *pack, struct mp_bin *m);
-int msgpack_read_raw_cpy (const msgpack_t *pack, struct mp_bin *m);
-int msgpack_read_ext (const msgpack_t *pack, struct mp_bin *m);
-int msgpack_read_ext_cpy (const msgpack_t *pack, struct mp_bin *m);
+int msgpack_read_nil (msgpack_t *pack);
+int msgpack_read_int (msgpack_t *pack, union mp_int *m);
+int msgpack_read_bool (msgpack_t *pack, bool *m);
+int msgpack_read_float (msgpack_t *pack, union mp_float *m);
+
+int msgpack_read_raw (msgpack_t *pack, struct mp_bin *m);
+// int msgpack_read_raw_cpy (msgpack_t *pack, struct mp_bin *m);
+int msgpack_read_ext (msgpack_t *pack, struct mp_bin *m);
+// int msgpack_read_ext_cpy (msgpack_t *pack, struct mp_bin *m);
int msgpack_read_array (msgpack_t *pack, size_t *length);
int msgpack_read_map (msgpack_t *pack, size_t *length);
-int msgpack_read_array2 (const msgpack_t *pack, struct mp_array *m);
-int msgpack_read_map2 (const msgpack_t *pack, struct mp_map *m);
+// int msgpack_read_array2 (const msgpack_t *pack, struct mp_array *m);
+// int msgpack_read_map2 (const msgpack_t *pack, struct mp_map *m);
-int msgpack_write_int (msgpack_t *pack, const union mp_int *m, int subtype);
-int msgpack_write_bool (msgpack_t *pack, const int *m);
-int msgpack_write_float (msgpack_t *pack, const union mp_float *m, int subtype);
+int msgpack_write_int (msgpack_t *pack, const union mp_int *m, enum msgpack_type subtype);
+int msgpack_write_bool (msgpack_t *pack, const bool *m);
+int msgpack_write_float (msgpack_t *pack, const union mp_float *m, enum msgpack_type subtype);
-int msgpack_write_raw (msgpack_t *pack, const struct mp_bin *m, int subtype);
-int msgpack_write_ext (msgpack_t *pack, const struct mp_bin *m, int subtype);
+int msgpack_write_raw (msgpack_t *pack, const struct mp_bin *m, enum msgpack_type subtype);
+int msgpack_write_ext (msgpack_t *pack, const struct mp_bin *m, enum msgpack_type subtype);
-int msgpack_write_array (msgpack_t *pack, const size_t *length);
-int msgpack_write_map (msgpack_t *pack, const size_t *length);
+int msgpack_write_array (msgpack_t *pack, const size_t *m);
+int msgpack_write_map (msgpack_t *pack, const size_t *m);
/* -- MessagePack Types --
*
@@ -157,9 +160,9 @@ int msgpack_write_map (msgpack_t *pack, const size_t *length);
X(MSGPACK_ARRAY) \
X(MSGPACK_MAP) \
X(MSGPACK_EXT) \
- X(MSGPACK_UNKNOWN) \
#define MSGPACK_SUBTYPES(X) \
+ X(MSGPACK_UNKNOWN) \
X(MSGPACK_INT_SIGNED) \
X(MSGPACK_INT_UNSIGNED) \
X(MSGPACK_FLOAT_32) \
@@ -170,11 +173,11 @@ int msgpack_write_map (msgpack_t *pack, const size_t *length);
#define MSGPACK_ERRORS(X) \
X(MSGPACK_ERROR_UNKNOWN) \
+ X(MSGPACK_ERROR_INVALID_PACK) \
+ X(MSGPACK_ERROR_INVALID_ARGUMENT) \
X(MSGPACK_ERROR_WRONG_TYPE) \
X(MSGPACK_ERROR_UNSUFFICIENT_CAPACITY) \
- X(MSGPACK_ERROR_UNEXPECTED_END) \
- X(MSGPACK_ERROR_INVALID_PACK) \
- X(MSGPACK_ERROR_INVALID_ARGUMENT)
+ X(MSGPACK_ERROR_UNEXPECTED_END)
#define X_TO_ENUM(e) e,
#define X_TO_STRING(e) [e] = #e,