Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Jan 7, 2022
1 parent 7dbd4bb commit 946115f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 45 deletions.
18 changes: 3 additions & 15 deletions src/Cron/Protocol/Frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ class Frame
{
/**
* Check the integrity of the package.
*
* @param string $buffer
*
* @return int
*/
public static function input($buffer, TcpConnection $connection)
public static function input(string $buffer, TcpConnection $connection): int
{
if (\strlen($buffer) < 4)
{
Expand All @@ -31,24 +27,16 @@ public static function input($buffer, TcpConnection $connection)

/**
* Decode.
*
* @param string $buffer
*
* @return string
*/
public static function decode($buffer)
public static function decode(string $buffer): string
{
return substr($buffer, 4);
}

/**
* Encode.
*
* @param string $buffer
*
* @return string
*/
public static function encode($buffer)
public static function encode(string $buffer): string
{
return pack('N', \strlen($buffer)) . $buffer;
}
Expand Down
18 changes: 3 additions & 15 deletions src/Server/Protocol/FrameWithLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ class FrameWithLength
{
/**
* Check the integrity of the package.
*
* @param string $buffer
*
* @return int
*/
public static function input($buffer, TcpConnection $connection)
public static function input(string $buffer, TcpConnection $connection): int
{
if (\strlen($buffer) < 4)
{
Expand All @@ -31,24 +27,16 @@ public static function input($buffer, TcpConnection $connection)

/**
* Decode.
*
* @param string $buffer
*
* @return string
*/
public static function decode($buffer)
public static function decode(string $buffer): string
{
return $buffer;
}

/**
* Encode.
*
* @param string $buffer
*
* @return string
*/
public static function encode($buffer)
public static function encode(string $buffer): string
{
$total_length = \strlen($buffer);

Expand Down
18 changes: 3 additions & 15 deletions src/Server/Protocol/TextCRLF.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ class TextCRLF
{
/**
* Check the integrity of the package.
*
* @param string $buffer
*
* @return int
*/
public static function input($buffer, ConnectionInterface $connection)
public static function input(string $buffer, ConnectionInterface $connection): int
{
// Judge whether the package length exceeds the limit.
if (isset($connection->maxPackageSize) && \strlen($buffer) >= $connection->maxPackageSize)
Expand All @@ -40,25 +36,17 @@ public static function input($buffer, ConnectionInterface $connection)

/**
* Encode.
*
* @param string $buffer
*
* @return string
*/
public static function encode($buffer)
public static function encode(string $buffer): string
{
// Add "\r\n"
return $buffer . "\r\n";
}

/**
* Decode.
*
* @param string $buffer
*
* @return string
*/
public static function decode($buffer)
public static function decode(string $buffer): string
{
// Remove "\r\n"
return rtrim($buffer, "\r\n");
Expand Down

0 comments on commit 946115f

Please sign in to comment.