SamsonGame/utils/msgpack_custom.inc.php

24 lines
466 B
PHP
Raw Permalink Normal View History

2021-12-29 20:50:11 +03:00
<?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;
}
}