feat: 实现TCP Server
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace app\Exceptions;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* 不支持的报文异常:当报文没有匹配到任何解析器时抛出
|
||||
*/
|
||||
class UnsupportedPacketException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* 构造函数(可选:添加自定义上下文)
|
||||
* @param string $message 异常消息
|
||||
* @param int $code 异常码
|
||||
* @param \Throwable|null $previous 前一个异常
|
||||
*/
|
||||
public function __construct(
|
||||
string $message = 'Unsupported packet type: no parser matched',
|
||||
int $code = 400,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
// 可选:添加获取报文相关信息的方法,方便调试
|
||||
public static function fromHexString(string $hexString): self
|
||||
{
|
||||
$len = strlen($hexString);
|
||||
return new self(
|
||||
sprintf('Unsupported packet (hex length: %d, hex string: %s)', $len, $hexString),
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user