/** * {@inheritdoc} */ public function read(StreamInterface $stream, DataSet $result) { $result->push($this->name); // Read the bytes into memory $byte = $stream->readByte(); $bitPosition = 0; // Get the structure $structure = $this->structure->get(); foreach ($structure as $bitFieldName => $bitFieldSize) { $value = ord($byte) >> $bitPosition & bindec(str_repeat('1', $bitFieldSize)); $result->setValue($bitFieldName, $value); $bitPosition += $bitFieldSize; } $result->pop(); }
/** * {@inheritdoc} */ public function read(StreamInterface $stream, DataSet $result) { // Get the delimiter to search for $delimiter = $this->delimiter->get($result); $delimiterLength = strlen($delimiter); $value = ''; while (false !== ($byte = $stream->readByte())) { $value .= $byte; // Does the string now end with the requested delimiter? if (substr($value, strlen($value) - $delimiterLength, $delimiterLength) === $delimiter) { break; } // Reached the limit of the lookahead? if (strlen($value) > $this->searchLength->get($result)) { break; } } // Strip the delimiter and add the read content to the result DataSet $value = substr($value, 0, strlen($value) - $delimiterLength); // Validate and return $this->validate($value); $result->setValue($this->name, $value); }