Browse Source

修改字节不够时候报错

master v0.3.5
blobt 4 years ago
parent
commit
28a544e17f
  1. 5
      examples/client.php
  2. 9
      src/Pack.php

5
examples/client.php

@ -46,7 +46,10 @@ function remoteCall(string $host, $port, string $data) {
}
$ret = remoteCall("127.0.0.1", "5188", '{"controller":"site","methor":"test","params":{"id":1,"status":0}}');
$ret = remoteCall("127.0.0.1", "5188", '{"controller":"site","methor":"test","params":{"id":1}}');
//'{"controller":"site","methor":"test","params":{"id":"111"}}
//'{"controller":"site","methor":"test","params":{"id":1,"status":0}}'
echo "{$ret}\n";
?>

9
src/Pack.php

@ -139,13 +139,14 @@ class Pack {
* @return string | boolean
*/
public function unpack(string $pack) {
try {
$ret = unpack($this->makeFormat(true), $pack);
if ($ret['type'] == self::DATA_TYPE_SAMPLE_DATA
&& $ret['length'] == strlen($ret['data'])
&& (int) $ret['length'] <= self::$packageMaxLength) {
if ($ret['type'] === self::DATA_TYPE_SAMPLE_DATA && $ret['length'] == strlen($ret['data']) && (int) $ret['length'] <= self::$packageMaxLength) {
return $ret;
}
} catch (\Exception $e) {
return false;
}
return false;
}

Loading…
Cancel
Save