almost there, timespan needs to stop after days
This commit is contained in:
parent
111b74b20b
commit
b1a6a4d047
4 changed files with 15 additions and 51 deletions
|
@ -9,7 +9,7 @@ use DateTimeZone;
|
|||
use InvalidArgumentException;
|
||||
|
||||
class FWIF {
|
||||
public const CONTENT_TYPE = 'text/plain; charset=us-ascii'; // TODO: come up with a mime type
|
||||
public const CONTENT_TYPE = 'application/x.fwif';
|
||||
|
||||
public const DEFAULT = 0; // Default behaviour
|
||||
public const DISCARD_MILLISECONDS = 0x01; // Always exclude the millisecond component from DateTime
|
||||
|
@ -148,7 +148,7 @@ class FWIF {
|
|||
return $packed;
|
||||
}
|
||||
private static function decodeInteger($data, int $flags): int {
|
||||
$number = 0; $shift = 0; $o = 0; $size = PHP_INT_SIZE * 8;
|
||||
$number = 0; $shift = 0; $size = PHP_INT_SIZE * 8;
|
||||
do {
|
||||
$byte = ord(fgetc($data));
|
||||
$number |= ($byte & 0x7F) << $shift;
|
||||
|
@ -475,6 +475,9 @@ class FWIF {
|
|||
if($wsmh & self::TIMESPAN_FLAG_DMY) {
|
||||
$dmy = unpack('n', fread($data, 2))[1];
|
||||
$di->d = ($dmy >> self::TIMESPAN_DAYS_SHIFT) & self::DATETIME_DAY_MASK;
|
||||
|
||||
// OOPS! THESE WILL BE HORRIBLY INACCURATE!
|
||||
// Perhaps go back to the drawing board and tack months and years onto days?
|
||||
$di->m = ($dmy >> self::TIMESPAN_MONTH_SHIFT) & self::DATETIME_MONTH_MASK;
|
||||
if($wsmh & self::TIMESPAN_FLAG_YEAR)
|
||||
$di->y = ord(fgetc($data))
|
||||
|
|
|
@ -12,33 +12,7 @@ header('Content-Type: ' . FWIF::CONTENT_TYPE);
|
|||
if($request->match('GET', '/packages')) {
|
||||
$tags = explode(';', (string)$request->getQueryParam('tags', FILTER_SANITIZE_STRING));
|
||||
$packages = empty($tags) ? Patchouli::getPackages() : Patchouli::getPackagesWithTags($tags);
|
||||
|
||||
$encoded = FWIF::encode($packages);
|
||||
echo 'FWIF ' . strlen($encoded) . ' bytes ' . $encoded;
|
||||
|
||||
echo "\r\n\r\n--------------------\r\n\r\n";
|
||||
|
||||
$jsonEncoded = json_encode($packages, JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
echo 'JSON ' . strlen($jsonEncoded) . ' bytes ' . $jsonEncoded;
|
||||
echo "\r\n\r\n--------------------\r\n\r\n";
|
||||
|
||||
$hexdump = bin2hex($encoded); $hexdumpSect = 8; $hexdumpSize = 32;
|
||||
for($i = 0; $i < strlen($hexdump) / $hexdumpSize; ++$i) {
|
||||
$line = substr($hexdump, $i * $hexdumpSize, $hexdumpSize);
|
||||
echo str_pad(dechex($i * $hexdumpSize), 4, '0', STR_PAD_LEFT) . ' ';
|
||||
for($j = 0; $j < strlen($line) / $hexdumpSect; ++$j)
|
||||
echo substr($line, $j * $hexdumpSect, $hexdumpSect) . ' ';
|
||||
echo "\r\n";
|
||||
}
|
||||
|
||||
echo "\r\n--------------------\r\n\r\n";
|
||||
|
||||
var_dump([(object)$packages[0]->fwifSerialize()]);
|
||||
|
||||
echo "\r\n--------------------\r\n\r\n";
|
||||
|
||||
$decoded = FWIF::decode($encoded);
|
||||
var_dump($decoded);
|
||||
echo FWIF::encode($packages);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Patchouli\Dummy;
|
|||
use Patchouli\IPackage;
|
||||
use Patchouli\Version;
|
||||
|
||||
class DummyPackage implements IPackage, \JsonSerializable {
|
||||
class DummyPackage implements IPackage {
|
||||
public function getId(): string {
|
||||
return 'package-id';
|
||||
}
|
||||
|
@ -23,6 +23,10 @@ class DummyPackage implements IPackage, \JsonSerializable {
|
|||
|
||||
public function fwifSerialize(): array {
|
||||
$data = [
|
||||
'id' => $this->getId(),
|
||||
'name' => $this->getName(),
|
||||
'version' => $this->getVersion(),
|
||||
'deps' => [],
|
||||
'null' => null,
|
||||
'zero' => 0,
|
||||
'u8' => 0x42,
|
||||
|
@ -55,9 +59,9 @@ class DummyPackage implements IPackage, \JsonSerializable {
|
|||
'floatSqrt12' => M_SQRT1_2,
|
||||
'floatLnPi' => M_LNPI,
|
||||
'floatEuler' => M_EULER,
|
||||
//'floatNaN' => NAN,
|
||||
//'floatInf' => INF,
|
||||
//'floatNegInf' => -INF,
|
||||
'floatNaN' => NAN,
|
||||
'floatInf' => INF,
|
||||
'floatNegInf' => -INF,
|
||||
'floatZero' => 0.0,
|
||||
'floatNegZero' => -0.0,
|
||||
'invalid' => "\xFF\x25\x25\x02\xFF蠕。蝮F鄒守清\xFF\xFF\xFF",
|
||||
|
@ -70,21 +74,9 @@ class DummyPackage implements IPackage, \JsonSerializable {
|
|||
'array' => ['e', 'a', 0x55],
|
||||
'object' => new \stdClass,
|
||||
'misaka' => '御坂 美琴',
|
||||
'id' => $this->getId(),
|
||||
'name' => $this->getName(),
|
||||
'version' => $this->getVersion(),
|
||||
'deps' => [],
|
||||
];
|
||||
foreach($this->getDependencies() as $dependency)
|
||||
$data['deps'][] = $dependency->getName();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
$serial = $this->fwifSerialize();
|
||||
$serial['datetime'] = $serial['datetime']->format(\DateTimeInterface::ATOM);
|
||||
$serial['datetimeNegative'] = $serial['datetimeNegative']->format(\DateTimeInterface::ATOM);
|
||||
$serial['datetimeNow'] = $serial['datetimeNow']->format(\DateTimeInterface::ATOM);
|
||||
return $serial;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,12 @@
|
|||
namespace Patchouli;
|
||||
|
||||
use FWIF\FWIFSerializable;
|
||||
use JsonSerializable;
|
||||
|
||||
class Version implements FWIFSerializable, JsonSerializable {
|
||||
class Version implements FWIFSerializable {
|
||||
public function fwifSerialize(): string {
|
||||
return (string)$this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): string {
|
||||
return (string)$this;
|
||||
}
|
||||
|
||||
public function __toString(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
|
Reference in a new issue