ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ZipStream\Bigint Class Reference
+ Collaboration diagram for ZipStream\Bigint:

Public Member Functions

 __construct (int $value=0)
 Initialize the bytes array. More...
 
 getHigh32 ()
 Get high 32. More...
 
 getValue (int $end=0, int $length=8)
 Get value from bytes array. More...
 
 getLowFF (bool $force=false)
 Get low FF. More...
 
 isOver32 (bool $force=false)
 Check if is over 32. More...
 
 getLow32 ()
 Get low 32. More...
 
 getHex64 ()
 Get hexadecimal. More...
 
 add (Bigint $other)
 Add. More...
 

Static Public Member Functions

static init (int $value=0)
 Get an instance. More...
 
static fromLowHigh (int $low, int $high)
 Fill bytes from low to high. More...
 

Protected Member Functions

 fillBytes (int $value, int $start, int $count)
 Fill the bytes field with int. More...
 

Private Attributes

 $bytes = [0, 0, 0, 0, 0, 0, 0, 0]
 

Detailed Description

Definition at line 8 of file Bigint.php.

Constructor & Destructor Documentation

◆ __construct()

ZipStream\Bigint::__construct ( int  $value = 0)

Initialize the bytes array.

Parameters
int$value

Definition at line 20 of file Bigint.php.

21 {
22 $this->fillBytes($value, 0, 8);
23 }
fillBytes(int $value, int $start, int $count)
Fill the bytes field with int.
Definition: Bigint.php:33

Member Function Documentation

◆ add()

ZipStream\Bigint::add ( Bigint  $other)

Add.

Parameters
Bigint$other
Returns
Bigint

Definition at line 152 of file Bigint.php.

152 : Bigint
153 {
154 $result = clone $this;
155 $overflow = false;
156 for ($i = 0; $i < 8; $i++) {
157 $result->bytes[$i] += $other->bytes[$i];
158 if ($overflow) {
159 $result->bytes[$i]++;
160 $overflow = false;
161 }
162 if ($result->bytes[$i] & 0x100) {
163 $overflow = true;
164 $result->bytes[$i] &= 0xFF;
165 }
166 }
167 if ($overflow) {
168 throw new OverflowException;
169 }
170 return $result;
171 }
$result
$i
Definition: disco.tpl.php:19

References $i, and $result.

◆ fillBytes()

ZipStream\Bigint::fillBytes ( int  $value,
int  $start,
int  $count 
)
protected

Fill the bytes field with int.

Parameters
int$value
int$start
int$count
Returns
void

Definition at line 33 of file Bigint.php.

33 : void
34 {
35 for ($i = 0; $i < $count; $i++) {
36 $this->bytes[$start + $i] = $i >= PHP_INT_SIZE ? 0 : $value & 0xFF;
37 $value >>= 8;
38 }
39 }
$start
Definition: bench.php:8

References $i, and $start.

◆ fromLowHigh()

static ZipStream\Bigint::fromLowHigh ( int  $low,
int  $high 
)
static

Fill bytes from low to high.

Parameters
int$low
int$high
Returns
Bigint

Definition at line 59 of file Bigint.php.

59 : self
60 {
61 $bigint = new Bigint();
62 $bigint->fillBytes($low, 0, 4);
63 $bigint->fillBytes($high, 4, 4);
64 return $bigint;
65 }

Referenced by BigintTest\BigintTest\testAddWithOverflowAtInteger64().

+ Here is the caller graph for this function:

◆ getHex64()

ZipStream\Bigint::getHex64 ( )

Get hexadecimal.

Returns
string

Definition at line 137 of file Bigint.php.

137 : string
138 {
139 $result = '0x';
140 for ($i = 7; $i >= 0; $i--) {
141 $result .= sprintf('%02X', $this->bytes[$i]);
142 }
143 return $result;
144 }

References $i, and $result.

◆ getHigh32()

ZipStream\Bigint::getHigh32 ( )

Get high 32.

Returns
int

Definition at line 72 of file Bigint.php.

72 : int
73 {
74 return $this->getValue(4, 4);
75 }
getValue(int $end=0, int $length=8)
Get value from bytes array.
Definition: Bigint.php:84

◆ getLow32()

ZipStream\Bigint::getLow32 ( )

Get low 32.

Returns
int

Definition at line 127 of file Bigint.php.

127 : int
128 {
129 return $this->getValue(0, 4);
130 }

◆ getLowFF()

ZipStream\Bigint::getLowFF ( bool  $force = false)

Get low FF.

Parameters
bool$force
Returns
float

Definition at line 100 of file Bigint.php.

100 : float
101 {
102 if ($force || $this->isOver32()) {
103 return (float)0xFFFFFFFF;
104 }
105 return (float)$this->getLow32();
106 }
isOver32(bool $force=false)
Check if is over 32.
Definition: Bigint.php:114
getLow32()
Get low 32.
Definition: Bigint.php:127

◆ getValue()

ZipStream\Bigint::getValue ( int  $end = 0,
int  $length = 8 
)

Get value from bytes array.

Parameters
int$end
int$length
Returns
int

Definition at line 84 of file Bigint.php.

84 : int
85 {
86 $result = 0;
87 for ($i = $end + $length - 1; $i >= $end; $i--) {
88 $result <<= 8;
89 $result |= $this->bytes[$i];
90 }
91 return $result;
92 }

References $end, $i, and $result.

◆ init()

static ZipStream\Bigint::init ( int  $value = 0)
static

Get an instance.

Parameters
int$value
Returns
Bigint

Definition at line 47 of file Bigint.php.

47 : self
48 {
49 return new self($value);
50 }

Referenced by BigintTest\BigintTest\testAddSmallValue(), BigintTest\BigintTest\testAddWithOverflowAtInteger32(), BigintTest\BigintTest\testAddWithOverflowAtInteger64(), and BigintTest\BigintTest\testAddWithOverflowAtLowestByte().

+ Here is the caller graph for this function:

◆ isOver32()

ZipStream\Bigint::isOver32 ( bool  $force = false)

Check if is over 32.

Parameters
bool$force
Returns
bool

Definition at line 114 of file Bigint.php.

114 : bool
115 {
116 // value 0xFFFFFFFF already needs a Zip64 header
117 return $force ||
118 max(array_slice($this->bytes, 4, 4)) > 0 ||
119 min(array_slice($this->bytes, 0, 4)) === 0xFF;
120 }

Field Documentation

◆ $bytes

ZipStream\Bigint::$bytes = [0, 0, 0, 0, 0, 0, 0, 0]
private

Definition at line 13 of file Bigint.php.


The documentation for this class was generated from the following file: