示例#1
0
 /**
  * Padding size should resize the packet size to the 8 bytes boundary for optimal performance
  */
 public function testAutomaticCalculationOfPaddingLength()
 {
     $record = new Record();
     $record->setContentData('12345');
     $this->assertEquals($record->getPaddingLength(), 3);
     $record->setContentData('12345678');
     $this->assertEquals($record->getPaddingLength(), 0);
 }
示例#2
0
 /**
  * Method to unpack the payload for the record
  *
  * @param Record|Params $self Instance of current frame
  * @param string $data Binary data
  *
  * @return Record
  */
 protected static function unpackPayload(Record $self, $data)
 {
     $currentOffset = 0;
     do {
         list($nameLengthHigh) = array_values(unpack('CnameLengthHigh', $data));
         $isLongName = $nameLengthHigh >> 7 == 1;
         $valueOffset = $isLongName ? 4 : 1;
         list($valueLengthHigh) = array_values(unpack('CvalueLengthHigh', substr($data, $valueOffset)));
         $isLongValue = $valueLengthHigh >> 7 == 1;
         $dataOffset = $valueOffset + ($isLongValue ? 4 : 1);
         $formatParts = array($isLongName ? 'NnameLength' : 'CnameLength', $isLongValue ? 'NvalueLength' : 'CvalueLength');
         $format = join('/', $formatParts);
         list($nameLength, $valueLength) = array_values(unpack($format, $data));
         // Clear top bit for long record
         $nameLength &= $isLongName ? 0x7fffffff : 0x7f;
         $valueLength &= $isLongValue ? 0x7fffffff : 0x7f;
         list($nameData, $valueData) = array_values(unpack("a{$nameLength}nameData/a{$valueLength}valueData", substr($data, $dataOffset)));
         $self->values[$nameData] = $valueData;
         $keyValueLength = $dataOffset + $nameLength + $valueLength;
         $data = substr($data, $keyValueLength);
         $currentOffset += $keyValueLength;
     } while ($currentOffset < $self->getContentLength());
     return $self;
 }