@@ -31,7 +31,7 @@ class EncapsulatedPacket{
3131
3232 public const SPLIT_INFO_LENGTH = 4 + 2 + 4 ; //split count (4) + split ID (2) + split index (4)
3333
34- public PacketReliability $ reliability ;
34+ public int $ reliability ;
3535 public ?int $ messageIndex = null ;
3636 public ?int $ sequenceIndex = null ;
3737 public ?int $ orderIndex = null ;
@@ -47,28 +47,23 @@ public static function fromBinary(BinaryStream $stream) : EncapsulatedPacket{
4747 $ packet = new EncapsulatedPacket ();
4848
4949 $ flags = $ stream ->getByte ();
50- $ reliability = PacketReliability::tryFrom (($ flags & self ::RELIABILITY_FLAGS ) >> self ::RELIABILITY_SHIFT );
51- if ($ reliability === null ){
52- //TODO: we should reject the ACK_RECEIPT types here - they aren't supposed to be sent over the wire
53- throw new BinaryDataException ("Invalid encapsulated packet reliability " );
54- }
55- $ packet ->reliability = $ reliability ;
50+ $ packet ->reliability = $ reliability = ($ flags & self ::RELIABILITY_FLAGS ) >> self ::RELIABILITY_SHIFT ;
5651 $ hasSplit = ($ flags & self ::SPLIT_FLAG ) !== 0 ;
5752
5853 $ length = (int ) ceil ($ stream ->getShort () / 8 );
5954 if ($ length === 0 ){
6055 throw new BinaryDataException ("Encapsulated payload length cannot be zero " );
6156 }
6257
63- if ($ reliability -> isReliable ()){
58+ if (PacketReliability:: isReliable ($ reliability )){
6459 $ packet ->messageIndex = $ stream ->getLTriad ();
6560 }
6661
67- if ($ reliability -> isSequenced ()){
62+ if (PacketReliability:: isSequenced ($ reliability )){
6863 $ packet ->sequenceIndex = $ stream ->getLTriad ();
6964 }
7065
71- if ($ reliability -> isSequencedOrOrdered ()){
66+ if (PacketReliability:: isSequencedOrOrdered ($ reliability )){
7267 $ packet ->orderIndex = $ stream ->getLTriad ();
7368 $ packet ->orderChannel = $ stream ->getByte ();
7469 }
@@ -86,11 +81,11 @@ public static function fromBinary(BinaryStream $stream) : EncapsulatedPacket{
8681
8782 public function toBinary () : string {
8883 return
89- chr (($ this ->reliability -> value << self ::RELIABILITY_SHIFT ) | ($ this ->splitInfo !== null ? self ::SPLIT_FLAG : 0 )) .
84+ chr (($ this ->reliability << self ::RELIABILITY_SHIFT ) | ($ this ->splitInfo !== null ? self ::SPLIT_FLAG : 0 )) .
9085 Binary::writeShort (strlen ($ this ->buffer ) << 3 ) .
91- ($ this ->reliability -> isReliable ( ) ? Binary::writeLTriad ($ this ->messageIndex ) : "" ) .
92- ($ this ->reliability -> isSequenced ( ) ? Binary::writeLTriad ($ this ->sequenceIndex ) : "" ) .
93- ($ this ->reliability -> isSequencedOrOrdered ( ) ? Binary::writeLTriad ($ this ->orderIndex ) . chr ($ this ->orderChannel ) : "" ) .
86+ (PacketReliability:: isReliable ( $ this ->reliability ) ? Binary::writeLTriad ($ this ->messageIndex ) : "" ) .
87+ (PacketReliability:: isSequenced ( $ this ->reliability ) ? Binary::writeLTriad ($ this ->sequenceIndex ) : "" ) .
88+ (PacketReliability:: isSequencedOrOrdered ( $ this ->reliability ) ? Binary::writeLTriad ($ this ->orderIndex ) . chr ($ this ->orderChannel ) : "" ) .
9489 ($ this ->splitInfo !== null ? Binary::writeInt ($ this ->splitInfo ->getTotalPartCount ()) . Binary::writeShort ($ this ->splitInfo ->getId ()) . Binary::writeInt ($ this ->splitInfo ->getPartIndex ()) : "" )
9590 . $ this ->buffer ;
9691 }
@@ -102,9 +97,9 @@ public function getHeaderLength() : int{
10297 return
10398 1 + //reliability
10499 2 + //length
105- ($ this ->reliability -> isReliable ( ) ? 3 : 0 ) + //message index
106- ($ this ->reliability -> isSequenced ( ) ? 3 : 0 ) + //sequence index
107- ($ this ->reliability -> isSequencedOrOrdered ( ) ? 3 + 1 : 0 ) + //order index (3) + order channel (1)
100+ (PacketReliability:: isReliable ( $ this ->reliability ) ? 3 : 0 ) + //message index
101+ (PacketReliability:: isSequenced ( $ this ->reliability ) ? 3 : 0 ) + //sequence index
102+ (PacketReliability:: isSequencedOrOrdered ( $ this ->reliability ) ? 3 + 1 : 0 ) + //order index (3) + order channel (1)
108103 ($ this ->splitInfo !== null ? self ::SPLIT_INFO_LENGTH : 0 );
109104 }
110105
0 commit comments