Passed
Push — 0.6.x ( 9a1948...a98caa )
by Shinji
03:23 queued 01:32
created

LittleEndianReader::read32()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the reliforp/reli-prof package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Reli\Lib\ByteStream\IntegerByteSequence;
15
16
use Reli\Lib\ByteStream\ByteReaderInterface;
17
use Reli\Lib\Integer\UInt64;
18
19
final class LittleEndianReader implements IntegerByteSequenceReader
20
{
21
    public function read8(ByteReaderInterface $data, int $offset): int
22
    {
23
        return $data[$offset];
24
    }
25
26
    public function read16(ByteReaderInterface $data, int $offset): int
27
    {
28
        return ($data[$offset + 1] << 8) | $data[$offset];
29
    }
30
31
    public function read32(ByteReaderInterface $data, int $offset): int
32
    {
33
        return ($data[$offset + 3] << 24)
34
            | ($data[$offset + 2] << 16)
35
            | ($data[$offset + 1] << 8)
36
            | $data[$offset];
37
    }
38
39
    public function read64(ByteReaderInterface $data, int $offset): UInt64
40
    {
41
        return new UInt64(
42
            $this->read32($data, $offset + 4),
43
            $this->read32($data, $offset),
44
        );
45
    }
46
}
47