@@ -54,8 +54,11 @@ public function getSignature(): int
5454 */
5555 private function next (int $ length ): string
5656 {
57- $ str = mb_strcut ($ this ->message , $ this ->offset , $ length , '8bit ' );
58- $ this ->offset += mb_strlen ($ str , '8bit ' );
57+ $ str = '' ;
58+ if (mb_strlen ($ this ->message , '8bit ' ) > $ this ->offset ) {
59+ $ str = mb_strcut ($ this ->message , $ this ->offset , $ length , '8bit ' );
60+ $ this ->offset += mb_strlen ($ str , '8bit ' );
61+ }
5962 return $ str ;
6063 }
6164
@@ -64,10 +67,11 @@ private function next(int $length): string
6467 */
6568 private function u (): mixed
6669 {
67- $ marker = ord ( $ this ->next (1 ) );
68- if (mb_strlen ($ marker , '8bit ' ) === 0 ) {
70+ $ str = $ this ->next (1 );
71+ if (mb_strlen ($ str , '8bit ' ) !== 1 ) {
6972 return null ;
7073 }
74+ $ marker = ord ($ str );
7175
7276 if ($ marker == 0xC3 ) {
7377 return true ;
@@ -137,13 +141,17 @@ private function unpackStruct(int $marker): array|IStructure|null
137141 }
138142
139143 $ class = $ this ->structuresLt [$ signature ];
140- $ reflection = new \ReflectionClass ($ class );
141- if ($ reflection ->getConstructor ()->getNumberOfParameters () != count ($ values ))
142- throw new UnpackException ('Incorrect amount of structure fields for ' . $ class );
144+ try {
145+ $ reflection = new \ReflectionClass ($ class );
146+ if ($ reflection ->getConstructor ()->getNumberOfParameters () != count ($ values ))
147+ throw new UnpackException ('Incorrect amount of structure fields for ' . $ class );
148+ } catch (\ReflectionException $ e ) {
149+ throw new UnpackException ($ e ->getMessage ());
150+ }
143151 return new $ class (...$ values );
144152 } else {
145153 $ this ->signature = $ signature ;
146- return mb_strlen ( $ this ->message , ' 8bit ' ) > $ this -> offset ? $ this -> u () : [];
154+ return $ this ->u () ?? [];
147155 }
148156 }
149157
0 commit comments