diff --git a/src/RPC/RPC.php b/src/RPC/RPC.php index 09f6b05..adce49a 100644 --- a/src/RPC/RPC.php +++ b/src/RPC/RPC.php @@ -32,14 +32,8 @@ class RPC implements RPCInterface /** * @var positive-int - * @deprecated since v3.2.1. */ - private static int $seq = 1; - - /** - * @deprecated since v3.2.1. Need for backward compatibility. - */ - private bool $hasSequence = false; + private int $seq = 1; /** * @param RelayInterface $relay @@ -49,8 +43,6 @@ public function __construct(RelayInterface $relay, CodecInterface $codec = null) { $this->relay = $relay; $this->codec = $codec ?? new JsonCodec(); - /** @psalm-suppress DeprecatedProperty */ - $this->hasSequence = \method_exists($this->relay, 'getNextSequence'); } /** @@ -84,10 +76,7 @@ public function withCodec(CodecInterface $codec): RPCInterface */ public function call(string $method, $payload, $options = null) { - /** @psalm-suppress DeprecatedMethod */ - $seq = $this->getNextSequence(); - - $this->relay->send($this->packFrame($method, $payload, $seq)); + $this->relay->send($this->packFrame($method, $payload)); // wait for the frame confirmation $frame = $this->relay->waitFrame(); @@ -96,11 +85,11 @@ public function call(string $method, $payload, $options = null) throw new RPCException('Invalid RPC frame, options missing'); } - if ($frame->options[0] !== $seq) { + if ($frame->options[0] !== $this->seq) { throw new RPCException('Invalid RPC frame, sequence mismatch'); } - self::$seq++; + $this->seq++; return $this->decodeResponse($frame, $options); } @@ -174,22 +163,13 @@ private function decodeResponse(Frame $frame, $options = null) * @param mixed $payload * @return Frame */ - private function packFrame(string $method, $payload, int $seq): Frame + private function packFrame(string $method, $payload): Frame { if ($this->service !== null) { $method = $this->service . '.' . \ucfirst($method); } $body = $method . $this->codec->encode($payload); - return new Frame($body, [$seq, \strlen($method)], $this->codec->getIndex()); - } - - /** - * @deprecated since v3.2.1. - */ - private function getNextSequence(): int - { - /** @psalm-suppress DeprecatedProperty */ - return $this->hasSequence ? $this->relay->getNextSequence() : self::$seq; + return new Frame($body, [$this->seq, \strlen($method)], $this->codec->getIndex()); } } diff --git a/src/Relay.php b/src/Relay.php index d05d567..ec4794d 100644 --- a/src/Relay.php +++ b/src/Relay.php @@ -13,8 +13,6 @@ abstract class Relay implements RelayInterface public const PIPES = 'pipes'; protected const CONNECTION_EXP = '/(?P[^:\/]+):\/\/(?P[^:]+)(:(?P[^:]+))?/'; - private int $sequence = 1; - /** * Create relay using string address. * @@ -95,9 +93,4 @@ private static function openOut(string $output) return $resource; } - - public function getNextSequence(): int - { - return $this->sequence++; - } } diff --git a/src/RelayInterface.php b/src/RelayInterface.php index c425999..209983c 100644 --- a/src/RelayInterface.php +++ b/src/RelayInterface.php @@ -8,14 +8,17 @@ /** * Blocking, duplex relay. - * @method getNextSequence(): int */ interface RelayInterface { /** + * @return Frame * @throws RelayException */ public function waitFrame(): Frame; + /** + * @param Frame $frame + */ public function send(Frame $frame): void; } diff --git a/tests/Goridge/RPCTest.php b/tests/Goridge/RPCTest.php index f817837..165a397 100644 --- a/tests/Goridge/RPCTest.php +++ b/tests/Goridge/RPCTest.php @@ -157,7 +157,7 @@ public function testLongRawBody(): void { $conn = $this->makeRPC(); $payload = random_bytes(65000 * 1000); - + $resp = $conn->withCodec(new RawCodec())->call( 'Service.EchoBinary', $payload