/** * {@inheritdoc} */ public function write(StreamInterface $stream, DataSet $result) { $dataSize = 2; $bytes = $result->getValue($this->name); for ($i = 0; $i < $dataSize; $i++) { $unsignedByte = $bytes >> ($dataSize - (1 + $i)) * 8 & 0xff; $stream->write(pack('C', intval($unsignedByte) & 0xff)); } }
/** * Get the value of the property for the given DataSet. * * @param DataSet $result * @return mixed */ public function get(DataSet $result) { // If the path begins '/', it is absolute $absolute = isset($this->path[0]) && $this->path[0] === '/'; $pathParts = explode('/', $this->path); if ($absolute) { array_shift($pathParts); } return $result->getValueByPath($pathParts, $absolute); }
/** * {@inheritdoc} */ public function read(StreamInterface $stream, DataSet $result) { $data = $stream->read(4); if (strlen($data) < 2) { $data = str_pad($data, 2, "", STR_PAD_LEFT); } $unpacked = unpack('l', $data); $this->validate($unpacked[1]); $result->setValue($this->getName(), $unpacked[1]); }
/** * {@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(); }
/** * {@inheritdoc} */ public function write(StreamInterface $stream, DataSet $result) { //Writing floats currently untested $bytes = $result->getValue($this->name); $stream->write(pack('f', intval($bytes))); }
/** * {@inheritdoc} */ public function write(StreamInterface $stream, DataSet $result) { $bytes = substr($result->getValue($this->getName()), 0, $this->size->get($result)); $stream->write($bytes); }
/** * Write the value for this field, then the delimiter at the end. * * {@inheritdoc} */ public function write(StreamInterface $stream, DataSet $result) { $stream->write($result->getValue($this->getName())); $stream->write($this->delimiter->get($result)); }