1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Transport\Frame\Value; |
5
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
7
|
|
|
Transport\Frame\Value, |
8
|
|
|
Exception\OutOfRangeValue, |
9
|
|
|
Exception\StringNotOfExpectedLength |
10
|
|
|
}; |
11
|
|
|
use Innmind\Math\{ |
12
|
|
|
Algebra\Integer, |
13
|
|
|
Algebra\Number\Infinite, |
14
|
|
|
DefinitionSet\Set, |
15
|
|
|
DefinitionSet\Range |
16
|
|
|
}; |
17
|
|
|
use Innmind\Immutable\Str; |
18
|
|
|
|
19
|
|
|
final class UnsignedLongLongInteger implements Value |
20
|
|
|
{ |
21
|
|
|
private static $definitionSet; |
22
|
|
|
|
23
|
|
|
private $value; |
24
|
|
|
private $original; |
25
|
|
|
|
26
|
94 |
|
public function __construct(Integer $value) |
27
|
|
|
{ |
28
|
94 |
|
if (!self::definitionSet()->contains($value)) { |
29
|
2 |
|
throw new OutOfRangeValue($value, self::definitionSet()); |
30
|
|
|
} |
31
|
|
|
|
32
|
92 |
|
$this->original = $value; |
33
|
92 |
|
} |
34
|
|
|
|
35
|
58 |
|
public static function fromString(Str $string): Value |
36
|
|
|
{ |
37
|
58 |
|
$string = $string->toEncoding('ASCII'); |
38
|
|
|
|
39
|
58 |
|
if ($string->length() !== 8) { |
40
|
2 |
|
throw new StringNotOfExpectedLength($string, 8); |
41
|
|
|
} |
42
|
|
|
|
43
|
56 |
|
[, $value] = unpack('J', (string) $string); |
44
|
|
|
|
45
|
56 |
|
return new self(new Integer($value)); |
46
|
|
|
} |
47
|
|
|
|
48
|
56 |
|
public static function cut(Str $string): Str |
49
|
|
|
{ |
50
|
56 |
|
return $string->toEncoding('ASCII')->substring(0, 8); |
51
|
|
|
} |
52
|
|
|
|
53
|
68 |
|
public function original(): Integer |
54
|
|
|
{ |
55
|
68 |
|
return $this->original; |
56
|
|
|
} |
57
|
|
|
|
58
|
90 |
|
public function __toString(): string |
59
|
|
|
{ |
60
|
90 |
|
return $this->value ?? $this->value = pack('J', $this->original->value()); |
61
|
|
|
} |
62
|
|
|
|
63
|
94 |
|
public static function definitionSet(): Set |
64
|
|
|
{ |
65
|
94 |
|
return self::$definitionSet ?? self::$definitionSet = Range::inclusive( |
66
|
|
|
new Integer(0), |
67
|
94 |
|
Infinite::positive() |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|