File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed
Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ public static function readSignedByte(string $c) : int{
142142 * Writes an unsigned/signed byte
143143 */
144144 public static function writeByte (int $ c ) : string {
145- return chr ($ c );
145+ return chr ($ c & 0xff );
146146 }
147147
148148 /**
@@ -434,10 +434,11 @@ public static function writeUnsignedVarInt(int $value) : string{
434434 $ buf = "" ;
435435 $ remaining = $ value & 0xffffffff ;
436436 for ($ i = 0 ; $ i < 5 ; ++$ i ){
437+ $ bits = $ remaining & 0x7f ;
437438 if (($ remaining >> 7 ) !== 0 ){
438- $ buf .= chr ($ remaining | 0x80 );
439+ $ buf .= chr ($ bits | 0x80 );
439440 }else {
440- $ buf .= chr ($ remaining & 0x7f );
441+ $ buf .= chr ($ bits & 0x7f );
441442 return $ buf ;
442443 }
443444
@@ -498,10 +499,11 @@ public static function writeUnsignedVarLong(int $value) : string{
498499 $ buf = "" ;
499500 $ remaining = $ value ;
500501 for ($ i = 0 ; $ i < 10 ; ++$ i ){
502+ $ bits = $ remaining & 0x7f ;
501503 if (($ remaining >> 7 ) !== 0 ){
502- $ buf .= chr ($ remaining | 0x80 ); //Let chr() take the last byte of this, it's faster than adding another & 0x7f.
504+ $ buf .= chr ($ bits | 0x80 );
503505 }else {
504- $ buf .= chr ($ remaining & 0x7f );
506+ $ buf .= chr ($ bits & 0x7f );
505507 return $ buf ;
506508 }
507509
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ public function getByte() : int{
119119 }
120120
121121 public function putByte (int $ v ) : void {
122- $ this ->buffer .= chr ($ v );
122+ $ this ->buffer .= chr ($ v & 0xff );
123123 }
124124
125125 /**
You can’t perform that action at this time.
0 commit comments