diff --git a/msgpack/unpack_define.h b/msgpack/unpack_define.h index bc513ca..c3a50ef 100644 --- a/msgpack/unpack_define.h +++ b/msgpack/unpack_define.h @@ -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, @@ -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, @@ -75,6 +76,7 @@ typedef enum { //ACS_BIG_INT_VALUE, //ACS_BIG_FLOAT_VALUE, + ACS_BIN_VALUE, ACS_RAW_VALUE, } msgpack_unpack_state; diff --git a/msgpack/unpack_template.h b/msgpack/unpack_template.h index 63508e4..07fe1d8 100644 --- a/msgpack/unpack_template.h +++ b/msgpack/unpack_template.h @@ -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: @@ -291,6 +294,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: diff --git a/msgpack_unpack.c b/msgpack_unpack.c index 3bf2ac9..45701ba 100644 --- a/msgpack_unpack.c +++ b/msgpack_unpack.c @@ -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) { diff --git a/msgpack_unpack.h b/msgpack_unpack.h index e140145..3239a27 100644 --- a/msgpack_unpack.h +++ b/msgpack_unpack.h @@ -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( @@ -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) \ diff --git a/tests/138.phpt b/tests/138.phpt new file mode 100644 index 0000000..f519c08 --- /dev/null +++ b/tests/138.phpt @@ -0,0 +1,36 @@ +--TEST-- +unpack bin format family +--SKIPIF-- + +--EXPECTF-- +string(9) "bin8 test" +OK +string(10) "bin16 test" +OK +string(10) "bin32 test" +OK