Skip to content

Commit 790e4c9

Browse files
committed
Add support deserializing the bin format family
1 parent 715013c commit 790e4c9

4 files changed

Lines changed: 40 additions & 8 deletions

File tree

msgpack/unpack_define.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ typedef enum {
4141
//CS_ = 0x02, // false
4242
//CS_ = 0x03, // true
4343

44-
//CS_ = 0x04,
45-
//CS_ = 0x05,
46-
//CS_ = 0x06,
47-
//CS_ = 0x07,
44+
CS_BIN_8 = 0x04,
45+
CS_BIN_16 = 0x05,
46+
CS_BIN_32 = 0x06,
4847

48+
//CS_ = 0x07,
4949
//CS_ = 0x08,
5050
//CS_ = 0x09,
51+
5152
CS_FLOAT = 0x0a,
5253
CS_DOUBLE = 0x0b,
5354
CS_UINT_8 = 0x0c,
@@ -65,7 +66,7 @@ typedef enum {
6566
//CS_BIG_INT_32 = 0x17,
6667
//CS_BIG_FLOAT_16 = 0x18,
6768
//CS_BIG_FLOAT_32 = 0x19,
68-
CS_RAW_8 = 0x19,
69+
CS_RAW_8 = 0x19,
6970
CS_RAW_16 = 0x1a,
7071
CS_RAW_32 = 0x1b,
7172
CS_ARRAY_16 = 0x1c,
@@ -75,6 +76,7 @@ typedef enum {
7576

7677
//ACS_BIG_INT_VALUE,
7778
//ACS_BIG_FLOAT_VALUE,
79+
ACS_BIN_VALUE,
7880
ACS_RAW_VALUE,
7981
} msgpack_unpack_state;
8082

msgpack/unpack_template.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,12 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
204204
push_simple_value(_false);
205205
case 0xc3: // true
206206
push_simple_value(_true);
207-
//case 0xc4:
208-
//case 0xc5:
209-
//case 0xc6:
207+
case 0xc4: // bin 8
208+
again_fixed_trail(NEXT_CS(p), 1);
209+
case 0xc5: // bin 16
210+
again_fixed_trail(NEXT_CS(p), 2);
211+
case 0xc6: // bin 32
212+
again_fixed_trail(NEXT_CS(p), 4);
210213
//case 0xc7:
211214
//case 0xc8:
212215
//case 0xc9:
@@ -291,6 +294,16 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
291294
case CS_INT_64:
292295
push_fixed_value(_int64, _msgpack_load64(int64_t,n));
293296

297+
case CS_BIN_8:
298+
again_fixed_trail_if_zero(ACS_BIN_VALUE, *(uint8_t*)n, _bin_zero);
299+
case CS_BIN_16:
300+
again_fixed_trail_if_zero(ACS_BIN_VALUE, _msgpack_load16(uint16_t,n), _bin_zero);
301+
case CS_BIN_32:
302+
again_fixed_trail_if_zero(ACS_BIN_VALUE, _msgpack_load32(uint32_t,n), _bin_zero);
303+
case ACS_BIN_VALUE:
304+
_bin_zero:
305+
push_variable_value(_bin, data, n, trail);
306+
294307
//case CS_
295308
//case CS_
296309
//case CS_BIG_INT_16:

msgpack_unpack.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,18 @@ int msgpack_unserialize_raw(
509509
return 0;
510510
}
511511

512+
int msgpack_unserialize_bin(
513+
msgpack_unserialize_data *unpack, const char* base,
514+
const char* data, unsigned int len, zval **obj)
515+
{
516+
MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack);
517+
518+
ZVAL_STRINGL(*obj, (char *)data, len, 1);
519+
520+
return 0;
521+
}
522+
523+
512524
int msgpack_unserialize_array(
513525
msgpack_unserialize_data *unpack, unsigned int count, zval **obj)
514526
{

msgpack_unpack.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ int msgpack_unserialize_false(msgpack_unserialize_data *unpack, zval **obj);
6060
int msgpack_unserialize_raw(
6161
msgpack_unserialize_data *unpack, const char* base, const char* data,
6262
unsigned int len, zval **obj);
63+
int msgpack_unserialize_bin(
64+
msgpack_unserialize_data *unpack, const char* base, const char* data,
65+
unsigned int len, zval **obj);
6366
int msgpack_unserialize_array(
6467
msgpack_unserialize_data *unpack, unsigned int count, zval **obj);
6568
int msgpack_unserialize_array_item(
@@ -120,6 +123,8 @@ static inline msgpack_unpack_object template_callback_root(unpack_user* user)
120123
msgpack_unserialize_false(user, obj)
121124
#define template_callback_raw(user, base, data, len, obj) \
122125
msgpack_unserialize_raw(user, base, data, len, obj)
126+
#define template_callback_bin(user, base, data, len, obj) \
127+
msgpack_unserialize_bin(user, base, data, len, obj)
123128
#define template_callback_array(user, count, obj) \
124129
msgpack_unserialize_array(user, count, obj)
125130
#define template_callback_array_item(user, container, obj) \

0 commit comments

Comments
 (0)