ProtocolInterface.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * This file is part of workerman.
  4. *
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the MIT-LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @author walkor<walkor@workerman.net>
  10. * @copyright walkor<walkor@workerman.net>
  11. * @link http://www.workerman.net/
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Workerman\Protocols;
  15. use Workerman\Connection\ConnectionInterface;
  16. /**
  17. * Protocol interface
  18. */
  19. interface ProtocolInterface
  20. {
  21. /**
  22. * Check the integrity of the package.
  23. * Please return the length of package.
  24. * If length is unknow please return 0 that mean wating more data.
  25. * If the package has something wrong please return false the connection will be closed.
  26. *
  27. * @param ConnectionInterface $connection
  28. * @param string $recv_buffer
  29. * @return int|false
  30. */
  31. public static function input($recv_buffer, ConnectionInterface $connection);
  32. /**
  33. * Decode package and emit onMessage($message) callback, $message is the result that decode returned.
  34. *
  35. * @param ConnectionInterface $connection
  36. * @param string $recv_buffer
  37. * @return mixed
  38. */
  39. public static function decode($recv_buffer, ConnectionInterface $connection);
  40. /**
  41. * Encode package brefore sending to client.
  42. *
  43. * @param ConnectionInterface $connection
  44. * @param mixed $data
  45. * @return string
  46. */
  47. public static function encode($data, ConnectionInterface $connection);
  48. }