private function timesMap($n, $type) { $data = array(); for ($i = 0; $i < $n; $i++) { $value = null; if ($type === 'uint32LE') { $value = $this->buffer->getUint32LE(); } else { if ($type === 'uint16LE') { $value = $this->buffer->getUint16LE(); } else { if ($type === 'float32') { $value = $this->buffer->getFloat32(); } else { if ($type === 'matrix33') { $value = $this->buffer->getMatrix33(); } else { if ($type === 'vector31') { $value = $this->buffer->getVector31(); } else { if ($type === 'uint8') { $value = $this->buffer->getUint8(); } } } } } } array_push($data, $value); } }
public function getFrameOptions() { $isChecksum = false; while (!$isChecksum) { $idOption = hexdec($this->buffer->getUint16LE()); $nameOption = Option::$optionIds[$idOption]; $sizeOption = $this->buffer->getUint16LE(); if ($nameOption === 'checksum') { $isChecksum = true; $expectedChecksum = 0; $checksum = $this->buffer->getUint32LE(); $data = $this->buffer->getData(); for ($i = 0; $i < $this->buffer->getLength() - $sizeOption; ++$i) { $expectedChecksum = $expectedChecksum + hexdec(bin2hex($data[$i])); } $expectedChecksum = dechex($expectedChecksum); if ($checksum !== $expectedChecksum) { throw new \Exception('Invalid checksum'); } } $option = new Option($idOption, $this->buffer); $this->options[$option->getName()] = $option; } }