예제 #1
0
 /**
  * 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
 /**
  * @depends testEmptyConstruction
  */
 public function testDecodingReturn(Byte $byte)
 {
     $stream = '4:failure';
     $this->assertEquals('ure', $byte->decode($stream));
     return $byte;
 }