1
0
mirror of https://github.com/danog/PHPStruct.git synced 2024-11-30 04:19:08 +01:00

Updated tests and p format.

This commit is contained in:
danogentili 2016-07-12 22:14:09 +02:00
parent c0bdd39430
commit 43cd56d019
3 changed files with 4 additions and 4 deletions

View File

@ -7,7 +7,7 @@ require('lib/danog/PHP/Struct.php');
var_dump(\danog\PHP\Struct::unpack("2cxbxBx?xhxHxixIxlxLxqxQxnxNxfxdx2sx5pP",
\danog\PHP\Struct::pack("2cxbxBx?xhxHxixIxlxLxqxQxnxNxfxdx2sx5pP",
"n", "v", 100, 100, false, 333, 444, 232423, 234342, 234234234234, 234234234234, 234234234234, 234234234234, 34434, 344434, 2.2343,
3.03424, "df", "asdf", 1283912
3.03424, "df", "asdfghjkl", 1283912
)
));

View File

@ -191,7 +191,7 @@ class Struct {
break;
case 'p':
$tempstring = pack("a" . ($command["count"]-1), $data[$command["datakey"]]);
$curresult = pack("v", strlen($tempstring))[0] . $tempstring;
$curresult = pack("v", ($command["count"]-1 > 255) ? 255 : $command["count"]-1)[0] . $tempstring;
break;
default:
$curresult = pack($command["phpformat"].$command["count"], $data[$command["datakey"]]); // Pack current char
@ -255,7 +255,8 @@ class Struct {
try {
switch ($command["format"]){
case 'p':
$result[$arraycount] = join('', unpack("a".($command["count"]-1), substr($dataarray[$command["datakey"]], 1)));
$templength = unpack("s", $dataarray[$command["datakey"]][0] . pack("x"))[1];
$result[$arraycount] = join('', unpack("a".$templength, substr($dataarray[$command["datakey"]], 1)));
break;
case '?':
if (join('', unpack($command["phpformat"].$command["count"], $dataarray[$command["datakey"]])) == 0) $result[$arraycount] = false; else $result[$arraycount] = true;
@ -264,7 +265,6 @@ class Struct {
$result[$arraycount] = join('', unpack($command["phpformat"].$command["count"], $dataarray[$command["datakey"]])); // Unpack current char
break;
}
} catch(StructException $e) {
throw new StructException("An error occurred while unpacking data at offset " . $key . " (" . $e->getMessage() . ").");
}

Binary file not shown.