-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 45ba224
Showing
9 changed files
with
1,338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: fehrim | ||
* Date: 2018/11/1 | ||
* Time: 21:30 | ||
*/ | ||
|
||
namespace Frame\Services\Protocols; | ||
|
||
/** | ||
* Frame Protocol. | ||
*/ | ||
class Frame | ||
{ | ||
/** | ||
* Check the integrity of the package. | ||
* | ||
* @param string $buffer | ||
* @return int | ||
*/ | ||
public static function input($buffer) | ||
{ | ||
if (strlen($buffer) < 4) { | ||
return 0; | ||
} | ||
$unpack_data = unpack('N'.'total_length', $buffer); | ||
return $unpack_data['total_length']; | ||
} | ||
|
||
/** | ||
* Decode. | ||
* | ||
* @param string $buffer | ||
* @return string | ||
*/ | ||
public static function decode($buffer) | ||
{ | ||
return substr($buffer, 4); | ||
} | ||
|
||
/** | ||
* Encode. | ||
* | ||
* @param string $buffer | ||
* @return string | ||
*/ | ||
public static function encode($buffer) | ||
{ | ||
$total_length = 4 + strlen($buffer); | ||
return pack('N', $total_length) . $buffer; | ||
} | ||
} |
Oops, something went wrong.