| @@ 110-135 (lines=26) @@ | ||
| 107 | public function sendFrame($data, $type = null, $cb = null) { |
|
| 108 | // Binary |
|
| 109 | $type = $this->getFrameType($type); |
|
| 110 | if (($type & self::BINARY) === self::BINARY) { |
|
| 111 | $n = strlen($data); |
|
| 112 | $len = ''; |
|
| 113 | $pos = 0; |
|
| 114 | ||
| 115 | char: |
|
| 116 | ||
| 117 | ++$pos; |
|
| 118 | $c = $n >> 0 & 0x7F; |
|
| 119 | $n >>= 7; |
|
| 120 | ||
| 121 | if ($pos !== 1) { |
|
| 122 | $c += 0x80; |
|
| 123 | } |
|
| 124 | ||
| 125 | if ($c !== 0x80) { |
|
| 126 | $len = chr($c) . $len; |
|
| 127 | goto char; |
|
| 128 | }; |
|
| 129 | ||
| 130 | $this->write(chr(self::BINARY) . $len . $data); |
|
| 131 | } |
|
| 132 | // String |
|
| 133 | else { |
|
| 134 | $this->write(chr(self::STRING) . $data . "\xFF"); |
|
| 135 | } |
|
| 136 | if ($cb !== null) { |
|
| 137 | $this->onWriteOnce($cb); |
|
| 138 | } |
|
| @@ 91-116 (lines=26) @@ | ||
| 88 | ||
| 89 | // Binary |
|
| 90 | $type = $this->getFrameType($type); |
|
| 91 | if (($type & self::BINARY) === self::BINARY) { |
|
| 92 | $n = strlen($data); |
|
| 93 | $len = ''; |
|
| 94 | $pos = 0; |
|
| 95 | ||
| 96 | char: |
|
| 97 | ||
| 98 | ++$pos; |
|
| 99 | $c = $n >> 0 & 0x7F; |
|
| 100 | $n >>= 7; |
|
| 101 | ||
| 102 | if ($pos !== 1) { |
|
| 103 | $c += 0x80; |
|
| 104 | } |
|
| 105 | ||
| 106 | if ($c !== 0x80) { |
|
| 107 | $len = chr($c) . $len; |
|
| 108 | goto char; |
|
| 109 | }; |
|
| 110 | ||
| 111 | $this->write(chr(self::BINARY) . $len . $data); |
|
| 112 | } |
|
| 113 | // String |
|
| 114 | else { |
|
| 115 | $this->write(chr(self::STRING) . $data . "\xFF"); |
|
| 116 | } |
|
| 117 | if ($cb !== null) { |
|
| 118 | $this->onWriteOnce($cb); |
|
| 119 | } |
|