|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the rybakit/msgpack.php package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eugene Leonovich <[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
|
|
|
namespace MessagePack; |
|
13
|
|
|
|
|
14
|
|
|
use MessagePack\Exception\InvalidOptionException; |
|
15
|
|
|
|
|
16
|
|
|
final class UnpackOptions |
|
17
|
|
|
{ |
|
18
|
|
|
public const BIGINT_AS_STR = 0b001; |
|
19
|
|
|
public const BIGINT_AS_GMP = 0b010; |
|
20
|
|
|
public const BIGINT_AS_DEC = 0b100; |
|
21
|
|
|
|
|
22
|
|
|
private $bigIntMode; |
|
23
|
|
|
|
|
24
|
333 |
|
private function __construct() |
|
25
|
|
|
{ |
|
26
|
333 |
|
} |
|
27
|
|
|
|
|
28
|
319 |
|
public static function fromDefaults() : self |
|
29
|
|
|
{ |
|
30
|
319 |
|
$self = new self(); |
|
31
|
319 |
|
$self->bigIntMode = self::BIGINT_AS_STR; |
|
32
|
|
|
|
|
33
|
319 |
|
return $self; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
21 |
|
public static function fromBitmask(int $bitmask) : self |
|
37
|
|
|
{ |
|
38
|
21 |
|
$self = new self(); |
|
39
|
|
|
|
|
40
|
21 |
|
$self->bigIntMode = self::getSingleOption('bigint', $bitmask, |
|
41
|
21 |
|
self::BIGINT_AS_STR | |
|
42
|
21 |
|
self::BIGINT_AS_GMP | |
|
43
|
21 |
|
self::BIGINT_AS_DEC |
|
44
|
3 |
|
) ?: self::BIGINT_AS_STR; |
|
45
|
|
|
|
|
46
|
16 |
|
return $self; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
4 |
|
public function isBigIntAsStrMode() : bool |
|
50
|
|
|
{ |
|
51
|
4 |
|
return self::BIGINT_AS_STR === $this->bigIntMode; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
324 |
|
public function isBigIntAsGmpMode() : bool |
|
55
|
|
|
{ |
|
56
|
324 |
|
return self::BIGINT_AS_GMP === $this->bigIntMode; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
324 |
|
public function isBigIntAsDecMode() : bool |
|
60
|
|
|
{ |
|
61
|
324 |
|
return self::BIGINT_AS_DEC === $this->bigIntMode; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
21 |
|
private static function getSingleOption(string $name, int $bitmask, int $validBitmask) : int |
|
65
|
|
|
{ |
|
66
|
21 |
|
$option = $bitmask & $validBitmask; |
|
67
|
21 |
|
if ($option === ($option & -$option)) { |
|
68
|
16 |
|
return $option; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
5 |
|
static $map = [ |
|
72
|
|
|
self::BIGINT_AS_STR => 'BIGINT_AS_STR', |
|
73
|
|
|
self::BIGINT_AS_GMP => 'BIGINT_AS_GMP', |
|
74
|
|
|
self::BIGINT_AS_DEC => 'BIGINT_AS_DEC', |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
5 |
|
$validOptions = []; |
|
78
|
5 |
|
for ($i = $validBitmask & -$validBitmask; $i <= $validBitmask; $i <<= 1) { |
|
79
|
5 |
|
$validOptions[] = __CLASS__.'::'.$map[$i]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
5 |
|
throw InvalidOptionException::outOfRange($name, $validOptions); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|