/** * {@inheritdoc} */ public function write(StreamInterface $stream, DataSet $result) { $result->push($this->getName()); $count = isset($this->count) ? $this->count->get($result) : 1; // Read this compound field $count times for ($iteration = 0; $iteration < $count; $iteration++) { $result->push($iteration); foreach ($this->fields as $field) { $field->write($stream, $result); } $result->pop(); } $result->pop(); }
/** * {@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(); }