diff options
Diffstat (limited to 'msgpack.c')
-rw-r--r-- | msgpack.c | 36 |
1 files changed, 24 insertions, 12 deletions
@@ -2,7 +2,6 @@ #include <endian.h> // endianness #include <string.h> // memcpy -// TODO: fix all these #define PINT8_H(p) (*(int8_t*)(p)) #define PINT16_H(p) ((int16_t)be16toh(*(uint16_t *)(p))) #define PINT32_H(p) ((int32_t)be32toh(*(uint32_t *)(p))) @@ -13,15 +12,26 @@ #define PUINT32_H(p) (be32toh(*(uint32_t *)(p))) #define PUINT64_H(p) (be64toh(*(uint64_t *)(p))) -#define H_PINT8(b) (*(int8_t*)(b)) -#define H_PINT16(b) ((int16_t)htobe16((int16_t)(b))) -#define H_PINT32(b) ((int32_t)htobe32((int32_t)(b))) -#define H_PINT64(b) ((int64_t)htobe64((int64_t)(b))) +#define H_UINT8(b) ((uint8_t)b) +#define H_UINT16(b) ((uint16_t)htobe16((uint16_t)(b))) +#define H_UINT32(b) ((uint32_t)htobe32((uint32_t)(b))) +#define H_UINT64(b) ((uint64_t)htobe64((uint64_t)(b))) -#define F32_H(b) (*(float *) &be32toh(*(uint32_t *)(b))) -#define F64_H(b) (*(double *)&be64toh(*(uint64_t *)(b))) -#define H_F32(b) (*(float *) &htobe32(*(uint32_t *)(b))) -#define H_F64(b) (*(double *)&htobe64(*(uint64_t *)(b))) +#define H_UINT8_CPY(b, p) (((uint8_t*)(p))[0] = H_UINT8(b)); +#define H_UINT16_CPY(b, p) (((uint16_t*)(p))[0] = H_UINT16(b)) +#define H_UINT32_CPY(b, p) (((uint32_t*)(p))[0] = H_UINT32(b)) +#define H_UINT64_CPY(b, p) (((uint64_t*)(p))[0] = H_UINT64(b)) + +#define H_INT8_CPY(b, p) H_UINT8_CPY(b, p) +#define H_INT16_CPY(b, p) H_UINT16_CPY(b, p) +#define H_INT32_CPY(b, p) H_UINT32_CPY(b, p) +#define H_INT64_CPY(b, p) H_UINT64_CPY(b, p) + +// fix these +// #define F32_H(b) (*(float *) &be32toh(*(uint32_t *)(b))) +// #define F64_H(b) (*(double *)&be64toh(*(uint64_t *)(b))) +// #define H_F32(b) (*(float *) &htobe32(*(uint32_t *)(b))) +// #define H_F64(b) (*(double *)&htobe64(*(uint64_t *)(b))) // range low, range high #define RANGES(X) \ @@ -174,7 +184,9 @@ const enum msgpack_type subtype; #define OP_INT_READ(_byte, ptr, value, x_conv) \ value = P##x_conv##_H(ptr) -#define OP_INT_WRITE(x_byte, ptr, value, x_conv) +#define OP_INT_WRITE(x_byte, ptr, value, x_conv) \ + (ptr-1)[0] = x_byte; /* temp fix*/ \ + H_##x_conv##_CPY((value), (ptr)) #define MAKE_X_INT(op, x_byte, x_fmt, x_type, x_subtype, x_offset, x_length, x_field, x_conv, ...) \ case x_fmt: \ @@ -211,7 +223,7 @@ int msgpack_read_int (msgpack_t *pack, union mp_int *m) COMPOSE_FUNCTION(RE int msgpack_write_nil (msgpack_t *pack); int msgpack_write_bool (msgpack_t *pack, const bool *m) COMPOSE_FUNCTION(WRITE, BOOL) -int msgpack_write_int (msgpack_t *pack, const union mp_int *m, enum msgpack_type subtype); +int msgpack_write_int (msgpack_t *pack, const union mp_int *m, enum msgpack_type subtype) COMPOSE_FUNCTION(WRITE, INT) 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, enum msgpack_type subtype); @@ -243,7 +255,7 @@ static enum msgpack_fmt pack_fmt(msgpack_t *pack) #define WRAP_FMT_INT(e) \ case MSGPACK_INT: e; break; -#define X_FMT_INT(_byte, x_fmt, x_type, x_subtype, _offset, _length, x_field, _conv, x_range_high, x_range_low) \ +#define X_FMT_INT(_byte, x_fmt, x_type, x_subtype, _offset, _length, x_field, _conv, x_range_low, x_range_high) \ if((x_subtype == subtype) && \ (((union mp_int *)m)->x_field >= x_range_low) && \ (((union mp_int *)m)->x_field <= x_range_high)) \ |