<?php



namespace MS\SerializerBundle\Serializer\Encoder;

class MsgpackEncoder extends AbstractEncoder
{
    const FORMAT = 'msgpack';

    /**
     * @return bool
     */
    public static function isInstalled()
    {
        return extension_loaded('msgpack');
    }

    /**
     * @param mixed  $data
     * @param string $format
     * @param array  $context
     *
     * @return string
     */
    public function encode($data, $format, array $context = array())
    {
        return msgpack_pack($data);
    }

    /**
     * @param string $data
     * @param string $format
     * @param array  $context
     *
     * @return mixed
     */
    public function decode($data, $format, array $context = array())
    {
        return msgpack_unpack($data);
    }
}
