/** * {@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)); } }
/** * {@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(); }
/** * Write $this->size NUL bytes to $stream. * * {@inheritdoc} */ public function write(StreamInterface $stream, DataSet $result) { $stream->write(pack('x' . $this->size->get($result))); }
/** * {@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)); }