File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -42,15 +42,21 @@ public static function binary(Closure $closure, int $packetId = 0): Binary
4242 *
4343 * @param Closure|null $closure
4444 * @param Binary $binary
45+ * @param bool $reset
4546 * @return array
4647 */
47- public static function parser (?Closure $ closure , Binary $ binary ): array
48+ public static function parser (?Closure $ closure , Binary $ binary, bool $ reset = false ): array
4849 {
50+ $ readCursor = $ binary ->getReadCursor ();
4951 // 重置读指针
5052 $ binary ->setReadCursor (0 );
5153 // 包头
5254 $ packetLength = $ binary ->readUB (Binary::UB3 );
5355 $ packetId = $ binary ->readByte ();
56+ // 恢复读指针到原位
57+ if ($ reset ) {
58+ $ binary ->setReadCursor ($ readCursor );
59+ }
5460 $ result = $ closure ? $ closure ($ binary ) : [];
5561 if (!is_array ($ result )) {
5662 throw new PacketException ('Packet parser must return array ' , ExceptionCode::ERROR );
You can’t perform that action at this time.
0 commit comments