Skip to content

Commit 082318c

Browse files
committed
Tweak examples
1 parent fce4ce6 commit 082318c

6 files changed

Lines changed: 15 additions & 29 deletions

File tree

examples/MessagePack/StructList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
final class StructList
1515
{
16+
/** @readonly */
1617
public $list;
1718

1819
public function __construct(array $list)

examples/MessagePack/Text.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
final class Text
1515
{
16+
/** @readonly */
1617
public $str;
1718

1819
public function __construct(string $str)

examples/MessagePack/Uint64.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111

1212
namespace App\MessagePack;
1313

14-
final class Uint64
14+
use MessagePack\Packer;
15+
use MessagePack\TypeTransformer\CanBePacked;
16+
17+
final class Uint64 implements CanBePacked
1518
{
19+
/** @readonly */
1620
public $value;
1721

1822
public function __construct(string $value)
@@ -24,4 +28,9 @@ public function __toString() : string
2428
{
2529
return $this->value;
2630
}
31+
32+
public function pack(Packer $packer) : string
33+
{
34+
return "\xcf".\gmp_export($this->value);
35+
}
2736
}

examples/MessagePack/Uint64Transformer.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

examples/uint64.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111

1212
use App\MessagePack\Uint64;
13-
use App\MessagePack\Uint64Transformer;
1413
use MessagePack\BufferUnpacker;
1514
use MessagePack\Packer;
1615
use MessagePack\UnpackOptions;
@@ -22,12 +21,12 @@
2221
exit(1);
2322
}
2423

25-
$packer = new Packer(null, [new Uint64Transformer()]);
24+
$packer = new Packer();
2625

2726
$uint64 = new Uint64('18446744073709551615');
2827
$packed = $packer->pack($uint64);
2928

30-
printf("Packed (%s): %s\n", $uint64, bin2hex($packed));
29+
printf("Packed (%s): %s\n", (string) $uint64, bin2hex($packed));
3130
printf("Unpacked: %s\n", (new BufferUnpacker($packed, UnpackOptions::BIGINT_AS_STR))->unpack());
3231

3332
/* OUTPUT

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
88
>
99
<projectFiles>
10+
<directory name="examples" />
1011
<directory name="src" />
1112
<ignoreFiles>
1213
<directory name="vendor" />

0 commit comments

Comments
 (0)