77use Closure ;
88use Workbunny \MysqlProtocol \Constants \ExceptionCode ;
99use Workbunny \MysqlProtocol \Exceptions \Exception ;
10+ use Workbunny \MysqlProtocol \Exceptions \InvalidArgumentException ;
1011use Workbunny \MysqlProtocol \Exceptions \PacketException ;
1112use Workbunny \MysqlProtocol \Packets \AuthMoreDataRequest ;
1213use Workbunny \MysqlProtocol \Packets \AuthSwitchRequest ;
@@ -21,7 +22,7 @@ class Packet
2122 /**
2223 * 新建符合Packet基础协议的binary对象
2324 *
24- * @param Closure $closure = function(Binary $binary) {}
25+ * @param Closure $closure = function(Binary $binary): void {}
2526 * @param int $packetId
2627 * @return Binary
2728 */
@@ -40,12 +41,12 @@ public static function binary(Closure $closure, int $packetId = 0): Binary
4041 /**
4142 * 快速解析包头和包体
4243 *
43- * @param Closure|null $closure
44+ * @param Closure|null $closure = function(Binary $binary): array {}
4445 * @param Binary $binary
45- * @param bool $reset
46- * @return array
46+ * @param bool $recover 是否恢复读指针
47+ * @return array{packet_length: int, packet_id: int, mixed ...$result}
4748 */
48- public static function parser (?Closure $ closure , Binary $ binary , bool $ reset = false ): array
49+ public static function parser (?Closure $ closure , Binary $ binary , bool $ recover = false ): array
4950 {
5051 $ readCursor = $ binary ->getReadCursor ();
5152 // 重置读指针
@@ -54,12 +55,12 @@ public static function parser(?Closure $closure, Binary $binary, bool $reset = f
5455 $ packetLength = $ binary ->readUB (Binary::UB3 );
5556 $ packetId = $ binary ->readByte ();
5657 // 恢复读指针到原位
57- if ($ reset ) {
58+ if ($ recover ) {
5859 $ binary ->setReadCursor ($ readCursor );
5960 }
6061 $ result = $ closure ? $ closure ($ binary ) : [];
6162 if (!is_array ($ result )) {
62- throw new PacketException ('Packet parser must return array ' , ExceptionCode::ERROR );
63+ throw new InvalidArgumentException ('Packet parser must return array ' , ExceptionCode::ERROR_TYPE );
6364 }
6465 return array_merge ([
6566 'packet_length ' => $ packetLength ,
0 commit comments