msgpack_pack和msgpack_serialize和MessagePack :: pack有什么区别?

时间:2013-11-22 08:23:17

标签: php serialization php-extension msgpack

msgpack在msgpack extension的PHP中实现。

有两个函数msgpack_packmsgpack_serialize以及方法MessagePack::pack。我不知道他们之间有什么区别。如何找到此扩展的API?

1 个答案:

答案 0 :(得分:2)

他们是一样的。

这是msgpack_serialize,它调用函数php_msgpack_serialize;

static ZEND_FUNCTION(msgpack_serialize)
{
    zval *parameter;
    smart_str buf = {0};

    if (zend_parse_parameters(
            ZEND_NUM_ARGS() TSRMLS_CC, "z", &parameter) == FAILURE)
    {
        return;
    }

    php_msgpack_serialize(&buf, parameter TSRMLS_CC);

    ZVAL_STRINGL(return_value, buf.c, buf.len, 1);

    smart_str_free(&buf);
}

msgpack_packmsgpack_serialize的别名。

// in msgpack.c
static zend_function_entry msgpack_functions[] = {
    ZEND_FE(msgpack_serialize, arginfo_msgpack_serialize)
    ZEND_FE(msgpack_unserialize, arginfo_msgpack_unserialize)
    ZEND_FALIAS(msgpack_pack, msgpack_serialize, arginfo_msgpack_serialize)
    ZEND_FALIAS(msgpack_unpack, msgpack_unserialize, arginfo_msgpack_unserialize)
    {NULL, NULL, NULL}
};

MessagePack::packmsgpack_serialize的对象形式。它还会调用php_msgpack_serialize

static ZEND_METHOD(msgpack, pack)
{
    zval *parameter;
    smart_str buf = {0};
    int php_only = MSGPACK_G(php_only);
    MSGPACK_BASE_OBJECT;

    if (zend_parse_parameters(
            ZEND_NUM_ARGS() TSRMLS_CC, "z", &parameter) == FAILURE)
    {
        return;
    }

    MSGPACK_G(php_only) = base->php_only;

    php_msgpack_serialize(&buf, parameter TSRMLS_CC);

    MSGPACK_G(php_only) = php_only;

    ZVAL_STRINGL(return_value, buf.c, buf.len, 1);

    smart_str_free(&buf);
}