mxmbsocket/lib/Ratchet/Application/WebSocket/Version/Hixie76/Frame.php
Chris Boden 5653f01f2f Message buffering & Refactoring
Refactored unframe() methods into Message/Frame classes (per protocol version)
Change onRecv of WebSocket App to use new interfaces to test statuses, resulting in reuniting a message fragmented by TCP
Wrote unit test covering most of new HyBi10 Frame class
2011-11-18 16:37:32 -05:00

58 lines
1.4 KiB
PHP

<?php
namespace Ratchet\Application\WebSocket\Version\Hixie76;
use Ratchet\Application\WebSocket\Version\FrameInterface;
/**
* This does not entirely follow the protocol to spec, but (mostly) works
* Hixie76 probably should not even be supported
*/
class Frame implements FrameInterface {
/**
* @type string
*/
protected $_data = '';
public function __toString() {
return $this->getPayload();
}
public function isCoalesced() {
return (boolean)($this->_data[0] == chr(0) && substr($this->_data, -1) == chr(255));
}
public function addBuffer($buf) {
$this->_data .= (string)$buf;
}
public function isFinal() {
return true;
}
public function isMasked() {
return false;
}
public function getOpcode() {
return 1;
}
public function getPayloadLength() {
if (!$this->isCoalesced()) {
throw new \UnderflowException('Not enough of the message has been buffered to determine the length of the payload');
}
return strlen($this->_data) - 2;
}
public function getMaskingKey() {
return '';
}
public function getPayload() {
if (!$this->isCoalesced()) {
return new \UnderflowException('Not enough data buffered to read payload');
}
return substr($this->_data, 1, strlen($this->_data) - 2);
}
}