← All changes
|
includes/sdk/s3/Aws/Api/Parser/DecodingEventStreamIterator.php
+20
-13
1.2.12
→
1.4.1
View file →
| @@ -23,17 +23,17 @@ | ||
| 23 | 23 | private static $preludeFormat = [self::LENGTH_TOTAL => 'decodeUint32', self::LENGTH_HEADERS => 'decodeUint32', self::CRC_PRELUDE => 'decodeUint32']; |
| 24 | 24 | private static $lengthFormatMap = [1 => 'decodeUint8', 2 => 'decodeUint16', 4 => 'decodeUint32', 8 => 'decodeUint64']; |
| 25 | 25 | private static $headerTypeMap = [0 => 'decodeBooleanTrue', 1 => 'decodeBooleanFalse', 2 => 'decodeInt8', 3 => 'decodeInt16', 4 => 'decodeInt32', 5 => 'decodeInt64', 6 => 'decodeBytes', 7 => 'decodeString', 8 => 'decodeTimestamp', 9 => 'decodeUuid']; |
| 26 | 26 | /** @var StreamInterface Stream of eventstream shape to parse. */ |
| 27 | - private $stream; | |
| 27 | + protected $stream; | |
| 28 | 28 | /** @var array Currently parsed event. */ |
| 29 | - private $currentEvent; | |
| 29 | + protected $currentEvent; | |
| 30 | 30 | /** @var int Current in-order event key. */ |
| 31 | - private $key; | |
| 31 | + protected $key; | |
| 32 | 32 | /** @var resource|\HashContext CRC32 hash context for event validation */ |
| 33 | - private $hashContext; | |
| 33 | + protected $hashContext; | |
| 34 | 34 | /** @var int $currentPosition */ |
| 35 | - private $currentPosition; | |
| 35 | + protected $currentPosition; | |
| 36 | 36 | /** |
| 37 | 37 | * DecodingEventStreamIterator constructor. |
| 38 | 38 | * |
| 39 | 39 | * @param StreamInterface $stream |
| @@ -42,9 +42,9 @@ | ||
| 42 | 42 | { |
| 43 | 43 | $this->stream = $stream; |
| 44 | 44 | $this->rewind(); |
| 45 | 45 | } |
| 46 | - private function parseHeaders($headerBytes) | |
| 46 | + protected function parseHeaders($headerBytes) | |
| 47 | 47 | { |
| 48 | 48 | $headers = []; |
| 49 | 49 | $bytesRead = 0; |
| 50 | 50 | while ($bytesRead < $headerBytes) { |
| @@ -61,9 +61,9 @@ | ||
| 61 | 61 | $headers[$key] = $value; |
| 62 | 62 | } |
| 63 | 63 | return [$headers, $bytesRead]; |
| 64 | 64 | } |
| 65 | - private function parsePrelude() | |
| 65 | + protected function parsePrelude() | |
| 66 | 66 | { |
| 67 | 67 | $prelude = []; |
| 68 | 68 | $bytesRead = 0; |
| 69 | 69 | $calculatedCrc = null; |
| @@ -81,9 +81,14 @@ | ||
| 81 | 81 | throw new ParserException('Prelude checksum mismatch.'); |
| 82 | 82 | } |
| 83 | 83 | return [$prelude, $bytesRead]; |
| 84 | 84 | } |
| 85 | - private function parseEvent() | |
| 85 | + /** | |
| 86 | + * This method decodes an event from the stream. | |
| 87 | + * | |
| 88 | + * @return array | |
| 89 | + */ | |
| 90 | + protected function parseEvent() | |
| 86 | 91 | { |
| 87 | 92 | $event = []; |
| 88 | 93 | if ($this->stream->tell() < $this->stream->getSize()) { |
| 89 | 94 | $this->hashContext = \hash_init('crc32b'); |
| @@ -122,8 +127,11 @@ | ||
| 122 | 127 | public function key() |
| 123 | 128 | { |
| 124 | 129 | return $this->key; |
| 125 | 130 | } |
| 131 | + /** | |
| 132 | + * @return void | |
| 133 | + */ | |
| 126 | 134 | #[\ReturnTypeWillChange] |
| 127 | 135 | public function next() |
| 128 | 136 | { |
| 129 | 137 | $this->currentPosition = $this->stream->tell(); |
| @@ -131,8 +139,11 @@ | ||
| 131 | 139 | $this->key++; |
| 132 | 140 | $this->currentEvent = $this->parseEvent(); |
| 133 | 141 | } |
| 134 | 142 | } |
| 143 | + /** | |
| 144 | + * @return void | |
| 145 | + */ | |
| 135 | 146 | #[\ReturnTypeWillChange] |
| 136 | 147 | public function rewind() |
| 137 | 148 | { |
| 138 | 149 | $this->stream->rewind(); |
| @@ -148,9 +159,9 @@ | ||
| 148 | 159 | { |
| 149 | 160 | return $this->currentPosition < $this->stream->getSize(); |
| 150 | 161 | } |
| 151 | 162 | // Decoding Utilities |
| 152 | - private function readAndHashBytes($num) | |
| 163 | + protected function readAndHashBytes($num) | |
| 153 | 164 | { |
| 154 | 165 | $bytes = $this->stream->read($num); |
| 155 | 166 | \hash_update($this->hashContext, $bytes); |
| 156 | 167 | return $bytes; |
| @@ -208,12 +219,8 @@ | ||
| 208 | 219 | return [$this->unpackInt64($this->readAndHashBytes(8))[1], 8]; |
| 209 | 220 | } |
| 210 | 221 | private function unpackInt64($bytes) |
| 211 | 222 | { |
| 212 | - if (\version_compare(\PHP_VERSION, '5.6.3', '<')) { | |
| 213 | - $d = \unpack('N2', $bytes); | |
| 214 | - return [1 => $d[1] << 32 | $d[2]]; | |
| 215 | - } | |
| 216 | 223 | return \unpack('J', $bytes); |
| 217 | 224 | } |
| 218 | 225 | private function decodeBytes($lengthBytes = 2) |
| 219 | 226 | { |