Fixing msgpack custom

This commit is contained in:
Pavel Shevaev 2022-05-16 17:52:12 +03:00
parent a5bd34e385
commit d3f562cfa2
2 changed files with 25 additions and 2 deletions

View File

@ -897,9 +897,9 @@ else
{ {
function config_msgpack_pack($data) function config_msgpack_pack($data)
{ {
include_once(__DIR__ . '/../utils/msgpack_custom.inc.php'); include_once(__DIR__ . '/msgpack_custom.inc.php');
$packer = new MessagePackCustom(); $packer = new \MessagePackCustom();
return $packer->pack($data); return $packer->pack($data);
} }

23
msgpack_custom.inc.php Normal file
View File

@ -0,0 +1,23 @@
<?php
class MessagePackCustom extends MessagePack\Packer
{
public function __construct()
{
parent::__construct(MessagePack\PackOptions::FORCE_STR);
}
public function packStr($str)
{
$length = \strlen($str);
if ($length < 32) {
return \chr(0xa0 | $length).$str;
}
if ($length <= 0xffff) {
return "\xda".\chr($length >> 8).\chr($length).$str;
}
return \pack('CN', 0xdb, $length).$str;
}
}