length() public method

Return current length of the buffer.
public length ( ) : integer
return integer
Beispiel #1
0
 public function testIteration()
 {
     $result = null;
     for ($i = 0, $this->iterator->rewind(); $this->iterator->valid(); ++$i, $this->iterator->next()) {
         if ($i !== $this->iterator->key()) {
             $this->fail('Got invalid key from iterator.');
         }
         $result .= $this->iterator->current();
     }
     $this->assertSame($this->initialString, $result);
     $this->iterator->prev();
     $this->assertTrue($this->iterator->valid());
     $this->assertSame($this->buffer->length() - 1, $this->iterator->key());
 }
 /**
  * @override
  * @inheritDoc
  */
 public function write($text)
 {
     if (!$this->writable) {
         return $this->throwAndEmitException(new WriteException('Stream is no longer writable.'));
     }
     $this->buffer->push($text);
     if (!$this->listening && !$this->paused) {
         $this->listening = true;
         $this->loop->addWriteStream($this->resource, [$this, 'handleWrite']);
     }
     return $this->buffer->length() < $this->bufferSize;
 }
Beispiel #3
0
 /**
  * @override
  * @inheritDoc
  */
 public function readResponse(BufferInterface $buffer, $data)
 {
     $buffer->push($data);
     if (($position = $buffer->search(self::HTTP_EOM)) === false) {
         if ($buffer->length() > $this->maxFrameSize) {
             throw new ReadException(sprintf('Message start line exceeded maximum size of %d bytes.', $this->maxFrameSize));
         }
         return null;
     }
     try {
         return $this->parser->parseResponse($buffer->drain());
     } catch (Error $ex) {
     } catch (Exception $ex) {
     }
     throw new InvalidFormatException('Could not parse start line.');
 }
Beispiel #4
0
 public function testApiLength_ReturnsLengthOfData()
 {
     $this->assertSame(strlen($this->initialString), $this->buffer->length());
 }
 public function testApiSeek()
 {
     $this->iterator->seek($this->buffer->length() - 1);
     $this->assertSame($this->buffer->length() - 1, $this->iterator->key());
     $this->assertSame(substr($this->buffer, -1), $this->iterator->current());
 }