Skip to content

Commit

Permalink
Tweak examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rybakit committed Jul 11, 2021
1 parent fce4ce6 commit 082318c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 29 deletions.
1 change: 1 addition & 0 deletions examples/MessagePack/StructList.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

final class StructList
{
/** @readonly */
public $list;

public function __construct(array $list)
Expand Down
1 change: 1 addition & 0 deletions examples/MessagePack/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

final class Text
{
/** @readonly */
public $str;

public function __construct(string $str)
Expand Down
11 changes: 10 additions & 1 deletion examples/MessagePack/Uint64.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

namespace App\MessagePack;

final class Uint64
use MessagePack\Packer;
use MessagePack\TypeTransformer\CanBePacked;

final class Uint64 implements CanBePacked
{
/** @readonly */
public $value;

public function __construct(string $value)
Expand All @@ -24,4 +28,9 @@ public function __toString() : string
{
return $this->value;
}

public function pack(Packer $packer) : string
{
return "\xcf".\gmp_export($this->value);
}
}
25 changes: 0 additions & 25 deletions examples/MessagePack/Uint64Transformer.php

This file was deleted.

5 changes: 2 additions & 3 deletions examples/uint64.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

use App\MessagePack\Uint64;
use App\MessagePack\Uint64Transformer;
use MessagePack\BufferUnpacker;
use MessagePack\Packer;
use MessagePack\UnpackOptions;
Expand All @@ -22,12 +21,12 @@
exit(1);
}

$packer = new Packer(null, [new Uint64Transformer()]);
$packer = new Packer();

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

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

/* OUTPUT
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="examples" />
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
Expand Down

0 comments on commit 082318c

Please sign in to comment.