Skip to content

Commit

Permalink
Add support deserializing the bin format family
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Der committed Jun 24, 2015
1 parent 715013c commit fb7ecfa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
12 changes: 7 additions & 5 deletions msgpack/unpack_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ typedef enum {
//CS_ = 0x02, // false
//CS_ = 0x03, // true

//CS_ = 0x04,
//CS_ = 0x05,
//CS_ = 0x06,
//CS_ = 0x07,
CS_BIN_8 = 0x04,
CS_BIN_16 = 0x05,
CS_BIN_32 = 0x06,

//CS_ = 0x07,
//CS_ = 0x08,
//CS_ = 0x09,

CS_FLOAT = 0x0a,
CS_DOUBLE = 0x0b,
CS_UINT_8 = 0x0c,
Expand All @@ -65,7 +66,7 @@ typedef enum {
//CS_BIG_INT_32 = 0x17,
//CS_BIG_FLOAT_16 = 0x18,
//CS_BIG_FLOAT_32 = 0x19,
CS_RAW_8 = 0x19,
CS_RAW_8 = 0x19,
CS_RAW_16 = 0x1a,
CS_RAW_32 = 0x1b,
CS_ARRAY_16 = 0x1c,
Expand All @@ -75,6 +76,7 @@ typedef enum {

//ACS_BIG_INT_VALUE,
//ACS_BIG_FLOAT_VALUE,
ACS_BIN_VALUE,
ACS_RAW_VALUE,
} msgpack_unpack_state;

Expand Down
20 changes: 17 additions & 3 deletions msgpack/unpack_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,12 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
push_simple_value(_false);
case 0xc3: // true
push_simple_value(_true);
//case 0xc4:
//case 0xc5:
//case 0xc6:
case 0xc4: // bin 8
again_fixed_trail(NEXT_CS(p), 1);
case 0xc5: // bin 16
again_fixed_trail(NEXT_CS(p), 2);
case 0xc6: // bin 32
again_fixed_trail(NEXT_CS(p), 4);
//case 0xc7:
//case 0xc8:
//case 0xc9:
Expand Down Expand Up @@ -241,6 +244,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
case 0xdf: // map 32
again_fixed_trail(NEXT_CS(p), 2 << (((unsigned int)*p) & 0x01));
default:
fprintf(stdout, "\n FUCK %d \n", *p);
goto _failed;
}
SWITCH_RANGE(0xa0, 0xbf) // FixRaw
Expand Down Expand Up @@ -291,6 +295,16 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
case CS_INT_64:
push_fixed_value(_int64, _msgpack_load64(int64_t,n));

case CS_BIN_8:
again_fixed_trail_if_zero(ACS_BIN_VALUE, *(uint8_t*)n, _bin_zero);
case CS_BIN_16:
again_fixed_trail_if_zero(ACS_BIN_VALUE, _msgpack_load16(uint16_t,n), _bin_zero);
case CS_BIN_32:
again_fixed_trail_if_zero(ACS_BIN_VALUE, _msgpack_load32(uint32_t,n), _bin_zero);
case ACS_BIN_VALUE:
_bin_zero:
push_variable_value(_bin, data, n, trail);

//case CS_
//case CS_
//case CS_BIG_INT_16:
Expand Down
12 changes: 12 additions & 0 deletions msgpack_unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,18 @@ int msgpack_unserialize_raw(
return 0;
}

int msgpack_unserialize_bin(
msgpack_unserialize_data *unpack, const char* base,
const char* data, unsigned int len, zval **obj)
{
MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack);

ZVAL_STRINGL(*obj, (char *)data, len, 1);

return 0;
}


int msgpack_unserialize_array(
msgpack_unserialize_data *unpack, unsigned int count, zval **obj)
{
Expand Down
5 changes: 5 additions & 0 deletions msgpack_unpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ int msgpack_unserialize_false(msgpack_unserialize_data *unpack, zval **obj);
int msgpack_unserialize_raw(
msgpack_unserialize_data *unpack, const char* base, const char* data,
unsigned int len, zval **obj);
int msgpack_unserialize_bin(
msgpack_unserialize_data *unpack, const char* base, const char* data,
unsigned int len, zval **obj);
int msgpack_unserialize_array(
msgpack_unserialize_data *unpack, unsigned int count, zval **obj);
int msgpack_unserialize_array_item(
Expand Down Expand Up @@ -120,6 +123,8 @@ static inline msgpack_unpack_object template_callback_root(unpack_user* user)
msgpack_unserialize_false(user, obj)
#define template_callback_raw(user, base, data, len, obj) \
msgpack_unserialize_raw(user, base, data, len, obj)
#define template_callback_bin(user, base, data, len, obj) \
msgpack_unserialize_bin(user, base, data, len, obj)
#define template_callback_array(user, count, obj) \
msgpack_unserialize_array(user, count, obj)
#define template_callback_array_item(user, container, obj) \
Expand Down

0 comments on commit fb7ecfa

Please sign in to comment.