コード例 #1
0
ファイル: BList.php プロジェクト: dsmithhayes/bencode
 /**
  * Reads a raw stream and decodes the List encoded portion of it. This will
  * append data to the internal buffer.
  *
  * @param string A raw encoded stream of a Bencode List.
  * 
  * @throws BListException;
  */
 public function decode($stream)
 {
     $stream = $this->dropEncoding($stream, self::PATTERN);
     // This block determines which type of primitive element is in the list
     if ($stream[0] === 'i') {
         $element = new Integer();
     } elseif (is_numeric($stream[0])) {
         $element = new Byte();
     } else {
         throw new BListException('Decoded improper encoding: ' . $stream);
     }
     $stream = $element->decode($stream);
     $this->_buffer[] = $element->write();
     if (strlen($stream) > 0) {
         return $this->decode($stream);
     }
 }
コード例 #2
0
ファイル: ByteTestCase.php プロジェクト: dsmithhayes/bencode
 /**
  * @depends testEmptyConstruction
  */
 public function testStreamDecoding(Byte $byte)
 {
     $byte->decode('4:test');
     $this->assertEquals('test', $byte->write());
 }