Total Complexity | 4 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | class InventorySerializer |
||
14 | 15 | { |
|
15 | /** |
||
16 | 15 | * @var \BitWasp\Buffertools\Types\Uint32 |
|
17 | 15 | */ |
|
18 | 15 | private $uint32le; |
|
19 | 15 | ||
20 | /** |
||
21 | * @var \BitWasp\Buffertools\Types\ByteString |
||
22 | */ |
||
23 | private $bytestring32le; |
||
24 | |||
25 | public function __construct() |
||
29 | 15 | } |
|
30 | 15 | ||
31 | 10 | /** |
|
32 | * @param Inventory $inv |
||
33 | * @return BufferInterface |
||
34 | */ |
||
35 | public function serialize(Inventory $inv): BufferInterface |
||
36 | { |
||
37 | $flags = $this->uint32le->write($inv->getType()); |
||
38 | 12 | $hash = $this->bytestring32le->write($inv->getHash()); |
|
39 | return new Buffer("{$flags}{$hash}"); |
||
40 | 12 | } |
|
41 | 12 | ||
42 | 8 | /** |
|
43 | * @param Parser $parser |
||
44 | 8 | * @return Inventory |
|
45 | */ |
||
46 | public function fromParser(Parser $parser): Inventory |
||
47 | { |
||
48 | $type = (int) $this->uint32le->read($parser); |
||
49 | $hash = $this->bytestring32le->read($parser); |
||
50 | return new Inventory($type, $hash); |
||
51 | 3 | } |
|
52 | |||
53 | 3 | /** |
|
54 | * @param BufferInterface $data |
||
55 | * @return Inventory |
||
56 | */ |
||
57 | public function parse(BufferInterface $data): Inventory |
||
60 | } |
||
61 | } |
||
62 |