예제 #1
0
 /**
  * {@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));
     }
 }
예제 #2
0
 /**
  * {@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();
 }
예제 #3
0
 /**
  * Write $this->size NUL bytes to $stream.
  *
  * {@inheritdoc}
  */
 public function write(StreamInterface $stream, DataSet $result)
 {
     $stream->write(pack('x' . $this->size->get($result)));
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function write(StreamInterface $stream, DataSet $result)
 {
     //Writing floats currently untested
     $bytes = $result->getValue($this->name);
     $stream->write(pack('f', intval($bytes)));
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function write(StreamInterface $stream, DataSet $result)
 {
     $bytes = substr($result->getValue($this->getName()), 0, $this->size->get($result));
     $stream->write($bytes);
 }
예제 #6
0
 /**
  * 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));
 }