* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Registerable {
+class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registerable {
/**
* Cached chunk size in bits
*/
return $hash;
}
- /**
- * "Getter" for the next hexadecimal-encoded serial number
- *
- * @return $encodedSerialNumber The next hexadecimal-encoded serial number
- */
- private function getNextHexSerialNumber () {
- // Assert on maximum serial number length
- assert($this->serialNumber <= $this->maxSerialNumber);
-
- // Encode the current serial number
- $encodedSerialNumber = $this->dec2Hex($this->serialNumber, self::MAX_SERIAL_LENGTH);
-
- // Count one up
- $this->serialNumber++;
-
- // Return the encoded serial number
- return $encodedSerialNumber;
- }
-
/**
* Appends an end-of-package chunk to the chunk list for given chunk and
* final hash. As of 23-March-2012 the format of this chunk will be as any
* regular one to keep things easy (KISS) in ChunkHandler class.
*
- * @param $chunkHash Last chunk's hash
+ * @param $lastChunk Last chunk raw data
* @param $finalHash Final hash for raw (unencoded) data
* @return void
*/
- private function appendEndOfPackageChunk ($chunkHash, $finalHash) {
+ private function appendEndOfPackageChunk ($lastChunk, $finalHash) {
// Generate end-of-package marker
$chunkData =
self::END_OF_PACKAGE_IDENTIFIER .
$finalHash . self::CHUNK_HASH_SEPARATOR .
- $chunkHash;
+ $this->generateHashFromRawData($lastChunk);
// Add it as regular chunk
$this->addChunkData($finalHash, $chunkData);
// Init variables
$chunkHash = '';
+ $chunkData = '';
// Now split it up
for ($idx = 0; $idx < strlen($rawData); $idx += $dataChunkSize) {
//* NOISY-DEBUG: */ $this->debugOutput('FRAGMENTER: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).');
// Add end-of-package chunk
- $this->appendEndOfPackageChunk($chunkHash, $finalHash);
+ $this->appendEndOfPackageChunk($chunkData, $finalHash);
}
/**
} // END - for
}
+ /**
+ * "Getter" for the next hexadecimal-encoded serial number
+ *
+ * @return $encodedSerialNumber The next hexadecimal-encoded serial number
+ */
+ public function getNextHexSerialNumber () {
+ // Assert on maximum serial number length
+ assert($this->serialNumber <= $this->maxSerialNumber);
+
+ // Encode the current serial number
+ $encodedSerialNumber = $this->dec2Hex($this->serialNumber, self::MAX_SERIAL_LENGTH);
+
+ // Count one up
+ $this->serialNumber++;
+
+ // Return the encoded serial number
+ return $encodedSerialNumber;
+ }
+
/**
* This method does "implode" the given package data array into one long
* string, splits it into small chunks, adds a serial number and checksum
// Return the chunk array
return $rawDataChunk;
}
+
+ /**
+ * Resets the serial number to zero
+ *
+ * @return void
+ */
+ public function resetSerialNumber () {
+ $this->serialNumber = 0;
+ }
}
// [EOF]