예제 #1
0
파일: Message.php 프로젝트: clue/icmp-react
 public function getMessagePacket()
 {
     $io = new StringWriter();
     $io->writeInt8($this->type);
     $io->writeInt8($this->code);
     $io->writeInt16BE($this->checksum);
     $io->writeInt32BE($this->header);
     return $io->toString() . $this->payload;
 }
예제 #2
0
 public function desiccate(Tree $tree)
 {
     $writer = new StringWriter();
     foreach ($tree->getNodes() as $node) {
         $writer->writeString8($node->getOctalModeString());
         $writer->writeString8(' ');
         $writer->writeString8($node->getName());
         $writer->writeString8("");
         $sha = $node->getRelatedObject()->getSha();
         if (strlen($sha) != 40) {
             throw new NotPersistedException("Object referred to by node named " . $node->getName() . " is not persisted yet.");
         }
         $writer->writeHHex($sha);
     }
     $data = $writer->toString();
     return new RawObject('tree', $data);
 }
예제 #3
0
 public function desiccate(Index $index)
 {
     $writer = new StringWriter();
     $entries = $index->getEntries();
     $writer->writeString8(Index::SIGNATURE);
     $writer->writeUInt32BE(Index::VERSION);
     $writer->writeUInt32BE(count($entries));
     $contents_offset = $writer->getOffset();
     usort($entries, function ($a, $b) {
         $cmp = strcmp($a->getName(), $b->getName());
         if ($cmp == 0) {
             return ($a->getStage() - $b->getStage());
         }
         return $cmp;
     });
     foreach ($entries as $entry) {
         $start = $writer->getOffset();
         $this->writeEntryTime($writer, $entry->getCtime());
         $this->writeEntryTime($writer, $entry->getMtime());
         $writer->writeUInt32BE($entry->getDev());
         $writer->writeUInt32BE($entry->getInode());
         $writer->writeUInt32BE($entry->getMode());
         $writer->writeUInt32BE($entry->getUid());
         $writer->writeUInt32BE($entry->getGid());
         $writer->writeUInt32BE($entry->getFileSize());
         $writer->writeHHex($entry->getBlob()->getSha());
         //FIXME: Stage
         $writer->writeUInt16BE(strlen($entry->getName()));
         $stop = $writer->getOffset();
         $length = $stop - $start + strlen($entry->getName()) + 1;
         //We need at least 1 NUL
         $padded_length = ceil($length / 8) * 8;
         $rest_length = $padded_length - $length;
         $writer->writeString8($entry->getName(), strlen($entry->getName()) + 1 + $rest_length);
     }
     $writer->writeHHex(sha1($writer->toString()));
     return $writer->toString();
 }