Skip to content

Commit

Permalink
build package
Browse files Browse the repository at this point in the history
  • Loading branch information
itfehrim committed Nov 5, 2018
0 parents commit 45ba224
Show file tree
Hide file tree
Showing 9 changed files with 1,338 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Created by .ignore support plugin (hsz.mobi)

.idea/
53 changes: 53 additions & 0 deletions Frame/Services/Protocols/Frame.php
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;
}
}
Loading

0 comments on commit 45ba224

Please sign in to comment.