Пример #1
0
 public function testParse()
 {
     $collection = new Collection(['a' => ['int', 'byte', ['assert' => 49]], 'b' => ['conditional', '/a', [0 => ['int', 8], 49 => ['conditional', '/a', [49 => ['string', 6]]]], ['default' => [['int', 8], ['int', 8]]]], 'c' => ['collection', ['d' => ['int', 8, ['signed' => true]], 'd2' => ['int', 8, ['signed' => true]]], ['assert' => ['d' => 76, 'd2' => 76]]], 'e' => ['arr', 16, ['string', 80]], 'f' => ['arr', function (Arr $arrayField) {
         $value = $arrayField->getDataSet()->getValueByPath('/a') - 45;
         return $value;
     }, ['fa' => ['arr', 5, ['field' => ['string', 16]]], 'fc' => ['qwe1' => ['int', 8], 'qwe2' => ['int', 8], 'qwe3' => [['string', 16], ['string', 16]]], 'fb' => ['string', 16, ['assert' => function ($readString) {
         return $readString === 'LL';
     }]]]]]);
     $stream = new StringStream(str_pad('', 1000, '1'));
     $dataSet = $collection->parse($stream);
     $this->assertInternalType('int', $dataSet['a']);
     $this->assertInternalType('string', $dataSet['b']);
     $this->assertCount(16, $dataSet['e']);
     $this->assertCount(4, $dataSet['f']);
     $this->assertCount(5, $dataSet['f'][2]['fa']);
     $this->assertCount(3, $dataSet['f'][3]['fc']);
     $this->assertCount(2, $dataSet['f'][3]['fc']['qwe3']);
     $this->assertEquals(2, strlen($dataSet['f'][3]['fc']['qwe3'][1]));
 }
Пример #2
0
 /**
  * Call parse method on arrayed field needed times.
  *
  * @api
  * @param AbstractStream $stream Stream from which children read.
  * @return array Array of parsed values.
  * @since 1.0
  */
 public function parse(AbstractStream $stream)
 {
     try {
         return parent::parse($stream);
     } catch (\OutOfBoundsException $e) {
         if ($this->isUntilEof()) {
             return $this->dataSet->getData();
         }
         throw $e;
     }
 }