Conditions | 2 |
Paths | 2 |
Total Lines | 25 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 18 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
17 | 8 | public function decodeFrameAddress(string $data, int $offset = 0): FrameAddress |
|
18 | { |
||
19 | 8 | if ((\strlen($data) - $offset) < FrameAddress::WIRE_SIZE) { |
|
20 | 2 | throw new InsufficientDataException( |
|
21 | 2 | "Frame address requires " . FrameAddress::WIRE_SIZE |
|
22 | 2 | . " bytes, got " . (\strlen($data) - $offset) . " bytes" |
|
23 | ); |
||
24 | } |
||
25 | |||
26 | [ |
||
27 | 6 | 'mac1' => $mac1, |
|
28 | 6 | 'mac2' => $mac2, |
|
29 | 6 | 'mac3' => $mac3, |
|
30 | 6 | 'mac4' => $mac4, |
|
31 | 6 | 'mac5' => $mac5, |
|
32 | 6 | 'mac6' => $mac6, |
|
33 | 6 | 'flags' => $flags, |
|
34 | 6 | 'sequence' => $sequence, |
|
35 | 6 | ] = \unpack('C8mac/C6reserved/Cflags/Csequence', $data, $offset); |
|
36 | |||
37 | 6 | $target = new MacAddress($mac1, $mac2, $mac3, $mac4, $mac5, $mac6); |
|
38 | 6 | $isAckRequired = (bool)($flags & 0x02); |
|
39 | 6 | $isResponseRequired = (bool)($flags & 0x01); |
|
40 | |||
41 | 6 | return new FrameAddress($target, $isAckRequired, $isResponseRequired, $sequence); |
|
42 | } |
||
44 |